diff --git a/Plugins/Flow.Launcher.Plugin.WebSearch/SettingsControl.xaml b/Plugins/Flow.Launcher.Plugin.WebSearch/SettingsControl.xaml index ae6f8c8005f..c2f64bc7eda 100644 --- a/Plugins/Flow.Launcher.Plugin.WebSearch/SettingsControl.xaml +++ b/Plugins/Flow.Launcher.Plugin.WebSearch/SettingsControl.xaml @@ -13,6 +13,24 @@ + + + + + + + + + + + + @@ -47,23 +65,40 @@ + 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(); + } + } } } 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",