mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
WebSearch UI Improvement
This commit is contained in:
parent
be8bb8bcd1
commit
0067fe86c6
2 changed files with 120 additions and 5 deletions
|
|
@ -13,6 +13,24 @@
|
|||
<Setter Property="Height" Value="28"/>
|
||||
<Setter Property="VerticalContentAlignment" Value="Center"/>
|
||||
</Style>
|
||||
<DataTemplate x:Key="HeaderTemplateArrowUp">
|
||||
<DockPanel>
|
||||
<TextBlock HorizontalAlignment="Center" Text="{Binding}"/>
|
||||
<Path x:Name="arrow"
|
||||
StrokeThickness = "1"
|
||||
Fill = "gray"
|
||||
Data = "M 5,10 L 15,10 L 10,5 L 5,10"/>
|
||||
</DockPanel>
|
||||
</DataTemplate>
|
||||
<DataTemplate x:Key="HeaderTemplateArrowDown">
|
||||
<DockPanel>
|
||||
<TextBlock HorizontalAlignment="Center" Text="{Binding }"/>
|
||||
<Path x:Name="arrow"
|
||||
StrokeThickness = "1"
|
||||
Fill = "gray"
|
||||
Data = "M 5,5 L 10,10 L 15,5 L 5,5"/>
|
||||
</DockPanel>
|
||||
</DataTemplate>
|
||||
</UserControl.Resources>
|
||||
<Grid Margin="15 0 0 0">
|
||||
<Grid.RowDefinitions>
|
||||
|
|
@ -47,23 +65,38 @@
|
|||
</StackPanel>
|
||||
<ListView ItemsSource="{Binding Settings.SearchSources}"
|
||||
SelectedItem="{Binding Settings.SelectedSearchSource}"
|
||||
x:Name="SearchSourcesListView"
|
||||
|
||||
Grid.Row="3"
|
||||
Style="{StaticResource {x:Static GridView.GridViewStyleKey}}"
|
||||
BorderBrush="DarkGray"
|
||||
BorderThickness="1">
|
||||
BorderThickness="1"
|
||||
GridViewColumnHeader.Click="SortByColumn"
|
||||
MouseDoubleClick="MouseDoubleClickItem">
|
||||
<ListView.View>
|
||||
<GridView>
|
||||
<GridViewColumn Header="{DynamicResource flowlauncher_plugin_websearch_action_keyword}">
|
||||
<GridViewColumn Header="{DynamicResource flowlauncher_plugin_websearch_title}"
|
||||
DisplayMemberBinding="{Binding Title}">
|
||||
<GridViewColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding ActionKeyword}" />
|
||||
<TextBlock Text="{Binding Title}"/>
|
||||
</DataTemplate>
|
||||
</GridViewColumn.CellTemplate>
|
||||
</GridViewColumn>
|
||||
<GridViewColumn Header="{DynamicResource flowlauncher_plugin_websearch_url}" Width="418">
|
||||
<GridViewColumn Header="{DynamicResource flowlauncher_plugin_websearch_action_keyword}"
|
||||
DisplayMemberBinding="{Binding ActionKeyword}">
|
||||
<GridViewColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding Url}" />
|
||||
<TextBlock Text="{Binding ActionKeyword}"/>
|
||||
</DataTemplate>
|
||||
</GridViewColumn.CellTemplate>
|
||||
</GridViewColumn>
|
||||
<GridViewColumn Header="{DynamicResource flowlauncher_plugin_websearch_url}"
|
||||
DisplayMemberBinding="{Binding Url}"
|
||||
Width="418">
|
||||
<GridViewColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding Url}"/>
|
||||
</DataTemplate>
|
||||
</GridViewColumn.CellTemplate>
|
||||
</GridViewColumn>
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue