From 7e799b5625b407cc0347e8331ef10c2c40de1834 Mon Sep 17 00:00:00 2001 From: Jeremy Date: Sat, 29 May 2021 20:08:34 +1000 Subject: [PATCH 1/6] keep search activation, enable and disable path and index search --- .../Languages/en.xaml | 2 + .../Search/SearchManager.cs | 15 ++++-- .../Flow.Launcher.Plugin.Explorer/Settings.cs | 6 +++ .../ViewModels/SettingsViewModel.cs | 6 ++- .../Views/ActionKeywordSetting.xaml | 6 ++- .../Views/ActionKeywordSetting.xaml.cs | 54 +++++++++++++++---- .../Views/ExplorerSettings.xaml.cs | 16 +++++- .../Flow.Launcher.Plugin.Explorer/plugin.json | 6 ++- 8 files changed, 88 insertions(+), 23 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Languages/en.xaml b/Plugins/Flow.Launcher.Plugin.Explorer/Languages/en.xaml index 3a1a1fb0597..71b16f159d6 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Languages/en.xaml +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Languages/en.xaml @@ -22,6 +22,8 @@ Index Search Activation: Path Explore Activation: File Content Search: + Index Only Search: + (Disabled) Explorer diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs index 1cb82b75ff5..4ff6070d43f 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs @@ -46,12 +46,12 @@ internal async Task> SearchAsync(Query query, CancellationToken tok var result = new HashSet(PathEqualityComparator.Instance); - if (ActionKeywordMatch(query, settings.PathSearchActionKeyword)) + if (ActionKeywordMatch(query, settings.PathSearchActionKeyword) || ActionKeywordMatch(query, settings.SearchActionKeyword)) { result.UnionWith(await PathSearchAsync(query, token).ConfigureAwait(false)); } - if (ActionKeywordMatch(query, settings.SearchActionKeyword) && + if ((ActionKeywordMatch(query, settings.IndexOnlySearchActionKeyword) || ActionKeywordMatch(query, settings.SearchActionKeyword)) && querySearch.Length > 0 && !querySearch.IsLocationPathString()) { @@ -61,10 +61,15 @@ internal async Task> SearchAsync(Query query, CancellationToken tok return result.ToList(); } - private bool ActionKeywordMatch(Query query, string actionKeyword) + private bool ActionKeywordMatch(Query query, string allowedActionKeyword) { - return query.ActionKeyword == actionKeyword || - query.ActionKeyword.Length == 0 && actionKeyword == Query.GlobalPluginWildcardSign; + if (settings.EnabledIndexOnlySearchKeyword && (settings.IndexOnlySearchActionKeyword == Query.GlobalPluginWildcardSign || query.ActionKeyword == allowedActionKeyword)) + return true; + + if (settings.EnabledPathSearchKeyword && (settings.PathSearchActionKeyword == Query.GlobalPluginWildcardSign || query.ActionKeyword == allowedActionKeyword)) + return true; + + return settings.SearchActionKeyword == Query.GlobalPluginWildcardSign || query.ActionKeyword == allowedActionKeyword; } public async Task> PathSearchAsync(Query query, CancellationToken token = default) diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Settings.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Settings.cs index e078bca6781..0359b00f788 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Settings.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Settings.cs @@ -22,5 +22,11 @@ public class Settings public string FileContentSearchActionKeyword { get; set; } = Constants.DefaultContentSearchActionKeyword; public string PathSearchActionKeyword { get; set; } = Query.GlobalPluginWildcardSign; + + public bool EnabledPathSearchKeyword { get; set; } + + public string IndexOnlySearchActionKeyword { get; set; } = Query.GlobalPluginWildcardSign; + + public bool EnabledIndexOnlySearchKeyword { get; set; } } } \ No newline at end of file diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/ViewModels/SettingsViewModel.cs b/Plugins/Flow.Launcher.Plugin.Explorer/ViewModels/SettingsViewModel.cs index 9d4019b9a57..ae84f92d495 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/ViewModels/SettingsViewModel.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/ViewModels/SettingsViewModel.cs @@ -59,6 +59,9 @@ internal void UpdateActionKeyword(ActionKeywordProperty modifiedActionKeyword, s case ActionKeywordProperty.FileContentSearchActionKeyword: Settings.FileContentSearchActionKeyword = newActionKeyword; break; + case ActionKeywordProperty.IndexOnlySearchActionKeyword: + Settings.IndexOnlySearchActionKeyword = newActionKeyword; + break; } } @@ -71,6 +74,7 @@ public enum ActionKeywordProperty { SearchActionKeyword, PathSearchActionKeyword, - FileContentSearchActionKeyword + FileContentSearchActionKeyword, + IndexOnlySearchActionKeyword } } diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Views/ActionKeywordSetting.xaml b/Plugins/Flow.Launcher.Plugin.Explorer/Views/ActionKeywordSetting.xaml index 0e1c7e87265..b49ae3465d2 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Views/ActionKeywordSetting.xaml +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Views/ActionKeywordSetting.xaml @@ -16,6 +16,7 @@ + @@ -23,8 +24,9 @@ Margin="10" Grid.Row="0" Width="105" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Left" /> - - + +