From 0067fe86c68c38fd3c9679dbefabf34ebdfc4097 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=98=E9=9F=AC=20=E5=BC=A0?= Date: Wed, 19 May 2021 16:55:29 +0800 Subject: [PATCH 01/57] WebSearch UI Improvement --- .../SettingsControl.xaml | 43 ++++++++-- .../SettingsControl.xaml.cs | 82 +++++++++++++++++++ 2 files changed, 120 insertions(+), 5 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.WebSearch/SettingsControl.xaml b/Plugins/Flow.Launcher.Plugin.WebSearch/SettingsControl.xaml index ae6f8c800..707e4b037 100644 --- a/Plugins/Flow.Launcher.Plugin.WebSearch/SettingsControl.xaml +++ b/Plugins/Flow.Launcher.Plugin.WebSearch/SettingsControl.xaml @@ -13,6 +13,24 @@ + + + + + + + + + + + + @@ -47,23 +65,38 @@ + BorderThickness="1" + GridViewColumnHeader.Click="SortByColumn" + MouseDoubleClick="MouseDoubleClickItem"> - + - + - + - + + + + + + + + diff --git a/Plugins/Flow.Launcher.Plugin.WebSearch/SettingsControl.xaml.cs b/Plugins/Flow.Launcher.Plugin.WebSearch/SettingsControl.xaml.cs index 16ef38cff..30e5a5132 100644 --- a/Plugins/Flow.Launcher.Plugin.WebSearch/SettingsControl.xaml.cs +++ b/Plugins/Flow.Launcher.Plugin.WebSearch/SettingsControl.xaml.cs @@ -2,6 +2,8 @@ using Microsoft.Win32; using System.Windows; using System.Windows.Controls; using Flow.Launcher.Core.Plugin; +using System.ComponentModel; +using System.Windows.Data; namespace Flow.Launcher.Plugin.WebSearch { @@ -88,5 +90,85 @@ namespace Flow.Launcher.Plugin.WebSearch { _settings.BrowserPath = browserPathBox.Text; } + + GridViewColumnHeader _lastHeaderClicked = null; + ListSortDirection _lastDirection = ListSortDirection.Ascending; + + private void SortByColumn(object sender, RoutedEventArgs e) + { + ListSortDirection direction; + + if (e.OriginalSource is not GridViewColumnHeader headerClicked) + { + return; + } + + if (headerClicked.Role == GridViewColumnHeaderRole.Padding) + { + return; + } + + if (headerClicked != _lastHeaderClicked) + { + direction = ListSortDirection.Ascending; + } + else + { + if (_lastDirection == ListSortDirection.Ascending) + { + direction = ListSortDirection.Descending; + } + else + { + direction = ListSortDirection.Ascending; + } + } + + var columnBinding = headerClicked.Column.DisplayMemberBinding as Binding; + var sortBy = columnBinding?.Path.Path ?? headerClicked.Column.Header as string; + + Sort(sortBy, direction); + + if (direction == ListSortDirection.Ascending) + { + headerClicked.Column.HeaderTemplate = + Resources["HeaderTemplateArrowUp"] as DataTemplate; + } + else + { + headerClicked.Column.HeaderTemplate = + Resources["HeaderTemplateArrowDown"] as DataTemplate; + } + + // Remove arrow from previously sorted header + if (_lastHeaderClicked != null && _lastHeaderClicked != headerClicked) + { + _lastHeaderClicked.Column.HeaderTemplate = null; + } + + _lastHeaderClicked = headerClicked; + _lastDirection = direction; + } + private void Sort(string sortBy, ListSortDirection direction) + { + ICollectionView dataView = CollectionViewSource.GetDefaultView(SearchSourcesListView.ItemsSource); + dataView.SortDescriptions.Clear(); + SortDescription sd = new(sortBy, direction); + dataView.SortDescriptions.Add(sd); + dataView.Refresh(); + } + + private void MouseDoubleClickItem(object sender, System.Windows.Input.MouseButtonEventArgs e) + { + if (((FrameworkElement)e.OriginalSource).DataContext is SearchSource && _settings.SelectedSearchSource != null) + { + var webSearch = new SearchSourceSettingWindow + ( + _settings.SearchSources, _context, _settings.SelectedSearchSource + ); + + webSearch.ShowDialog(); + } + } } } From e8cf5ee0c1be684b7f1293d5b5b6b82ca50f0e07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=98=E9=9F=AC=20=E5=BC=A0?= Date: Wed, 19 May 2021 18:59:19 +0800 Subject: [PATCH 02/57] Use ConcurrentDictionary to replace Dictionary --- Flow.Launcher/PublicAPIInstance.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Flow.Launcher/PublicAPIInstance.cs b/Flow.Launcher/PublicAPIInstance.cs index b3f7b8d4f..f3403696e 100644 --- a/Flow.Launcher/PublicAPIInstance.cs +++ b/Flow.Launcher/PublicAPIInstance.cs @@ -21,6 +21,7 @@ using JetBrains.Annotations; using System.Runtime.CompilerServices; using Flow.Launcher.Infrastructure.Logger; using Flow.Launcher.Infrastructure.Storage; +using System.Collections.Concurrent; namespace Flow.Launcher { @@ -144,7 +145,7 @@ namespace Flow.Launcher public void LogException(string className, string message, Exception e, [CallerMemberName] string methodName = "") => Log.Exception(className, message, e, methodName); - private readonly Dictionary _pluginJsonStorages = new(); + private readonly ConcurrentDictionary _pluginJsonStorages = new(); public void SavePluginSettings() { From c6847326ad699d3f6ac36fc0b6d48cde99ded77d Mon Sep 17 00:00:00 2001 From: Jeremy Date: Thu, 20 May 2021 08:36:43 +1000 Subject: [PATCH 03/57] adjusted width of columns --- Plugins/Flow.Launcher.Plugin.WebSearch/SettingsControl.xaml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.WebSearch/SettingsControl.xaml b/Plugins/Flow.Launcher.Plugin.WebSearch/SettingsControl.xaml index 707e4b037..96bb7c4eb 100644 --- a/Plugins/Flow.Launcher.Plugin.WebSearch/SettingsControl.xaml +++ b/Plugins/Flow.Launcher.Plugin.WebSearch/SettingsControl.xaml @@ -76,7 +76,8 @@ + DisplayMemberBinding="{Binding Title}" + Width="130"> @@ -93,7 +94,7 @@ + Width="388"> From f5dee93a397971eb6c9036f37f492bf9ddd937c6 Mon Sep 17 00:00:00 2001 From: Jeremy Date: Thu, 20 May 2021 08:38:02 +1000 Subject: [PATCH 04/57] version bump WebSearch --- Plugins/Flow.Launcher.Plugin.WebSearch/plugin.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/Flow.Launcher.Plugin.WebSearch/plugin.json b/Plugins/Flow.Launcher.Plugin.WebSearch/plugin.json index 705f1529d..679f976d3 100644 --- a/Plugins/Flow.Launcher.Plugin.WebSearch/plugin.json +++ b/Plugins/Flow.Launcher.Plugin.WebSearch/plugin.json @@ -26,7 +26,7 @@ "Name": "Web Searches", "Description": "Provide the web search ability", "Author": "qianlifeng", - "Version": "1.3.9", + "Version": "1.4.0", "Language": "csharp", "Website": "https://github.com/Flow-Launcher/Flow.Launcher", "ExecuteFileName": "Flow.Launcher.Plugin.WebSearch.dll", From 117402de76a4b282235d6074f6860fab268e74b8 Mon Sep 17 00:00:00 2001 From: Jeremy Date: Thu, 20 May 2021 12:57:48 +1000 Subject: [PATCH 05/57] allow url column to auto adjust --- Plugins/Flow.Launcher.Plugin.WebSearch/SettingsControl.xaml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.WebSearch/SettingsControl.xaml b/Plugins/Flow.Launcher.Plugin.WebSearch/SettingsControl.xaml index 96bb7c4eb..c2f64bc7e 100644 --- a/Plugins/Flow.Launcher.Plugin.WebSearch/SettingsControl.xaml +++ b/Plugins/Flow.Launcher.Plugin.WebSearch/SettingsControl.xaml @@ -85,7 +85,8 @@ + DisplayMemberBinding="{Binding ActionKeyword}" + Width="137"> @@ -94,7 +95,7 @@ + Width="auto"> 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 06/57] 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"> - + - - - + + + +