From 4a02cff498094b7ec971d2b043ca33851de5247e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=98=E9=9F=AC=20=E5=BC=A0?= Date: Thu, 20 May 2021 17:07:44 +0800 Subject: [PATCH] Implement Option to disable program description --- .../Languages/en.xaml | 1 + .../Languages/zh-cn.xaml | 1 + .../Programs/UWP.cs | 8 +-- .../Programs/Win32.cs | 44 ++++++-------- .../Flow.Launcher.Plugin.Program/Settings.cs | 1 + .../Views/ProgramSetting.xaml | 14 +++-- .../Views/ProgramSetting.xaml.cs | 60 ++++++++++++------- 7 files changed, 73 insertions(+), 56 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.Program/Languages/en.xaml b/Plugins/Flow.Launcher.Plugin.Program/Languages/en.xaml index c266aa6f6..ce84aa65b 100644 --- a/Plugins/Flow.Launcher.Plugin.Program/Languages/en.xaml +++ b/Plugins/Flow.Launcher.Plugin.Program/Languages/en.xaml @@ -14,6 +14,7 @@ Indexing Index Start Menu Index Registry + Enable Program Description Suffixes Max Depth diff --git a/Plugins/Flow.Launcher.Plugin.Program/Languages/zh-cn.xaml b/Plugins/Flow.Launcher.Plugin.Program/Languages/zh-cn.xaml index 7771cdf82..8632abb68 100644 --- a/Plugins/Flow.Launcher.Plugin.Program/Languages/zh-cn.xaml +++ b/Plugins/Flow.Launcher.Plugin.Program/Languages/zh-cn.xaml @@ -14,6 +14,7 @@ 索引中 索引开始菜单 索引注册表 + 启用程序描述 后缀 最大深度 diff --git a/Plugins/Flow.Launcher.Plugin.Program/Programs/UWP.cs b/Plugins/Flow.Launcher.Plugin.Program/Programs/UWP.cs index 0aebc9e34..89d6dcc7d 100644 --- a/Plugins/Flow.Launcher.Plugin.Program/Programs/UWP.cs +++ b/Plugins/Flow.Launcher.Plugin.Program/Programs/UWP.cs @@ -63,14 +63,14 @@ namespace Flow.Launcher.Plugin.Program.Programs if (hResult == Hresult.Ok) { var apps = new List(); - + List _apps = _helper.getAppsFromManifest(stream); - foreach(var _app in _apps) + foreach (var _app in _apps) { var app = new Application(_app, this); apps.Add(app); } - + Apps = apps.Where(a => a.AppListEntry != "none").ToArray(); } else @@ -275,7 +275,7 @@ namespace Flow.Launcher.Plugin.Program.Programs MatchResult matchResult; // We suppose Name won't be null - if (Description == null || Name.StartsWith(Description)) + if (!Main._settings.EnableDescription || Description == null || Name.StartsWith(Description)) { title = Name; matchResult = StringMatcher.FuzzySearch(query, title); diff --git a/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs b/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs index 773d0c6b6..931cfacc1 100644 --- a/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs +++ b/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs @@ -54,51 +54,43 @@ namespace Flow.Launcher.Plugin.Program.Programs public Result Result(string query, IPublicAPI api) { string title; - - var nameMatchResult = StringMatcher.FuzzySearch(query, Name); - var descriptionMatchResult = StringMatcher.FuzzySearch(query, Description); - - var pathMatchResult = new MatchResult(false, 0, new List(), 0); - if (ExecutableName != null) // only lnk program will need this one - pathMatchResult = StringMatcher.FuzzySearch(query, ExecutableName); - - MatchResult matchResult = nameMatchResult; - - if (nameMatchResult.Score < descriptionMatchResult.Score) - matchResult = descriptionMatchResult; - - if (!matchResult.IsSearchPrecisionScoreMet()) - { - if (pathMatchResult.IsSearchPrecisionScoreMet()) - matchResult = pathMatchResult; - else return null; - } + MatchResult matchResult; // We suppose Name won't be null - if (Description == null || Name.StartsWith(Description)) + if (!Main._settings.EnableDescription || Description == null || Name.StartsWith(Description)) { title = Name; + matchResult = StringMatcher.FuzzySearch(query, title); } else if (Description.StartsWith(Name)) { title = Description; + matchResult = StringMatcher.FuzzySearch(query, Description); } else { title = $"{Name}: {Description}"; - - if (matchResult == descriptionMatchResult) + var nameMatch = StringMatcher.FuzzySearch(query, Name); + var desciptionMatch = StringMatcher.FuzzySearch(query, Description); + if (desciptionMatch.Score > nameMatch.Score) { - for (int i = 0; i < descriptionMatchResult.MatchData.Count; i++) + for (int i = 0; i < desciptionMatch.MatchData.Count; i++) { - matchResult.MatchData[i] += Name.Length + 2; // 2 is ": " + desciptionMatch.MatchData[i] += Name.Length + 2; // 2 is ": " } + matchResult = desciptionMatch; } + else matchResult = nameMatch; } - if (matchResult == pathMatchResult) + if (!matchResult.IsSearchPrecisionScoreMet()) { - // path Match won't have valid highlight data + if (ExecutableName != null) // only lnk program will need this one + matchResult = StringMatcher.FuzzySearch(query, ExecutableName); + + if (!matchResult.IsSearchPrecisionScoreMet()) + return null; + matchResult.MatchData = new List(); } diff --git a/Plugins/Flow.Launcher.Plugin.Program/Settings.cs b/Plugins/Flow.Launcher.Plugin.Program/Settings.cs index 7cb02a852..70e5bd4f5 100644 --- a/Plugins/Flow.Launcher.Plugin.Program/Settings.cs +++ b/Plugins/Flow.Launcher.Plugin.Program/Settings.cs @@ -13,6 +13,7 @@ namespace Flow.Launcher.Plugin.Program public bool EnableStartMenuSource { get; set; } = true; + public bool EnableDescription { get; set; } = true; public bool EnableRegistrySource { get; set; } = true; public string CustomizedExplorer { get; set; } = Explorer; public string CustomizedArgs { get; set; } = ExplorerArgs; diff --git a/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml b/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml index 90fda1756..45f2a609d 100644 --- a/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml +++ b/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml @@ -4,19 +4,21 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:program="clr-namespace:Flow.Launcher.Plugin.Program" + DataContext="{Binding RelativeSource={RelativeSource Self}}" mc:Ignorable="d" d:DesignHeight="404.508" d:DesignWidth="600"> - + - - - + + + +