Skip to content

Commit ff404c5

Browse files
committed
update ActionKeywordSetting view logic
1 parent f13e24b commit ff404c5

File tree

6 files changed

+39
-38
lines changed

6 files changed

+39
-38
lines changed

Flow.Launcher.Core/Plugin/PluginManager.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,8 @@ public static List<Result> GetContextMenusForPlugin(Result result)
252252

253253
public static bool ActionKeywordRegistered(string actionKeyword)
254254
{
255+
// this method is only checking for action keywords (defined as not '*') registration
256+
// hence the actionKeyword != Query.GlobalPluginWildcardSign logic
255257
return actionKeyword != Query.GlobalPluginWildcardSign
256258
&& NonGlobalPlugins.ContainsKey(actionKeyword);
257259
}

Plugins/Flow.Launcher.Plugin.Explorer/Languages/en.xaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
<system:String x:Key="plugin_explorer_actionkeywordview_path">Path Search:</system:String>
2424
<system:String x:Key="plugin_explorer_actionkeywordview_filecontentsearch">File Content Search:</system:String>
2525
<system:String x:Key="plugin_explorer_actionkeywordview_indexonlysearch">Index Search:</system:String>
26+
<system:String x:Key="plugin_explorer_actionkeyword_current">Current Action Keyword:</system:String>
27+
<system:String x:Key="plugin_explorer_actionkeyword_done">Done</system:String>
28+
<system:String x:Key="plugin_explorer_actionkeyword_enabled">Enabled</system:String>
29+
<system:String x:Key="plugin_explorer_actionkeyword_enabled_tooltip">When disabled Flow will not execute this search option, and will additionally revert back to '*' to free up the action keyword</system:String>
2630

2731
<!--Plugin Infos-->
2832
<system:String x:Key="plugin_explorer_plugin_name">Explorer</system:String>

Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ internal async Task<List<Result>> SearchAsync(Query query, CancellationToken tok
6767

6868
private bool ActionKeywordMatch(Query query, Settings.ActionKeyword allowedActionKeyword)
6969
{
70-
var keyword = query.ActionKeyword.Length == 0 ? "*" : query.ActionKeyword;
70+
var keyword = query.ActionKeyword.Length == 0 ? Query.GlobalPluginWildcardSign : query.ActionKeyword;
7171

7272
return allowedActionKeyword switch
7373
{

Plugins/Flow.Launcher.Plugin.Explorer/ViewModels/SettingsViewModel.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,14 @@ internal void UpdateActionKeyword(Settings.ActionKeyword modifiedActionKeyword,
6262
}
6363
}
6464

65-
internal bool IsActionKeywordAlreadyAssigned(string newActionKeyword) => PluginManager.ActionKeywordRegistered(newActionKeyword);
65+
internal bool IsActionKeywordAlreadyAssigned(string newActionKeyword, string oldActionKeyword)
66+
{
67+
// PluginManager.ActionKeywordRegistered does not check global action keyword ('*'), so use this logic instead
68+
if (newActionKeyword == Query.GlobalPluginWildcardSign)
69+
return newActionKeyword == oldActionKeyword;
70+
71+
return PluginManager.ActionKeywordRegistered(newActionKeyword);
72+
}
6673

6774
internal bool IsNewActionKeywordGlobal(string newActionKeyword) => newActionKeyword == Query.GlobalPluginWildcardSign;
6875
}

Plugins/Flow.Launcher.Plugin.Explorer/Views/ActionKeywordSetting.xaml

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,19 @@
2020
<ColumnDefinition />
2121
</Grid.ColumnDefinitions>
2222
<TextBlock Margin="20 10 10 10" FontSize="14" Grid.Row="0" Grid.Column="0" VerticalAlignment="Center"
23-
HorizontalAlignment="Left" Text="Current Action Keyword:" />
23+
HorizontalAlignment="Left" Text="{DynamicResource plugin_explorer_actionkeyword_current}" />
2424
<TextBox Name="TxtCurrentActionKeyword"
2525
Margin="10" Grid.Row="0" Width="105" Grid.Column="1"
2626
VerticalAlignment="Center"
2727
HorizontalAlignment="Left"
2828
Text="{Binding CurrentActionKeyword.Keyword}" />
29-
<CheckBox Name="ChkActionKeywordEnabled" Margin="10" Grid.Row="0" Grid.Column="2" Content="Enabled"
29+
<CheckBox Name="ChkActionKeywordEnabled" ToolTip="{DynamicResource plugin_explorer_actionkeyword_enabled_tooltip}"
30+
Margin="10" Grid.Row="0" Grid.Column="2" Content="{DynamicResource plugin_explorer_actionkeyword_enabled}"
3031
Width="auto"
3132
VerticalAlignment="Center" IsChecked="{Binding CurrentActionKeyword.Enabled}"
3233
Visibility="{Binding Visible}"/>
33-
<StackPanel Orientation="Horizontal" Grid.Column="1" Grid.ColumnSpan="2" Margin="100 92 0 0" Grid.RowSpan="2">
34-
<Button Click="OnConfirmButtonClick"
35-
Margin="10 0 10 0" Width="80" Height="35"
36-
Content="OK" />
37-
<Button Click="OnCancelButtonClick"
38-
Margin="10 0 10 0" Width="80" Height="35"
39-
Content="Cancel" />
40-
</StackPanel>
34+
<Button Click="OnDoneButtonClick" Grid.Row="1" Grid.Column="2"
35+
Margin="10 0 10 0" Width="80" Height="35"
36+
Content="{DynamicResource plugin_explorer_actionkeyword_done}" />
4137
</Grid>
4238
</Window>

Plugins/Flow.Launcher.Plugin.Explorer/Views/ActionKeywordSetting.xaml.cs

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Flow.Launcher.Plugin.Explorer.ViewModels;
1+
using Flow.Launcher.Plugin.Explorer.ViewModels;
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Windows;
@@ -14,6 +14,8 @@ public partial class ActionKeywordSetting : Window
1414

1515
public ActionKeywordView CurrentActionKeyword { get; set; }
1616

17+
private string oldActionKeyword;
18+
1719
private List<ActionKeywordView> actionKeywordListView;
1820

1921
private Settings settings;
@@ -30,32 +32,20 @@ public ActionKeywordSetting(SettingsViewModel settingsViewModel,
3032

3133
CurrentActionKeyword = selectedActionKeyword;
3234

35+
oldActionKeyword = selectedActionKeyword.Keyword;
36+
3337
this.actionKeywordListView = actionKeywordListView;
3438

3539
InitializeComponent();
3640

3741
}
3842

39-
private void OnConfirmButtonClick(object sender, RoutedEventArgs e)
43+
private void OnDoneButtonClick(object sender, RoutedEventArgs e)
4044
{
41-
var newActionKeyword = TxtCurrentActionKeyword.Text;
42-
43-
if (string.IsNullOrEmpty(newActionKeyword))
45+
if (string.IsNullOrEmpty(CurrentActionKeyword.Keyword))
4446
return;
4547

46-
// reset to global so it does not take up an action keyword when disabled
47-
if (!CurrentActionKeyword.Enabled is not null && newActionKeyword != Query.GlobalPluginWildcardSign)
48-
settingsViewModel.UpdateActionKeyword(CurrentActionKeyword.KeywordProperty,
49-
Query.GlobalPluginWildcardSign, CurrentActionKeyword.Keyword);
50-
51-
if (newActionKeyword == CurrentActionKeyword.Keyword)
52-
{
53-
Close();
54-
55-
return;
56-
}
57-
58-
if (settingsViewModel.IsNewActionKeywordGlobal(newActionKeyword)
48+
if (settingsViewModel.IsNewActionKeywordGlobal(CurrentActionKeyword.Keyword)
5949
&& CurrentActionKeyword.KeywordProperty == Settings.ActionKeyword.FileContentSearchActionKeyword)
6050
{
6151
MessageBox.Show(
@@ -64,13 +54,12 @@ private void OnConfirmButtonClick(object sender, RoutedEventArgs e)
6454
return;
6555
}
6656

67-
if (!settingsViewModel.IsActionKeywordAlreadyAssigned(newActionKeyword))
57+
if (!settingsViewModel.IsActionKeywordAlreadyAssigned(CurrentActionKeyword.Keyword, oldActionKeyword))
6858
{
69-
settingsViewModel.UpdateActionKeyword(CurrentActionKeyword.KeywordProperty, newActionKeyword,
70-
CurrentActionKeyword.Keyword);
59+
settingsViewModel.UpdateActionKeyword(CurrentActionKeyword.KeywordProperty, CurrentActionKeyword.Keyword, oldActionKeyword);
7160

7261
actionKeywordListView.FirstOrDefault(x => x.Description == CurrentActionKeyword.Description).Keyword =
73-
newActionKeyword;
62+
CurrentActionKeyword.Keyword;
7463

7564
// automatically help users set this to enabled if an action keyword is set and currently disabled
7665
if (CurrentActionKeyword.KeywordProperty == Settings.ActionKeyword.IndexSearchActionKeyword
@@ -81,16 +70,19 @@ private void OnConfirmButtonClick(object sender, RoutedEventArgs e)
8170
&& !settings.EnabledPathSearchKeyword)
8271
settings.EnabledPathSearchKeyword = true;
8372

73+
if (CurrentActionKeyword.KeywordProperty == Settings.ActionKeyword.SearchActionKeyword
74+
&& !settings.EnableSearchActionKeyword)
75+
settings.EnableSearchActionKeyword = true;
76+
8477
Close();
8578

8679
return;
8780
}
8881

89-
MessageBox.Show(settingsViewModel.Context.API.GetTranslation("newActionKeywordsHasBeenAssigned"));
90-
}
82+
// reset to global so it does not take up an action keyword when disabled
83+
if (CurrentActionKeyword.Enabled is not null && CurrentActionKeyword.Enabled == false && CurrentActionKeyword.Keyword != Query.GlobalPluginWildcardSign)
84+
settingsViewModel.UpdateActionKeyword(CurrentActionKeyword.KeywordProperty, Query.GlobalPluginWildcardSign, oldActionKeyword);
9185

92-
private void OnCancelButtonClick(object sender, RoutedEventArgs e)
93-
{
9486
Close();
9587

9688
return;

0 commit comments

Comments
 (0)