From eeb38d84b3d5719adf551f5cef3b4379088a0282 Mon Sep 17 00:00:00 2001 From: Kevin Zhang Date: Fri, 2 Jul 2021 11:38:07 +0800 Subject: [PATCH 1/7] Fix up Actionkeyword for folder result --- Plugins/Flow.Launcher.Plugin.Explorer/Main.cs | 2 +- .../Search/ResultManager.cs | 41 +++++++++++++++---- 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Main.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Main.cs index 92b7c95a0bd..60208759ed0 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Main.cs @@ -46,7 +46,7 @@ public Task InitAsync(PluginInitContext context) contextMenu = new ContextMenu(Context, Settings, viewModel); searchManager = new SearchManager(Settings, Context); - ResultManager.Init(Context); + ResultManager.Init(Context, Settings); return Task.CompletedTask; } diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs index f756f8a0a7e..004e57cfb31 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs @@ -10,10 +10,12 @@ namespace Flow.Launcher.Plugin.Explorer.Search public static class ResultManager { private static PluginInitContext Context; + private static Settings Settings { get; set; } - public static void Init(PluginInitContext context) + public static void Init(PluginInitContext context, Settings settings) { Context = context; + Settings = settings; } internal static Result CreateFolderResult(string title, string subtitle, string path, Query query, int score = 0, bool showIndexState = false, bool windowsIndexed = false) @@ -41,15 +43,21 @@ internal static Result CreateFolderResult(string title, string subtitle, string } string changeTo = path.EndsWith(Constants.DirectorySeperator) ? path : path + Constants.DirectorySeperator; - Context.API.ChangeQuery(string.IsNullOrEmpty(query.ActionKeyword) ? + Context.API.ChangeQuery(Settings.PathSearchActionKeyword == "*" ? changeTo : - query.ActionKeyword + " " + changeTo); + $"{Settings.PathSearchActionKeyword} {changeTo}"); return false; }, Score = score, TitleToolTip = Constants.ToolTipOpenDirectory, SubTitleToolTip = Constants.ToolTipOpenDirectory, - ContextData = new SearchResult { Type = ResultType.Folder, FullPath = path, ShowIndexState = showIndexState, WindowsIndexed = windowsIndexed } + ContextData = new SearchResult + { + Type = ResultType.Folder, + FullPath = path, + ShowIndexState = showIndexState, + WindowsIndexed = windowsIndexed + } }; } @@ -57,7 +65,10 @@ internal static Result CreateOpenCurrentFolderResult(string path, bool windowsIn { var retrievedDirectoryPath = FilesFolders.ReturnPreviousDirectoryIfIncompleteString(path); - var folderName = retrievedDirectoryPath.TrimEnd(Constants.DirectorySeperator).Split(new[] { Path.DirectorySeparatorChar }, StringSplitOptions.None).Last(); + var folderName = retrievedDirectoryPath.TrimEnd(Constants.DirectorySeperator).Split(new[] + { + Path.DirectorySeparatorChar + }, StringSplitOptions.None).Last(); if (retrievedDirectoryPath.EndsWith(":\\")) { @@ -81,7 +92,7 @@ internal static Result CreateOpenCurrentFolderResult(string path, bool windowsIn { Title = title, SubTitle = $"Use > to search within {subtitleFolderName}, " + - $"* to search for file extensions or >* to combine both searches.", + $"* to search for file extensions or >* to combine both searches.", IcoPath = retrievedDirectoryPath, Score = 500, Action = c => @@ -91,7 +102,13 @@ internal static Result CreateOpenCurrentFolderResult(string path, bool windowsIn }, TitleToolTip = retrievedDirectoryPath, SubTitleToolTip = retrievedDirectoryPath, - ContextData = new SearchResult { Type = ResultType.Folder, FullPath = retrievedDirectoryPath, ShowIndexState = true, WindowsIndexed = windowsIndexed } + ContextData = new SearchResult + { + Type = ResultType.Folder, + FullPath = retrievedDirectoryPath, + ShowIndexState = true, + WindowsIndexed = windowsIndexed + } }; } @@ -126,7 +143,13 @@ internal static Result CreateFileResult(string filePath, Query query, int score }, TitleToolTip = Constants.ToolTipOpenContainingFolder, SubTitleToolTip = Constants.ToolTipOpenContainingFolder, - ContextData = new SearchResult { Type = ResultType.File, FullPath = filePath, ShowIndexState = showIndexState, WindowsIndexed = windowsIndexed } + ContextData = new SearchResult + { + Type = ResultType.File, + FullPath = filePath, + ShowIndexState = showIndexState, + WindowsIndexed = windowsIndexed + } }; return result; } @@ -148,4 +171,4 @@ public enum ResultType Folder, File } -} +} \ No newline at end of file From e8a9377ec48a6246563f3a8925fd8b1504c18188 Mon Sep 17 00:00:00 2001 From: Kevin Zhang Date: Fri, 2 Jul 2021 11:46:10 +0800 Subject: [PATCH 2/7] fix up logic --- .../Search/ResultManager.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs index 004e57cfb31..76736466f1e 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs @@ -28,7 +28,7 @@ internal static Result CreateFolderResult(string title, string subtitle, string TitleHighlightData = StringMatcher.FuzzySearch(query.Search, title).MatchData, Action = c => { - if (c.SpecialKeyState.CtrlPressed) + if (c.SpecialKeyState.CtrlPressed || !(Settings.EnabledPathSearchKeyword || Settings.EnableSearchActionKeyword)) { try { @@ -41,11 +41,13 @@ internal static Result CreateFolderResult(string title, string subtitle, string return false; } } + // one of it is enabled + var keyword = Settings.EnableSearchActionKeyword ? Settings.SearchActionKeyword : Settings.PathSearchActionKeyword; + + keyword = keyword == "*" ? "" : $"{keyword} "; string changeTo = path.EndsWith(Constants.DirectorySeperator) ? path : path + Constants.DirectorySeperator; - Context.API.ChangeQuery(Settings.PathSearchActionKeyword == "*" ? - changeTo : - $"{Settings.PathSearchActionKeyword} {changeTo}"); + Context.API.ChangeQuery($"{keyword}{changeTo}"); return false; }, Score = score, From 192d64bb2a72d259919a0e0df4eb660d6cecf68c Mon Sep 17 00:00:00 2001 From: Kevin Zhang Date: Sat, 3 Jul 2021 00:20:33 +0800 Subject: [PATCH 3/7] Use Constant Name --- .../Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs | 6 +++--- .../Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs | 2 +- Plugins/Flow.Launcher.Plugin.Explorer/Settings.cs | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs index 76736466f1e..8af757da93f 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs @@ -28,7 +28,7 @@ internal static Result CreateFolderResult(string title, string subtitle, string TitleHighlightData = StringMatcher.FuzzySearch(query.Search, title).MatchData, Action = c => { - if (c.SpecialKeyState.CtrlPressed || !(Settings.EnabledPathSearchKeyword || Settings.EnableSearchActionKeyword)) + if (c.SpecialKeyState.CtrlPressed || !(Settings.EnabledPathSearchKeyword || Settings.EnabledSearchActionKeyword)) { try { @@ -42,9 +42,9 @@ internal static Result CreateFolderResult(string title, string subtitle, string } } // one of it is enabled - var keyword = Settings.EnableSearchActionKeyword ? Settings.SearchActionKeyword : Settings.PathSearchActionKeyword; + var keyword = Settings.EnabledSearchActionKeyword ? Settings.SearchActionKeyword : Settings.PathSearchActionKeyword; - keyword = keyword == "*" ? "" : $"{keyword} "; + keyword = keyword == Query.GlobalPluginWildcardSign ? string.Empty : keyword + ""; string changeTo = path.EndsWith(Constants.DirectorySeperator) ? path : path + Constants.DirectorySeperator; Context.API.ChangeQuery($"{keyword}{changeTo}"); diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs index 6f3996b0dac..d98c5400a80 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs @@ -71,7 +71,7 @@ private bool ActionKeywordMatch(Query query, Settings.ActionKeyword allowedActio return allowedActionKeyword switch { - Settings.ActionKeyword.SearchActionKeyword => settings.EnableSearchActionKeyword && + Settings.ActionKeyword.SearchActionKeyword => settings.EnabledSearchActionKeyword && keyword == settings.SearchActionKeyword, Settings.ActionKeyword.PathSearchActionKeyword => settings.EnabledPathSearchKeyword && keyword == settings.PathSearchActionKeyword, diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Settings.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Settings.cs index bd6fe7e20de..26204616a6b 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Settings.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Settings.cs @@ -21,7 +21,7 @@ public class Settings public List IndexSearchExcludedSubdirectoryPaths { get; set; } = new List(); public string SearchActionKeyword { get; set; } = Query.GlobalPluginWildcardSign; - public bool EnableSearchActionKeyword { get; set; } = true; + public bool EnabledSearchActionKeyword { get; set; } = true; public string FileContentSearchActionKeyword { get; set; } = Constants.DefaultContentSearchActionKeyword; @@ -60,7 +60,7 @@ internal enum ActionKeyword internal bool? GetActionKeywordEnable(ActionKeyword actionKeyword) => actionKeyword switch { - ActionKeyword.SearchActionKeyword => EnableSearchActionKeyword, + ActionKeyword.SearchActionKeyword => EnabledSearchActionKeyword, ActionKeyword.PathSearchActionKeyword => EnabledPathSearchKeyword, ActionKeyword.IndexSearchActionKeyword => EnabledIndexOnlySearchKeyword, _ => null @@ -68,7 +68,7 @@ internal enum ActionKeyword internal void SetActionKeywordEnable(ActionKeyword actionKeyword, bool enable) => _ = actionKeyword switch { - ActionKeyword.SearchActionKeyword => EnableSearchActionKeyword = enable, + ActionKeyword.SearchActionKeyword => EnabledSearchActionKeyword = enable, ActionKeyword.PathSearchActionKeyword => EnabledPathSearchKeyword = enable, ActionKeyword.IndexSearchActionKeyword => EnabledIndexOnlySearchKeyword = enable, _ => throw new ArgumentOutOfRangeException(nameof(actionKeyword), actionKeyword, "Unexpected property") From 0c3a37eb706090b9016b2c4bd59a4d69dfbc9c7b Mon Sep 17 00:00:00 2001 From: Kevin Zhang Date: Sat, 3 Jul 2021 00:23:23 +0800 Subject: [PATCH 4/7] change logic --- Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs index 8af757da93f..f2d1cbe2af6 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs @@ -28,7 +28,7 @@ internal static Result CreateFolderResult(string title, string subtitle, string TitleHighlightData = StringMatcher.FuzzySearch(query.Search, title).MatchData, Action = c => { - if (c.SpecialKeyState.CtrlPressed || !(Settings.EnabledPathSearchKeyword || Settings.EnabledSearchActionKeyword)) + if (c.SpecialKeyState.CtrlPressed || (!Settings.EnabledPathSearchKeyword && !Settings.EnabledSearchActionKeyword)) { try { From 428efb1cd0f5c6a29013660e49e7e587e2b45fca Mon Sep 17 00:00:00 2001 From: Kevin Zhang Date: Sat, 3 Jul 2021 12:43:38 +0800 Subject: [PATCH 5/7] fix unexpected empty string --- Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs index f2d1cbe2af6..47a5a006c89 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs @@ -44,7 +44,7 @@ internal static Result CreateFolderResult(string title, string subtitle, string // one of it is enabled var keyword = Settings.EnabledSearchActionKeyword ? Settings.SearchActionKeyword : Settings.PathSearchActionKeyword; - keyword = keyword == Query.GlobalPluginWildcardSign ? string.Empty : keyword + ""; + keyword = keyword == Query.GlobalPluginWildcardSign ? string.Empty : keyword + " "; string changeTo = path.EndsWith(Constants.DirectorySeperator) ? path : path + Constants.DirectorySeperator; Context.API.ChangeQuery($"{keyword}{changeTo}"); From 0df9f373ce8a06bc3211f8bc94bc996691c65523 Mon Sep 17 00:00:00 2001 From: Kevin Zhang Date: Sat, 3 Jul 2021 12:45:00 +0800 Subject: [PATCH 6/7] Rename variables --- .../Search/ResultManager.cs | 4 ++-- .../Search/SearchManager.cs | 6 +++--- .../Flow.Launcher.Plugin.Explorer/Settings.cs | 18 +++++++++--------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs index 47a5a006c89..d0f78e14db8 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs @@ -28,7 +28,7 @@ internal static Result CreateFolderResult(string title, string subtitle, string TitleHighlightData = StringMatcher.FuzzySearch(query.Search, title).MatchData, Action = c => { - if (c.SpecialKeyState.CtrlPressed || (!Settings.EnabledPathSearchKeyword && !Settings.EnabledSearchActionKeyword)) + if (c.SpecialKeyState.CtrlPressed || (!Settings.PathSearchKeywordEnabled && !Settings.SearchActionKeywordEnabled)) { try { @@ -42,7 +42,7 @@ internal static Result CreateFolderResult(string title, string subtitle, string } } // one of it is enabled - var keyword = Settings.EnabledSearchActionKeyword ? Settings.SearchActionKeyword : Settings.PathSearchActionKeyword; + var keyword = Settings.SearchActionKeywordEnabled ? Settings.SearchActionKeyword : Settings.PathSearchActionKeyword; keyword = keyword == Query.GlobalPluginWildcardSign ? string.Empty : keyword + " "; diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs index d98c5400a80..2aa389f8950 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs @@ -71,13 +71,13 @@ private bool ActionKeywordMatch(Query query, Settings.ActionKeyword allowedActio return allowedActionKeyword switch { - Settings.ActionKeyword.SearchActionKeyword => settings.EnabledSearchActionKeyword && + Settings.ActionKeyword.SearchActionKeyword => settings.SearchActionKeywordEnabled && keyword == settings.SearchActionKeyword, - Settings.ActionKeyword.PathSearchActionKeyword => settings.EnabledPathSearchKeyword && + Settings.ActionKeyword.PathSearchActionKeyword => settings.PathSearchKeywordEnabled && keyword == settings.PathSearchActionKeyword, Settings.ActionKeyword.FileContentSearchActionKeyword => keyword == settings.FileContentSearchActionKeyword, - Settings.ActionKeyword.IndexSearchActionKeyword => settings.EnabledIndexOnlySearchKeyword && + Settings.ActionKeyword.IndexSearchActionKeyword => settings.IndexOnlySearchKeywordEnabled && keyword == settings.IndexSearchActionKeyword }; } diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Settings.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Settings.cs index 26204616a6b..985cb2fd93e 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Settings.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Settings.cs @@ -21,17 +21,17 @@ public class Settings public List IndexSearchExcludedSubdirectoryPaths { get; set; } = new List(); public string SearchActionKeyword { get; set; } = Query.GlobalPluginWildcardSign; - public bool EnabledSearchActionKeyword { get; set; } = true; + public bool SearchActionKeywordEnabled { get; set; } = true; public string FileContentSearchActionKeyword { get; set; } = Constants.DefaultContentSearchActionKeyword; public string PathSearchActionKeyword { get; set; } = Query.GlobalPluginWildcardSign; - public bool EnabledPathSearchKeyword { get; set; } + public bool PathSearchKeywordEnabled { get; set; } public string IndexSearchActionKeyword { get; set; } = Query.GlobalPluginWildcardSign; - public bool EnabledIndexOnlySearchKeyword { get; set; } + public bool IndexOnlySearchKeywordEnabled { get; set; } internal enum ActionKeyword { @@ -60,17 +60,17 @@ internal enum ActionKeyword internal bool? GetActionKeywordEnable(ActionKeyword actionKeyword) => actionKeyword switch { - ActionKeyword.SearchActionKeyword => EnabledSearchActionKeyword, - ActionKeyword.PathSearchActionKeyword => EnabledPathSearchKeyword, - ActionKeyword.IndexSearchActionKeyword => EnabledIndexOnlySearchKeyword, + ActionKeyword.SearchActionKeyword => SearchActionKeywordEnabled, + ActionKeyword.PathSearchActionKeyword => PathSearchKeywordEnabled, + ActionKeyword.IndexSearchActionKeyword => IndexOnlySearchKeywordEnabled, _ => null }; internal void SetActionKeywordEnable(ActionKeyword actionKeyword, bool enable) => _ = actionKeyword switch { - ActionKeyword.SearchActionKeyword => EnabledSearchActionKeyword = enable, - ActionKeyword.PathSearchActionKeyword => EnabledPathSearchKeyword = enable, - ActionKeyword.IndexSearchActionKeyword => EnabledIndexOnlySearchKeyword = enable, + ActionKeyword.SearchActionKeyword => SearchActionKeywordEnabled = enable, + ActionKeyword.PathSearchActionKeyword => PathSearchKeywordEnabled = enable, + ActionKeyword.IndexSearchActionKeyword => IndexOnlySearchKeywordEnabled = enable, _ => throw new ArgumentOutOfRangeException(nameof(actionKeyword), actionKeyword, "Unexpected property") }; } From 2d32bc981450708838f5c7e84d1c5e9d1e262b42 Mon Sep 17 00:00:00 2001 From: Jeremy Date: Sat, 3 Jul 2021 16:33:29 +1000 Subject: [PATCH 7/7] fix method typo --- Plugins/Flow.Launcher.Plugin.Explorer/Settings.cs | 4 ++-- .../Views/ExplorerSettings.xaml.cs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Settings.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Settings.cs index 985cb2fd93e..13f938dea1c 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Settings.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Settings.cs @@ -58,7 +58,7 @@ internal enum ActionKeyword _ => throw new ArgumentOutOfRangeException(nameof(actionKeyword), actionKeyword, "Unexpected property") }; - internal bool? GetActionKeywordEnable(ActionKeyword actionKeyword) => actionKeyword switch + internal bool? GetActionKeywordEnabled(ActionKeyword actionKeyword) => actionKeyword switch { ActionKeyword.SearchActionKeyword => SearchActionKeywordEnabled, ActionKeyword.PathSearchActionKeyword => PathSearchKeywordEnabled, @@ -66,7 +66,7 @@ internal enum ActionKeyword _ => null }; - internal void SetActionKeywordEnable(ActionKeyword actionKeyword, bool enable) => _ = actionKeyword switch + internal void SetActionKeywordEnabled(ActionKeyword actionKeyword, bool enable) => _ = actionKeyword switch { ActionKeyword.SearchActionKeyword => SearchActionKeywordEnabled = enable, ActionKeyword.PathSearchActionKeyword => PathSearchKeywordEnabled = enable, diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Views/ExplorerSettings.xaml.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Views/ExplorerSettings.xaml.cs index ffd5b618ad6..0c3799cee03 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Views/ExplorerSettings.xaml.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Views/ExplorerSettings.xaml.cs @@ -337,8 +337,8 @@ public string Keyword public bool? Enabled { - get => _settings.GetActionKeywordEnable(KeywordProperty); - set => _settings.SetActionKeywordEnable(KeywordProperty, + get => _settings.GetActionKeywordEnabled(KeywordProperty); + set => _settings.SetActionKeywordEnabled(KeywordProperty, value ?? throw new ArgumentException("Unexpected null value")); } }