Skip to content

Commit 995cf56

Browse files
committed
option to allow action keywords to be disabled
1 parent e9abaf3 commit 995cf56

File tree

6 files changed

+97
-19
lines changed

6 files changed

+97
-19
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
<system:String x:Key="plugin_explorer_actionkeywordview_path">Path Explore Activation:</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 Only Search:</system:String>
26+
<system:String x:Key="plugin_explorer_actionkeywordview_brackets_disabled">(Disabled)</system:String>
2627

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

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ internal async Task<List<Result>> SearchAsync(Query query, CancellationToken tok
4646

4747
var result = new HashSet<Result>(PathEqualityComparator.Instance);
4848

49-
if (ActionKeywordMatch(query, settings.PathSearchActionKeyword) || ActionKeywordMatch(query, settings.SearchActionKeyword))
49+
if (ActionKeywordMatch(query, Settings.ActionKeyword.PathSearchActionKeyword) || ActionKeywordMatch(query, Settings.ActionKeyword.SearchActionKeyword))
5050
{
5151
result.UnionWith(await PathSearchAsync(query, token).ConfigureAwait(false));
5252
}
5353

54-
if ((ActionKeywordMatch(query, settings.IndexOnlySearchActionKeyword) || ActionKeywordMatch(query, settings.SearchActionKeyword)) &&
54+
if ((ActionKeywordMatch(query, Settings.ActionKeyword.IndexOnlySearchActionKeyword) || ActionKeywordMatch(query, Settings.ActionKeyword.SearchActionKeyword)) &&
5555
querySearch.Length > 0 &&
5656
!querySearch.IsLocationPathString())
5757
{
@@ -61,18 +61,21 @@ internal async Task<List<Result>> SearchAsync(Query query, CancellationToken tok
6161
return result.ToList();
6262
}
6363

64-
private bool ActionKeywordMatch(Query query, string allowedActionKeyword)
64+
private bool ActionKeywordMatch(Query query, Settings.ActionKeyword allowedActionKeyword)
6565
{
6666
if (query.ActionKeyword == settings.IndexOnlySearchActionKeyword)
67-
return settings.IndexOnlySearchActionKeyword == allowedActionKeyword;
67+
return Settings.ActionKeyword.IndexOnlySearchActionKeyword == allowedActionKeyword && settings.EnabledIndexOnlySearchKeyword;
6868

6969
if (query.ActionKeyword == settings.PathSearchActionKeyword)
70-
return settings.PathSearchActionKeyword == allowedActionKeyword;
70+
return Settings.ActionKeyword.PathSearchActionKeyword == allowedActionKeyword && settings.EnabledPathSearchKeyword;
7171

7272
if (query.ActionKeyword == settings.SearchActionKeyword)
73-
return settings.SearchActionKeyword == allowedActionKeyword;
73+
return Settings.ActionKeyword.SearchActionKeyword == allowedActionKeyword;
7474

75-
return Query.GlobalPluginWildcardSign == allowedActionKeyword;
75+
76+
return (Settings.ActionKeyword.IndexOnlySearchActionKeyword == allowedActionKeyword && settings.EnabledIndexOnlySearchKeyword)
77+
|| (Settings.ActionKeyword.PathSearchActionKeyword == allowedActionKeyword && settings.EnabledPathSearchKeyword)
78+
|| settings.SearchActionKeyword == Query.GlobalPluginWildcardSign;
7679
}
7780

7881
public async Task<List<Result>> PathSearchAsync(Query query, CancellationToken token = default)

Plugins/Flow.Launcher.Plugin.Explorer/Settings.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@ public class Settings
2323

2424
public string PathSearchActionKeyword { get; set; } = Query.GlobalPluginWildcardSign;
2525

26+
public bool EnabledPathSearchKeyword { get; set; }
27+
2628
public string IndexOnlySearchActionKeyword { get; set; } = Query.GlobalPluginWildcardSign;
29+
30+
public bool EnabledIndexOnlySearchKeyword { get; set; }
31+
32+
internal enum ActionKeyword
33+
{
34+
SearchActionKeyword,
35+
PathSearchActionKeyword,
36+
FileContentSearchActionKeyword,
37+
IndexOnlySearchActionKeyword
38+
}
2739
}
2840
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,17 @@
1616
<Grid.ColumnDefinitions>
1717
<ColumnDefinition Width="180" />
1818
<ColumnDefinition />
19+
<ColumnDefinition />
1920
</Grid.ColumnDefinitions>
2021
<TextBlock Margin="20 10 10 10" FontSize="14" Grid.Row="0" Grid.Column="0" VerticalAlignment="Center"
2122
HorizontalAlignment="Left" Text="Current Action Keyword:" />
2223
<TextBox Name="txtCurrentActionKeyword"
2324
Margin="10" Grid.Row="0" Width="105" Grid.Column="1"
2425
VerticalAlignment="Center"
2526
HorizontalAlignment="Left" />
26-
27-
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Grid.Row="1" Grid.Column="1">
27+
<CheckBox Name="chkActionKeywordEnabled" Margin="10" Grid.Row="0" Grid.Column="2" Content="Enabled" Width="auto"
28+
VerticalAlignment="Center" Checked="OnActionKeywordEnabledChecked" Unchecked="OnActionKeywordEnabledUnChecked"/>
29+
<StackPanel Orientation="Horizontal" Grid.Column="1" Grid.ColumnSpan="2" Margin="100 92 0 0" Grid.RowSpan="2">
2830
<Button Click="OnConfirmButtonClick"
2931
Margin="10 0 10 0" Width="80" Height="35"
3032
Content="OK" />

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

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,17 @@ public ActionKeywordSetting(SettingsViewModel settingsViewModel,
3333
txtCurrentActionKeyword.Text = selectedActionKeyword.Keyword;
3434

3535
this.actionKeywordListView = actionKeywordListView;
36+
37+
// Search and File Content action keyword are not allowed to be disabled, they are the default search keywords.
38+
if (currentActionKeyword.KeywordProperty == ActionKeywordProperty.SearchActionKeyword
39+
|| currentActionKeyword.KeywordProperty == ActionKeywordProperty.FileContentSearchActionKeyword)
40+
chkActionKeywordEnabled.Visibility = Visibility.Collapsed;
41+
42+
if (currentActionKeyword.KeywordProperty == ActionKeywordProperty.IndexOnlySearchActionKeyword)
43+
chkActionKeywordEnabled.IsChecked = this.settings.EnabledIndexOnlySearchKeyword;
44+
45+
if (currentActionKeyword.KeywordProperty == ActionKeywordProperty.PathSearchActionKeyword)
46+
chkActionKeywordEnabled.IsChecked = this.settings.EnabledPathSearchKeyword;
3647
}
3748

3849
private void OnConfirmButtonClick(object sender, RoutedEventArgs e)
@@ -42,6 +53,24 @@ private void OnConfirmButtonClick(object sender, RoutedEventArgs e)
4253
if (string.IsNullOrEmpty(newActionKeyword))
4354
return;
4455

56+
if (currentActionKeyword.KeywordProperty == ActionKeywordProperty.IndexOnlySearchActionKeyword)
57+
{
58+
// reset to global so it does not take up an action keyword when disabled
59+
if (!currentActionKeyword.Enabled && newActionKeyword != Query.GlobalPluginWildcardSign)
60+
settingsViewModel.UpdateActionKeyword(currentActionKeyword.KeywordProperty, Query.GlobalPluginWildcardSign, currentActionKeyword.Keyword);
61+
62+
settings.EnabledIndexOnlySearchKeyword = currentActionKeyword.Enabled;
63+
}
64+
65+
if (currentActionKeyword.KeywordProperty == ActionKeywordProperty.PathSearchActionKeyword)
66+
{
67+
// reset to global so it does not take up an action keyword when disabled
68+
if (!currentActionKeyword.Enabled && newActionKeyword != Query.GlobalPluginWildcardSign)
69+
settingsViewModel.UpdateActionKeyword(currentActionKeyword.KeywordProperty, Query.GlobalPluginWildcardSign, currentActionKeyword.Keyword);
70+
71+
settings.EnabledPathSearchKeyword = currentActionKeyword.Enabled;
72+
}
73+
4574
if (newActionKeyword == currentActionKeyword.Keyword)
4675
{
4776
Close();
@@ -63,6 +92,15 @@ private void OnConfirmButtonClick(object sender, RoutedEventArgs e)
6392

6493
actionKeywordListView.FirstOrDefault(x => x.Description == currentActionKeyword.Description).Keyword = newActionKeyword;
6594

95+
// automatically help users set this to enabled if an action keyword is set and currently disabled
96+
if (currentActionKeyword.KeywordProperty == ActionKeywordProperty.IndexOnlySearchActionKeyword
97+
&& !settings.EnabledIndexOnlySearchKeyword)
98+
settings.EnabledIndexOnlySearchKeyword = true;
99+
100+
if (currentActionKeyword.KeywordProperty == ActionKeywordProperty.PathSearchActionKeyword
101+
&& !settings.EnabledPathSearchKeyword)
102+
settings.EnabledPathSearchKeyword = true;
103+
66104
Close();
67105

68106
return;
@@ -77,5 +115,14 @@ private void OnCancelButtonClick(object sender, RoutedEventArgs e)
77115

78116
return;
79117
}
118+
private void OnActionKeywordEnabledChecked(object sender, RoutedEventArgs e)
119+
{
120+
currentActionKeyword.Enabled = true;
121+
}
122+
123+
private void OnActionKeywordEnabledUnChecked(object sender, RoutedEventArgs e)
124+
{
125+
currentActionKeyword.Enabled = false;
126+
}
80127
}
81128
}

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

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,26 +38,36 @@ public ExplorerSettings(SettingsViewModel viewModel)
3838
new ()
3939
{
4040
Description = viewModel.Context.API.GetTranslation("plugin_explorer_actionkeywordview_search"),
41-
Keyword = this.viewModel.Settings.SearchActionKeyword,
42-
KeywordProperty = ActionKeywordProperty.SearchActionKeyword
41+
Keyword = viewModel.Settings.SearchActionKeyword,
42+
KeywordProperty = ActionKeywordProperty.SearchActionKeyword,
43+
Enabled = true
4344
},
4445
new ()
4546
{
4647
Description = viewModel.Context.API.GetTranslation("plugin_explorer_actionkeywordview_filecontentsearch"),
47-
Keyword = this.viewModel.Settings.FileContentSearchActionKeyword,
48-
KeywordProperty = ActionKeywordProperty.FileContentSearchActionKeyword
48+
Keyword = viewModel.Settings.FileContentSearchActionKeyword,
49+
KeywordProperty = ActionKeywordProperty.FileContentSearchActionKeyword,
50+
Enabled = true
4951
},
5052
new ()
5153
{
52-
Description = viewModel.Context.API.GetTranslation("plugin_explorer_actionkeywordview_path"),
53-
Keyword = this.viewModel.Settings.PathSearchActionKeyword,
54-
KeywordProperty = ActionKeywordProperty.PathSearchActionKeyword
54+
Description = viewModel.Settings.EnabledPathSearchKeyword
55+
? viewModel.Context.API.GetTranslation("plugin_explorer_actionkeywordview_path")
56+
: viewModel.Context.API.GetTranslation("plugin_explorer_actionkeywordview_path")
57+
+ " " + viewModel.Context.API.GetTranslation("plugin_explorer_actionkeywordview_brackets_disabled"),
58+
Keyword = viewModel.Settings.PathSearchActionKeyword,
59+
KeywordProperty = ActionKeywordProperty.PathSearchActionKeyword,
60+
Enabled = viewModel.Settings.EnabledPathSearchKeyword
5561
},
5662
new ()
5763
{
58-
Description = viewModel.Context.API.GetTranslation("plugin_explorer_actionkeywordview_indexonlysearch"),
59-
Keyword = this.viewModel.Settings.IndexOnlySearchActionKeyword,
60-
KeywordProperty = ActionKeywordProperty.IndexOnlySearchActionKeyword
64+
Description = viewModel.Settings.EnabledIndexOnlySearchKeyword
65+
? viewModel.Context.API.GetTranslation("plugin_explorer_actionkeywordview_indexonlysearch")
66+
: viewModel.Context.API.GetTranslation("plugin_explorer_actionkeywordview_indexonlysearch")
67+
+ " " + viewModel.Context.API.GetTranslation("plugin_explorer_actionkeywordview_brackets_disabled"),
68+
Keyword = viewModel.Settings.IndexOnlySearchActionKeyword,
69+
KeywordProperty = ActionKeywordProperty.IndexOnlySearchActionKeyword,
70+
Enabled = viewModel.Settings.EnabledIndexOnlySearchKeyword
6171
}
6272
};
6373

@@ -330,6 +340,9 @@ public class ActionKeywordView
330340
public string Description { get; set; }
331341

332342
public ActionKeywordProperty KeywordProperty { get; init; }
343+
333344
public string Keyword { get; set; }
345+
346+
public bool Enabled { get; set; }
334347
}
335348
}

0 commit comments

Comments
 (0)