diff --git a/Flow.Launcher.Core/Plugin/PluginManager.cs b/Flow.Launcher.Core/Plugin/PluginManager.cs index e2c009ee3aa..7fe771253b0 100644 --- a/Flow.Launcher.Core/Plugin/PluginManager.cs +++ b/Flow.Launcher.Core/Plugin/PluginManager.cs @@ -274,7 +274,7 @@ public static void AddActionKeyword(string id, string newActionKeyword) } /// - /// used to add action keyword for multiple action keyword plugin + /// used to remove action keyword for multiple action keyword plugin /// e.g. web search /// public static void RemoveActionKeyword(string id, string oldActionkeyword) 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..8082da1dc0d 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs @@ -26,6 +26,7 @@ private class PathEqualityComparator : IEqualityComparer { private static PathEqualityComparator instance; public static PathEqualityComparator Instance => instance ??= new PathEqualityComparator(); + public bool Equals(Result x, Result y) { return x.SubTitle == y.SubTitle; @@ -46,25 +47,39 @@ internal async Task> SearchAsync(Query query, CancellationToken tok var result = new HashSet(PathEqualityComparator.Instance); - if (ActionKeywordMatch(query, settings.PathSearchActionKeyword)) + if (ActionKeywordMatch(query, Settings.ActionKeyword.PathSearchActionKeyword) || + ActionKeywordMatch(query, Settings.ActionKeyword.SearchActionKeyword)) { result.UnionWith(await PathSearchAsync(query, token).ConfigureAwait(false)); } - if (ActionKeywordMatch(query, settings.SearchActionKeyword) && - querySearch.Length > 0 && - !querySearch.IsLocationPathString()) + if ((ActionKeywordMatch(query, Settings.ActionKeyword.IndexOnlySearchActionKeyword) || + ActionKeywordMatch(query, Settings.ActionKeyword.SearchActionKeyword)) && + querySearch.Length > 0 && + !querySearch.IsLocationPathString()) { - result.UnionWith(await WindowsIndexFilesAndFoldersSearchAsync(query, querySearch, token).ConfigureAwait(false)); + result.UnionWith(await WindowsIndexFilesAndFoldersSearchAsync(query, querySearch, token) + .ConfigureAwait(false)); } return result.ToList(); } - private bool ActionKeywordMatch(Query query, string actionKeyword) + private bool ActionKeywordMatch(Query query, Settings.ActionKeyword allowedActionKeyword) { - return query.ActionKeyword == actionKeyword || - query.ActionKeyword.Length == 0 && actionKeyword == Query.GlobalPluginWildcardSign; + var keyword = query.ActionKeyword.Length == 0 ? "*" : query.ActionKeyword; + + return allowedActionKeyword switch + { + Settings.ActionKeyword.SearchActionKeyword => settings.EnableSearchActionKeyword && + keyword == settings.SearchActionKeyword, + Settings.ActionKeyword.PathSearchActionKeyword => settings.EnabledPathSearchKeyword && + keyword == settings.PathSearchActionKeyword, + Settings.ActionKeyword.FileContentSearchActionKeyword => keyword == + settings.FileContentSearchActionKeyword, + Settings.ActionKeyword.IndexOnlySearchActionKeyword => settings.EnabledIndexOnlySearchKeyword && + keyword == settings.IndexOnlySearchActionKeyword + }; } public async Task> PathSearchAsync(Query query, CancellationToken token = default) @@ -118,7 +133,8 @@ public async Task> PathSearchAsync(Query query, CancellationToken t return results.ToList(); } - private async Task> WindowsIndexFileContentSearchAsync(Query query, string querySearchString, CancellationToken token) + private async Task> WindowsIndexFileContentSearchAsync(Query query, string querySearchString, + CancellationToken token) { var queryConstructor = new QueryConstructor(settings); @@ -126,11 +142,11 @@ private async Task> WindowsIndexFileContentSearchAsync(Query query, return new List(); return await IndexSearch.WindowsIndexSearchAsync(querySearchString, - queryConstructor.CreateQueryHelper().ConnectionString, - queryConstructor.QueryForFileContentSearch, - settings.IndexSearchExcludedSubdirectoryPaths, - query, - token).ConfigureAwait(false); + queryConstructor.CreateQueryHelper().ConnectionString, + queryConstructor.QueryForFileContentSearch, + settings.IndexSearchExcludedSubdirectoryPaths, + query, + token).ConfigureAwait(false); } public bool IsFileContentSearch(string actionKeyword) @@ -157,28 +173,30 @@ public async Task> TopLevelDirectorySearchBehaviourAsync( return await windowsIndexSearch(query, querySearchString, token); } - private async Task> WindowsIndexFilesAndFoldersSearchAsync(Query query, string querySearchString, CancellationToken token) + private async Task> WindowsIndexFilesAndFoldersSearchAsync(Query query, string querySearchString, + CancellationToken token) { var queryConstructor = new QueryConstructor(settings); return await IndexSearch.WindowsIndexSearchAsync(querySearchString, - queryConstructor.CreateQueryHelper().ConnectionString, - queryConstructor.QueryForAllFilesAndFolders, - settings.IndexSearchExcludedSubdirectoryPaths, - query, - token).ConfigureAwait(false); + queryConstructor.CreateQueryHelper().ConnectionString, + queryConstructor.QueryForAllFilesAndFolders, + settings.IndexSearchExcludedSubdirectoryPaths, + query, + token).ConfigureAwait(false); } - private async Task> WindowsIndexTopLevelFolderSearchAsync(Query query, string path, CancellationToken token) + private async Task> WindowsIndexTopLevelFolderSearchAsync(Query query, string path, + CancellationToken token) { var queryConstructor = new QueryConstructor(settings); return await IndexSearch.WindowsIndexSearchAsync(path, - queryConstructor.CreateQueryHelper().ConnectionString, - queryConstructor.QueryForTopLevelDirectorySearch, - settings.IndexSearchExcludedSubdirectoryPaths, - query, - token).ConfigureAwait(false); + queryConstructor.CreateQueryHelper().ConnectionString, + queryConstructor.QueryForTopLevelDirectorySearch, + settings.IndexSearchExcludedSubdirectoryPaths, + query, + token).ConfigureAwait(false); } private bool UseWindowsIndexForDirectorySearch(string locationPath) @@ -189,11 +207,11 @@ private bool UseWindowsIndexForDirectorySearch(string locationPath) return false; if (settings.IndexSearchExcludedSubdirectoryPaths - .Any(x => FilesFolders.ReturnPreviousDirectoryIfIncompleteString(pathToDirectory) - .StartsWith(x.Path, StringComparison.OrdinalIgnoreCase))) + .Any(x => FilesFolders.ReturnPreviousDirectoryIfIncompleteString(pathToDirectory) + .StartsWith(x.Path, StringComparison.OrdinalIgnoreCase))) return false; return IndexSearch.PathIsIndexed(pathToDirectory); } } -} +} \ No newline at end of file diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Settings.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Settings.cs index e078bca6781..790e57439f0 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Settings.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Settings.cs @@ -1,6 +1,9 @@ using Flow.Launcher.Plugin.Explorer.Search; using Flow.Launcher.Plugin.Explorer.Search.QuickAccessLinks; +using Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption; +using System; using System.Collections.Generic; +using System.IO; namespace Flow.Launcher.Plugin.Explorer { @@ -18,9 +21,57 @@ public class Settings public List IndexSearchExcludedSubdirectoryPaths { get; set; } = new List(); public string SearchActionKeyword { get; set; } = Query.GlobalPluginWildcardSign; + public bool EnableSearchActionKeyword { get; set; } = true; 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; } + + internal enum ActionKeyword + { + SearchActionKeyword, + PathSearchActionKeyword, + FileContentSearchActionKeyword, + IndexOnlySearchActionKeyword + } + + internal string GetActionKeyword(ActionKeyword actionKeyword) => actionKeyword switch + { + ActionKeyword.SearchActionKeyword => SearchActionKeyword, + ActionKeyword.PathSearchActionKeyword => PathSearchActionKeyword, + ActionKeyword.FileContentSearchActionKeyword => FileContentSearchActionKeyword, + ActionKeyword.IndexOnlySearchActionKeyword => IndexOnlySearchActionKeyword + }; + + internal void SetActionKeyword(ActionKeyword actionKeyword, string keyword) => _ = actionKeyword switch + { + ActionKeyword.SearchActionKeyword => SearchActionKeyword = keyword, + ActionKeyword.PathSearchActionKeyword => PathSearchActionKeyword = keyword, + ActionKeyword.FileContentSearchActionKeyword => FileContentSearchActionKeyword = keyword, + ActionKeyword.IndexOnlySearchActionKeyword => IndexOnlySearchActionKeyword = keyword, + _ => throw new ArgumentOutOfRangeException(nameof(actionKeyword), actionKeyword, "Unexpected property") + }; + + internal bool? GetActionKeywordEnable(ActionKeyword actionKeyword) => actionKeyword switch + { + ActionKeyword.SearchActionKeyword => EnableSearchActionKeyword, + ActionKeyword.PathSearchActionKeyword => EnabledPathSearchKeyword, + ActionKeyword.IndexOnlySearchActionKeyword => EnabledIndexOnlySearchKeyword, + _ => null + }; + + internal void SetActionKeywordEnable(ActionKeyword actionKeyword, bool enable) => _ = actionKeyword switch + { + ActionKeyword.SearchActionKeyword => EnableSearchActionKeyword = enable, + ActionKeyword.PathSearchActionKeyword => EnabledPathSearchKeyword = enable, + ActionKeyword.IndexOnlySearchActionKeyword => EnabledIndexOnlySearchKeyword = enable, + _ => throw new ArgumentOutOfRangeException(nameof(actionKeyword), actionKeyword, "Unexpected property") + }; } } \ 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..3403fef3f79 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/ViewModels/SettingsViewModel.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/ViewModels/SettingsViewModel.cs @@ -41,24 +41,24 @@ internal void OpenWindowsIndexingOptions() Process.Start(psi); } - internal void UpdateActionKeyword(ActionKeywordProperty modifiedActionKeyword, string newActionKeyword, string oldActionKeyword) + internal void UpdateActionKeyword(Settings.ActionKeyword modifiedActionKeyword, string newActionKeyword, string oldActionKeyword) { - if (Settings.SearchActionKeyword == Settings.PathSearchActionKeyword) - PluginManager.AddActionKeyword(Context.CurrentPluginMetadata.ID, newActionKeyword); - else - PluginManager.ReplaceActionKeyword(Context.CurrentPluginMetadata.ID, oldActionKeyword, newActionKeyword); + PluginManager.ReplaceActionKeyword(Context.CurrentPluginMetadata.ID, oldActionKeyword, newActionKeyword); switch (modifiedActionKeyword) { - case ActionKeywordProperty.SearchActionKeyword: + case Settings.ActionKeyword.SearchActionKeyword: Settings.SearchActionKeyword = newActionKeyword; break; - case ActionKeywordProperty.PathSearchActionKeyword: + case Settings.ActionKeyword.PathSearchActionKeyword: Settings.PathSearchActionKeyword = newActionKeyword; break; - case ActionKeywordProperty.FileContentSearchActionKeyword: + case Settings.ActionKeyword.FileContentSearchActionKeyword: Settings.FileContentSearchActionKeyword = newActionKeyword; break; + case Settings.ActionKeyword.IndexOnlySearchActionKeyword: + Settings.IndexOnlySearchActionKeyword = newActionKeyword; + break; } } @@ -66,11 +66,4 @@ internal void UpdateActionKeyword(ActionKeywordProperty modifiedActionKeyword, s internal bool IsNewActionKeywordGlobal(string newActionKeyword) => newActionKeyword == Query.GlobalPluginWildcardSign; } - - public enum ActionKeywordProperty - { - SearchActionKeyword, - PathSearchActionKeyword, - FileContentSearchActionKeyword - } } diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Views/ActionKeywordSetting.xaml b/Plugins/Flow.Launcher.Plugin.Explorer/Views/ActionKeywordSetting.xaml index 0e1c7e87265..52df61a5f4d 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Views/ActionKeywordSetting.xaml +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Views/ActionKeywordSetting.xaml @@ -7,6 +7,7 @@ mc:Ignorable="d" ResizeMode="NoResize" WindowStartupLocation="CenterScreen" + DataContext="{Binding RelativeSource={RelativeSource Self}}" Title="Action Keyword Setting" Height="200" Width="500"> @@ -16,15 +17,20 @@ + - - - + HorizontalAlignment="Left" + Text="{Binding CurrentActionKeyword.Keyword}" /> + +