mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Use binding instead of local functions
This commit is contained in:
parent
bf63ddad25
commit
44f136cca5
7 changed files with 79 additions and 183 deletions
|
|
@ -1,23 +0,0 @@
|
|||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace Flow.Launcher.Converters
|
||||
{
|
||||
public class StringEqualityToVisibilityConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value == null || parameter == null)
|
||||
return Visibility.Collapsed;
|
||||
|
||||
return value.ToString() == parameter.ToString() ? Visibility.Visible : Visibility.Collapsed;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -135,9 +135,9 @@
|
|||
<system:String x:Key="pluginSearchDelayTime">Plugin seach delay time</system:String>
|
||||
<system:String x:Key="pluginSearchDelayTimeTooltip">Change Plugin Seach Delay Time</system:String>
|
||||
<system:String x:Key="FilterComboboxLabel">Advanced Settings:</system:String>
|
||||
<system:String x:Key="EnabledCombobox">Enabled</system:String>
|
||||
<system:String x:Key="PriorityCombobox">Priority</system:String>
|
||||
<system:String x:Key="SearchDelayCombobox">Search Delay</system:String>
|
||||
<system:String x:Key="DisplayModeOnOff">Enabled</system:String>
|
||||
<system:String x:Key="DisplayModePriority">Priority</system:String>
|
||||
<system:String x:Key="DisplayModeSearchDelay">Search Delay</system:String>
|
||||
<system:String x:Key="currentPriority">Current Priority</system:String>
|
||||
<system:String x:Key="newPriority">New Priority</system:String>
|
||||
<system:String x:Key="priority">Priority</system:String>
|
||||
|
|
|
|||
|
|
@ -3,17 +3,17 @@
|
|||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:cc="clr-namespace:Flow.Launcher.Resources.Controls"
|
||||
xmlns:converters="clr-namespace:Flow.Launcher.Converters"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:ui="http://schemas.modernwpf.com/2019"
|
||||
xmlns:viewModel="clr-namespace:Flow.Launcher.ViewModel"
|
||||
xmlns:converters="clr-namespace:Flow.Launcher.Converters"
|
||||
d:DataContext="{d:DesignInstance viewModel:PluginViewModel}"
|
||||
d:DesignHeight="300"
|
||||
d:DesignWidth="300"
|
||||
mc:Ignorable="d">
|
||||
<UserControl.Resources>
|
||||
<converters:StringEqualityToVisibilityConverter x:Key="StringEqualityToVisibilityConverter" />
|
||||
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
|
||||
</UserControl.Resources>
|
||||
<Expander
|
||||
Padding="0"
|
||||
|
|
@ -48,99 +48,55 @@
|
|||
Text="{Binding PluginPair.Metadata.Description}"
|
||||
TextWrapping="WrapWithOverflow" />
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel
|
||||
Grid.Column="2"
|
||||
HorizontalAlignment="Right"
|
||||
Orientation="Horizontal">
|
||||
<!--<TextBlock
|
||||
Margin="0 0 8 0"
|
||||
VerticalAlignment="Center"
|
||||
FontSize="12"
|
||||
Foreground="{DynamicResource Color08B}"
|
||||
Text="{DynamicResource priority}" />
|
||||
<Button
|
||||
x:Name="PriorityButton"
|
||||
Margin="0 0 22 0"
|
||||
VerticalAlignment="Center"
|
||||
Command="{Binding EditPluginPriorityCommand}"
|
||||
Content="{Binding Priority}"
|
||||
Cursor="Hand"
|
||||
ToolTip="{DynamicResource priorityToolTip}">
|
||||
-->
|
||||
<!--#region Priority Button Style-->
|
||||
<!--
|
||||
<Button.Resources>
|
||||
<Style TargetType="Border">
|
||||
<Setter Property="CornerRadius" Value="2" />
|
||||
</Style>
|
||||
</Button.Resources>
|
||||
<Button.Style>
|
||||
<Style BasedOn="{StaticResource DefaultButtonStyle}" TargetType="Button">
|
||||
<Setter Property="Padding" Value="12 8" />
|
||||
<Setter Property="BorderThickness" Value="0" />
|
||||
<Setter Property="FontWeight" Value="DemiBold" />
|
||||
<Setter Property="Foreground" Value="{DynamicResource Color05B}" />
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding ElementName=PriorityButton, UpdateSourceTrigger=PropertyChanged, Path=Content}" Value="0">
|
||||
<Setter Property="Foreground" Value="{DynamicResource Color08B}" />
|
||||
<Setter Property="FontWeight" Value="Normal" />
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</Button.Style>
|
||||
-->
|
||||
<!--#endregion-->
|
||||
<!--
|
||||
</Button>-->
|
||||
<StackPanel VerticalAlignment="Center"
|
||||
<StackPanel
|
||||
x:Name="PriorityControl"
|
||||
VerticalAlignment="Center"
|
||||
Orientation="Horizontal"
|
||||
Visibility="{Binding DataContext.CurrentDisplayMode,
|
||||
RelativeSource={RelativeSource AncestorType=ListBox},
|
||||
Converter={StaticResource StringEqualityToVisibilityConverter},
|
||||
ConverterParameter=Priority}">
|
||||
Visibility="{Binding DataContext.IsPrioritySelected, RelativeSource={RelativeSource AncestorType=ListBox}, Converter={StaticResource BooleanToVisibilityConverter}}">
|
||||
<TextBlock
|
||||
Margin="0 0 8 0"
|
||||
VerticalAlignment="Center"
|
||||
FontSize="13" ToolTip="{DynamicResource priorityToolTip}"
|
||||
Foreground="{DynamicResource Color08B}"
|
||||
Text="{DynamicResource priority}" />
|
||||
Margin="0 0 8 0"
|
||||
VerticalAlignment="Center"
|
||||
FontSize="13"
|
||||
Foreground="{DynamicResource Color08B}"
|
||||
Text="{DynamicResource priority}"
|
||||
ToolTip="{DynamicResource priorityToolTip}" />
|
||||
<ui:NumberBox
|
||||
Margin="0 0 8 0"
|
||||
Maximum="999" ToolTip="{DynamicResource priorityToolTip}"
|
||||
Maximum="999"
|
||||
Minimum="-999"
|
||||
SpinButtonPlacementMode="Inline" />
|
||||
SpinButtonPlacementMode="Inline"
|
||||
ToolTip="{DynamicResource priorityToolTip}" />
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel
|
||||
x:Name="SearchDelayControl"
|
||||
Orientation="Horizontal"
|
||||
VerticalAlignment="Center"
|
||||
Visibility="{Binding DataContext.CurrentDisplayMode,
|
||||
RelativeSource={RelativeSource AncestorType=ListBox},
|
||||
Converter={StaticResource StringEqualityToVisibilityConverter},
|
||||
ConverterParameter=SearchDelay}">
|
||||
Orientation="Horizontal"
|
||||
Visibility="{Binding DataContext.IsSearchDelaySelected, RelativeSource={RelativeSource AncestorType=ListBox}, Converter={StaticResource BooleanToVisibilityConverter}}">
|
||||
<TextBlock
|
||||
Margin="0 0 8 0"
|
||||
VerticalAlignment="Center"
|
||||
FontSize="13" ToolTip="{DynamicResource searchDelayToolTip}"
|
||||
FontSize="13"
|
||||
Foreground="{DynamicResource Color08B}"
|
||||
Text="{DynamicResource searchDelay}" />
|
||||
<cc:InstalledPluginSearchDelayCombobox
|
||||
Margin="0 0 8 0" />
|
||||
Text="{DynamicResource searchDelay}"
|
||||
ToolTip="{DynamicResource searchDelayToolTip}" />
|
||||
<cc:InstalledPluginSearchDelayCombobox Margin="0 0 8 0" />
|
||||
</StackPanel>
|
||||
|
||||
<!-- Put OnOffControl after PriorityControl & SearchDelayControl so that it can display correctly -->
|
||||
<ui:ToggleSwitch
|
||||
x:Name="OnOffControl"
|
||||
Margin="0 0 8 0"
|
||||
IsOn="{Binding PluginState}"
|
||||
OffContent="{DynamicResource disable}"
|
||||
OnContent="{DynamicResource enable}"
|
||||
Visibility="{Binding DataContext.CurrentDisplayMode,
|
||||
RelativeSource={RelativeSource AncestorType=ListBox},
|
||||
Converter={StaticResource StringEqualityToVisibilityConverter},
|
||||
ConverterParameter=OnOff}" />
|
||||
</StackPanel>
|
||||
Visibility="{Binding DataContext.IsOnOffSelected, RelativeSource={RelativeSource AncestorType=ListBox}, Converter={StaticResource BooleanToVisibilityConverter}}" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Border>
|
||||
</Expander.Header>
|
||||
|
|
@ -148,8 +104,6 @@
|
|||
<StackPanel>
|
||||
<ContentControl Content="{Binding BottomPart1}" />
|
||||
|
||||
<!-- <ContentControl Content="{Binding BottomPart2}" /> -->
|
||||
|
||||
<Border
|
||||
Background="{DynamicResource Color00B}"
|
||||
BorderBrush="{DynamicResource Color03B}"
|
||||
|
|
@ -170,7 +124,7 @@
|
|||
Content="{Binding SettingControl}" />
|
||||
</Border>
|
||||
|
||||
<ContentControl Content="{Binding BottomPart3}" />
|
||||
<ContentControl Content="{Binding BottomPart2}" />
|
||||
</StackPanel>
|
||||
</Expander>
|
||||
</UserControl>
|
||||
|
|
|
|||
|
|
@ -19,8 +19,13 @@ public partial class SettingsPanePluginsViewModel : BaseModel
|
|||
{
|
||||
private readonly Settings _settings;
|
||||
|
||||
private string _selectedDisplayMode = "OnOff";
|
||||
public string SelectedDisplayMode
|
||||
public class DisplayModeData : DropdownDataGeneric<DisplayMode> { }
|
||||
|
||||
public List<DisplayModeData> DisplayModes { get; } =
|
||||
DropdownDataGeneric<DisplayMode>.GetValues<DisplayModeData>("DisplayMode");
|
||||
|
||||
private DisplayMode _selectedDisplayMode = DisplayMode.OnOff;
|
||||
public DisplayMode SelectedDisplayMode
|
||||
{
|
||||
get => _selectedDisplayMode;
|
||||
set
|
||||
|
|
@ -28,34 +33,12 @@ public partial class SettingsPanePluginsViewModel : BaseModel
|
|||
if (_selectedDisplayMode != value)
|
||||
{
|
||||
_selectedDisplayMode = value;
|
||||
OnPropertyChanged(nameof(SelectedDisplayMode));
|
||||
OnPropertyChanged();
|
||||
UpdateDisplayModeFromSelection();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateDisplayModeFromSelection()
|
||||
{
|
||||
switch (SelectedDisplayMode)
|
||||
{
|
||||
case "OnOff":
|
||||
IsOnOffSelected = true;
|
||||
IsPrioritySelected = false;
|
||||
IsSearchDelaySelected = false;
|
||||
break;
|
||||
case "Priority":
|
||||
IsOnOffSelected = false;
|
||||
IsPrioritySelected = true;
|
||||
IsSearchDelaySelected = false;
|
||||
break;
|
||||
case "SearchDelay":
|
||||
IsOnOffSelected = false;
|
||||
IsPrioritySelected = false;
|
||||
IsSearchDelaySelected = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private bool _isOnOffSelected = true;
|
||||
public bool IsOnOffSelected
|
||||
{
|
||||
|
|
@ -65,8 +48,7 @@ public partial class SettingsPanePluginsViewModel : BaseModel
|
|||
if (_isOnOffSelected != value)
|
||||
{
|
||||
_isOnOffSelected = value;
|
||||
OnPropertyChanged(nameof(IsOnOffSelected));
|
||||
UpdateDisplayMode();
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -80,8 +62,7 @@ public partial class SettingsPanePluginsViewModel : BaseModel
|
|||
if (_isPrioritySelected != value)
|
||||
{
|
||||
_isPrioritySelected = value;
|
||||
OnPropertyChanged(nameof(IsPrioritySelected));
|
||||
UpdateDisplayMode();
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -95,38 +76,15 @@ public partial class SettingsPanePluginsViewModel : BaseModel
|
|||
if (_isSearchDelaySelected != value)
|
||||
{
|
||||
_isSearchDelaySelected = value;
|
||||
OnPropertyChanged(nameof(IsSearchDelaySelected));
|
||||
UpdateDisplayMode();
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private string _currentDisplayMode = "OnOff";
|
||||
public string CurrentDisplayMode
|
||||
{
|
||||
get => _currentDisplayMode;
|
||||
set
|
||||
{
|
||||
if (_currentDisplayMode != value)
|
||||
{
|
||||
_currentDisplayMode = value;
|
||||
OnPropertyChanged(nameof(CurrentDisplayMode));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateDisplayMode()
|
||||
{
|
||||
if (IsOnOffSelected)
|
||||
CurrentDisplayMode = "OnOff";
|
||||
else if (IsPrioritySelected)
|
||||
CurrentDisplayMode = "Priority";
|
||||
else if (IsSearchDelaySelected)
|
||||
CurrentDisplayMode = "SearchDelay";
|
||||
}
|
||||
public SettingsPanePluginsViewModel(Settings settings)
|
||||
{
|
||||
_settings = settings;
|
||||
UpdateEnumDropdownLocalizations();
|
||||
}
|
||||
|
||||
public string FilterText { get; set; } = string.Empty;
|
||||
|
|
@ -196,4 +154,38 @@ public partial class SettingsPanePluginsViewModel : BaseModel
|
|||
|
||||
await helpDialog.ShowAsync();
|
||||
}
|
||||
|
||||
private void UpdateEnumDropdownLocalizations()
|
||||
{
|
||||
DropdownDataGeneric<DisplayMode>.UpdateLabels(DisplayModes);
|
||||
}
|
||||
|
||||
private void UpdateDisplayModeFromSelection()
|
||||
{
|
||||
switch (SelectedDisplayMode)
|
||||
{
|
||||
case DisplayMode.Priority:
|
||||
IsOnOffSelected = false;
|
||||
IsPrioritySelected = true;
|
||||
IsSearchDelaySelected = false;
|
||||
break;
|
||||
case DisplayMode.SearchDelay:
|
||||
IsOnOffSelected = false;
|
||||
IsPrioritySelected = false;
|
||||
IsSearchDelaySelected = true;
|
||||
break;
|
||||
default:
|
||||
IsOnOffSelected = true;
|
||||
IsPrioritySelected = false;
|
||||
IsSearchDelaySelected = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum DisplayMode
|
||||
{
|
||||
OnOff,
|
||||
Priority,
|
||||
SearchDelay
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:cc="clr-namespace:Flow.Launcher.Resources.Controls"
|
||||
xmlns:converters="clr-namespace:Flow.Launcher.Converters"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:sys="clr-namespace:System;assembly=mscorlib"
|
||||
|
|
@ -16,10 +15,6 @@
|
|||
FocusManager.FocusedElement="{Binding ElementName=PluginFilterTextbox}"
|
||||
KeyDown="SettingsPanePlugins_OnKeyDown"
|
||||
mc:Ignorable="d">
|
||||
<ui:Page.Resources>
|
||||
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
|
||||
<converters:StringEqualityToVisibilityConverter x:Key="StringEqualityToVisibilityConverter" />
|
||||
</ui:Page.Resources>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="73" />
|
||||
|
|
@ -53,19 +48,10 @@
|
|||
Margin="0 0 4 0"
|
||||
HorizontalContentAlignment="Left"
|
||||
Background="{DynamicResource Color00B}"
|
||||
DisplayMemberPath="Display"
|
||||
ItemsSource="{Binding DisplayModes}"
|
||||
SelectedValue="{Binding SelectedDisplayMode, Mode=TwoWay}"
|
||||
SelectedValuePath="Tag"
|
||||
SelectionChanged="DisplayModeComboBox_SelectionChanged">
|
||||
<ComboBoxItem Tag="OnOff">
|
||||
<TextBlock Text="{DynamicResource EnabledCombobox}" />
|
||||
</ComboBoxItem>
|
||||
<ComboBoxItem Tag="Priority">
|
||||
<TextBlock Text="{DynamicResource PriorityCombobox}" />
|
||||
</ComboBoxItem>
|
||||
<ComboBoxItem Tag="SearchDelay">
|
||||
<TextBlock Text="{DynamicResource SearchDelayCombobox}" />
|
||||
</ComboBoxItem>
|
||||
</ComboBox>
|
||||
SelectedValuePath="Value" />
|
||||
<Button
|
||||
Width="34"
|
||||
Height="34"
|
||||
|
|
|
|||
|
|
@ -1,10 +1,8 @@
|
|||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Navigation;
|
||||
using CommunityToolkit.Mvvm.DependencyInjection;
|
||||
using Flow.Launcher.SettingPages.ViewModels;
|
||||
using Flow.Launcher.Infrastructure.UserSettings;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace Flow.Launcher.SettingPages.Views;
|
||||
|
||||
|
|
@ -23,14 +21,6 @@ public partial class SettingsPanePlugins
|
|||
}
|
||||
base.OnNavigatedTo(e);
|
||||
}
|
||||
|
||||
private void DisplayModeComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
if (DataContext is SettingsPanePluginsViewModel viewModel)
|
||||
{
|
||||
viewModel.UpdateDisplayModeFromSelection();
|
||||
}
|
||||
}
|
||||
|
||||
private void SettingsPanePlugins_OnKeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -112,10 +112,7 @@ namespace Flow.Launcher.ViewModel
|
|||
public Control BottomPart1 => IsExpanded ? _bottomPart1 ??= new InstalledPluginDisplayKeyword() : null;
|
||||
|
||||
private Control _bottomPart2;
|
||||
public Control BottomPart2 => IsExpanded ? _bottomPart2 ??= new InstalledPluginSearchDelay() : null;
|
||||
|
||||
private Control _bottomPart3;
|
||||
public Control BottomPart3 => IsExpanded ? _bottomPart3 ??= new InstalledPluginDisplayBottomData() : null;
|
||||
public Control BottomPart2 => IsExpanded ? _bottomPart2 ??= new InstalledPluginDisplayBottomData() : null;
|
||||
|
||||
public bool HasSettingControl => PluginPair.Plugin is ISettingProvider &&
|
||||
(PluginPair.Plugin is not JsonRPCPluginBase jsonRPCPluginBase || jsonRPCPluginBase.NeedCreateSettingPanel());
|
||||
|
|
|
|||
Loading…
Reference in a new issue