diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs index e62fc822c..8082da1dc 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs @@ -26,6 +26,7 @@ namespace Flow.Launcher.Plugin.Explorer.Search { private static PathEqualityComparator instance; public static PathEqualityComparator Instance => instance ??= new PathEqualityComparator(); + public bool Equals(Result x, Result y) { return x.SubTitle == y.SubTitle; @@ -46,16 +47,19 @@ namespace Flow.Launcher.Plugin.Explorer.Search var result = new HashSet(PathEqualityComparator.Instance); - if (ActionKeywordMatch(query, Settings.ActionKeyword.PathSearchActionKeyword) || ActionKeywordMatch(query, Settings.ActionKeyword.SearchActionKeyword)) + if (ActionKeywordMatch(query, Settings.ActionKeyword.PathSearchActionKeyword) || + ActionKeywordMatch(query, Settings.ActionKeyword.SearchActionKeyword)) { result.UnionWith(await PathSearchAsync(query, token).ConfigureAwait(false)); } - if ((ActionKeywordMatch(query, Settings.ActionKeyword.IndexOnlySearchActionKeyword) || ActionKeywordMatch(query, Settings.ActionKeyword.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(); @@ -63,19 +67,19 @@ namespace Flow.Launcher.Plugin.Explorer.Search private bool ActionKeywordMatch(Query query, Settings.ActionKeyword allowedActionKeyword) { - if (query.ActionKeyword == settings.IndexOnlySearchActionKeyword) - return Settings.ActionKeyword.IndexOnlySearchActionKeyword == allowedActionKeyword && settings.EnabledIndexOnlySearchKeyword; + var keyword = query.ActionKeyword.Length == 0 ? "*" : query.ActionKeyword; - if (query.ActionKeyword == settings.PathSearchActionKeyword) - return Settings.ActionKeyword.PathSearchActionKeyword == allowedActionKeyword && settings.EnabledPathSearchKeyword; - - if (query.ActionKeyword == settings.SearchActionKeyword) - return Settings.ActionKeyword.SearchActionKeyword == allowedActionKeyword; - - - return (Settings.ActionKeyword.IndexOnlySearchActionKeyword == allowedActionKeyword && settings.EnabledIndexOnlySearchKeyword) - || (Settings.ActionKeyword.PathSearchActionKeyword == allowedActionKeyword && settings.EnabledPathSearchKeyword) - || settings.SearchActionKeyword == Query.GlobalPluginWildcardSign; + 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) @@ -129,7 +133,8 @@ namespace Flow.Launcher.Plugin.Explorer.Search 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); @@ -137,11 +142,11 @@ namespace Flow.Launcher.Plugin.Explorer.Search 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) @@ -168,28 +173,30 @@ namespace Flow.Launcher.Plugin.Explorer.Search 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) @@ -200,11 +207,11 @@ namespace Flow.Launcher.Plugin.Explorer.Search 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 aaf4d2977..790e57439 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,6 +21,7 @@ namespace Flow.Launcher.Plugin.Explorer 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; @@ -36,5 +40,38 @@ namespace Flow.Launcher.Plugin.Explorer 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 bc2e6ba09..3403fef3f 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/ViewModels/SettingsViewModel.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/ViewModels/SettingsViewModel.cs @@ -41,22 +41,22 @@ namespace Flow.Launcher.Plugin.Explorer.ViewModels Process.Start(psi); } - internal void UpdateActionKeyword(ActionKeywordProperty modifiedActionKeyword, string newActionKeyword, string oldActionKeyword) + internal void UpdateActionKeyword(Settings.ActionKeyword modifiedActionKeyword, string newActionKeyword, string oldActionKeyword) { 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 ActionKeywordProperty.IndexOnlySearchActionKeyword: + case Settings.ActionKeyword.IndexOnlySearchActionKeyword: Settings.IndexOnlySearchActionKeyword = newActionKeyword; break; } @@ -66,12 +66,4 @@ namespace Flow.Launcher.Plugin.Explorer.ViewModels internal bool IsNewActionKeywordGlobal(string newActionKeyword) => newActionKeyword == Query.GlobalPluginWildcardSign; } - - public enum ActionKeywordProperty - { - SearchActionKeyword, - PathSearchActionKeyword, - FileContentSearchActionKeyword, - IndexOnlySearchActionKeyword - } } diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Views/ActionKeywordSetting.xaml b/Plugins/Flow.Launcher.Plugin.Explorer/Views/ActionKeywordSetting.xaml index b49ae3465..52df61a5f 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"> @@ -20,12 +21,15 @@ - - + HorizontalAlignment="Left" + Text="{Binding CurrentActionKeyword.Keyword}" /> +