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 1/4] 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 ae6f8c8005f..707e4b03748 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 16ef38cffa0..30e5a5132db 100644 --- a/Plugins/Flow.Launcher.Plugin.WebSearch/SettingsControl.xaml.cs +++ b/Plugins/Flow.Launcher.Plugin.WebSearch/SettingsControl.xaml.cs @@ -2,6 +2,8 @@ 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 @@ private void OnBrowserPathTextChanged(object sender, TextChangedEventArgs e) { _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 c6847326ad699d3f6ac36fc0b6d48cde99ded77d Mon Sep 17 00:00:00 2001 From: Jeremy Date: Thu, 20 May 2021 08:36:43 +1000 Subject: [PATCH 2/4] 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 707e4b03748..96bb7c4eb86 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 3/4] 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 705f1529de3..679f976d316 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 4/4] 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 96bb7c4eb86..c2f64bc7eda 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">