Flow.Launcher/Plugins/Flow.Launcher.Plugin.WebSearch/SettingsControl.xaml
Jack251970 72269db8e6 Enable TwoWay binding for MaxSuggestions NumberBox
Changed NumberBox binding for Settings.MaxSuggestions from OneWay to TwoWay, allowing user input in the UI to update the underlying setting. This ensures changes made by users are saved back to the settings model.
2026-02-24 00:07:36 +08:00

190 lines
No EOL
9.2 KiB
XML

<UserControl
x:Class="Flow.Launcher.Plugin.WebSearch.SettingsControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:ikw="http://schemas.inkore.net/lib/ui/wpf"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ui="http://schemas.inkore.net/lib/ui/wpf/modern"
xmlns:vm="clr-namespace:Flow.Launcher.Plugin.WebSearch"
d:DataContext="{d:DesignInstance vm:SettingsViewModel}"
d:DesignHeight="300"
d:DesignWidth="500"
mc:Ignorable="d">
<UserControl.Resources>
<DataTemplate x:Key="HeaderTemplateArrowUp">
<DockPanel>
<TextBlock HorizontalAlignment="Center" Text="{Binding}" />
<Path
x:Name="arrow"
Data="M 5,10 L 15,10 L 10,5 L 5,10"
Fill="gray"
StrokeThickness="1" />
</DockPanel>
</DataTemplate>
<DataTemplate x:Key="HeaderTemplateArrowDown">
<DockPanel>
<TextBlock HorizontalAlignment="Center" Text="{Binding}" />
<Path
x:Name="arrow"
Data="M 5,5 L 10,10 L 15,5 L 5,5"
Fill="gray"
StrokeThickness="1" />
</DockPanel>
</DataTemplate>
</UserControl.Resources>
<Grid Margin="{StaticResource SettingPanelMargin}">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto" />
<RowDefinition />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<ListView
x:Name="SearchSourcesListView"
Grid.Row="0"
Margin="{StaticResource SettingPanelItemTopBottomMargin}"
AllowDrop="True"
BorderBrush="DarkGray"
BorderThickness="1"
Drop="ListView_Drop"
GridViewColumnHeader.Click="SortByColumn"
ItemsSource="{Binding Settings.SearchSources}"
MouseDoubleClick="MouseDoubleClickItem"
PreviewMouseLeftButtonDown="ListView_PreviewMouseLeftButtonDown"
PreviewMouseMove="ListView_PreviewMouseMove"
SelectedItem="{Binding Settings.SelectedSearchSource}"
SizeChanged="ListView_SizeChanged"
Style="{StaticResource {x:Static GridView.GridViewStyleKey}}">
<ListView.View>
<GridView>
<!-- Margin="0 4" is a workaround to set this TextBlock to vertially center -->
<GridViewColumn Width="45">
<GridViewColumn.CellTemplate>
<DataTemplate>
<Image
Width="20"
Height="20"
Margin="6 4 0 4"
Source="{Binding Path=IconPath}" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<!-- Margin="0 6" is a workaround to set this TextBlock to vertially center -->
<GridViewColumn Width="135" Header="{DynamicResource flowlauncher_plugin_websearch_action_keyword}">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Margin="0 6" Text="{Binding ActionKeyword}" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Width="145" Header="{DynamicResource flowlauncher_plugin_websearch_title}">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Margin="0 6" Text="{Binding Title}" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Width="112" Header="{DynamicResource flowlauncher_plugin_websearch_enable}">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Margin="0 6">
<TextBlock.Style>
<Style TargetType="TextBlock">
<Setter Property="Text" Value="{DynamicResource flowlauncher_plugin_websearch_false}" />
<Style.Triggers>
<DataTrigger Binding="{Binding Status, UpdateSourceTrigger=PropertyChanged}" Value="True">
<Setter Property="Text" Value="{DynamicResource flowlauncher_plugin_websearch_true}" />
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<!-- CheckBox is vertially center by default -->
<GridViewColumn Width="123" Header="{DynamicResource flowlauncher_plugin_websearch_private_mode_label}">
<GridViewColumn.CellTemplate>
<DataTemplate>
<CheckBox
HorizontalAlignment="Center"
VerticalAlignment="Center"
IsChecked="{Binding IsPrivateMode}"
IsEnabled="False" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
<StackPanel
Grid.Row="1"
Margin="{StaticResource SettingPanelItemTopBottomMargin}"
HorizontalAlignment="Right"
Orientation="Horizontal">
<Button
Width="100"
Margin="{StaticResource SettingPanelItemLeftMargin}"
Click="OnDeleteSearchSearchClick"
Content="{DynamicResource flowlauncher_plugin_websearch_delete}" />
<Button
Width="100"
Margin="{StaticResource SettingPanelItemLeftMargin}"
Click="OnEditSearchSourceClick"
Content="{DynamicResource flowlauncher_plugin_websearch_edit}" />
<Button
Width="100"
Margin="{StaticResource SettingPanelItemLeftMargin}"
Click="OnAddSearchSearchClick"
Content="{DynamicResource flowlauncher_plugin_websearch_add}" />
</StackPanel>
<Separator Grid.Row="2" Style="{StaticResource SettingPanelSeparatorStyle}" />
<WrapPanel Grid.Row="3" HorizontalAlignment="Stretch">
<StackPanel Orientation="Horizontal">
<TextBlock
Margin="{StaticResource SettingPanelItemRightTopBottomMargin}"
VerticalAlignment="Center"
Text="{DynamicResource flowlauncher_plugin_websearch_max_suggestions}" />
<ui:NumberBox
Width="120"
MinWidth="120"
Margin="{StaticResource SettingPanelItemRightTopBottomMargin}"
Maximum="1000"
Minimum="1"
SmallChange="10"
SpinButtonPlacementMode="Compact"
ValidationMode="InvalidInputOverwritten"
ValueChanged="NumberBox_ValueChanged"
Value="{Binding Settings.MaxSuggestions, Mode=TwoWay}" />
</StackPanel>
<CheckBox
Name="EnableSuggestion"
Margin="{StaticResource SettingPanelItemRightTopBottomMargin}"
VerticalAlignment="Center"
Content="{DynamicResource flowlauncher_plugin_websearch_enable_suggestion}"
IsChecked="{Binding Settings.EnableSuggestion}" />
<StackPanel Orientation="Horizontal">
<TextBlock
Margin="{StaticResource SettingPanelItemRightTopBottomMargin}"
VerticalAlignment="Center"
Text="{DynamicResource flowlauncher_plugin_websearch_enable_suggestion_provider}" />
<ComboBox
Height="30"
Margin="{StaticResource SettingPanelItemTopBottomMargin}"
VerticalAlignment="Center"
IsEnabled="{Binding Settings.EnableSuggestion}"
ItemsSource="{Binding Settings.Suggestions}"
SelectedItem="{Binding Settings.SelectedSuggestion}" />
</StackPanel>
</WrapPanel>
</Grid>
</UserControl>