From 0136c570faf3d8cdf4e7094054a1ed0cd62103c5 Mon Sep 17 00:00:00 2001 From: DB p Date: Mon, 31 Mar 2025 22:44:46 +0900 Subject: [PATCH] Add Setting Filter --- .../StringEqualityToVisibilityConverter.cs | 23 ++++- .../Controls/InstalledPluginDisplay.xaml | 34 +++++-- .../SettingsPanePluginsViewModel.cs | 69 +++++++++++++++ .../Views/SettingsPanePlugins.xaml | 88 ++++++++++--------- Flow.Launcher/ViewModel/PluginViewModel.cs | 14 ++- 5 files changed, 172 insertions(+), 56 deletions(-) diff --git a/Flow.Launcher/Converters/StringEqualityToVisibilityConverter.cs b/Flow.Launcher/Converters/StringEqualityToVisibilityConverter.cs index 4757681bc..4e4453636 100644 --- a/Flow.Launcher/Converters/StringEqualityToVisibilityConverter.cs +++ b/Flow.Launcher/Converters/StringEqualityToVisibilityConverter.cs @@ -1,6 +1,23 @@ -namespace Flow.Launcher.Converters; +using System; +using System.Globalization; +using System.Windows; +using System.Windows.Data; -public class StringEqualityToVisibilityConverter +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(); + } + } } diff --git a/Flow.Launcher/Resources/Controls/InstalledPluginDisplay.xaml b/Flow.Launcher/Resources/Controls/InstalledPluginDisplay.xaml index 74edd2dea..ca9f673d8 100644 --- a/Flow.Launcher/Resources/Controls/InstalledPluginDisplay.xaml +++ b/Flow.Launcher/Resources/Controls/InstalledPluginDisplay.xaml @@ -7,10 +7,14 @@ 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"> + + + + Visibility="{Binding DataContext.CurrentDisplayMode, + RelativeSource={RelativeSource AncestorType=ListBox}, + Converter={StaticResource StringEqualityToVisibilityConverter}, + ConverterParameter=Priority}"> + Margin="0 0 8 0" + VerticalAlignment="Center" + FontSize="13" + Foreground="{DynamicResource Color08B}" + Text="{DynamicResource priority}" /> + + Visibility="{Binding DataContext.CurrentDisplayMode, + RelativeSource={RelativeSource AncestorType=ListBox}, + Converter={StaticResource StringEqualityToVisibilityConverter}, + ConverterParameter=SearchDelay}"> + - + Visibility="{Binding DataContext.CurrentDisplayMode, + RelativeSource={RelativeSource AncestorType=ListBox}, + Converter={StaticResource StringEqualityToVisibilityConverter}, + ConverterParameter=OnOff}" /> + diff --git a/Flow.Launcher/SettingPages/ViewModels/SettingsPanePluginsViewModel.cs b/Flow.Launcher/SettingPages/ViewModels/SettingsPanePluginsViewModel.cs index 3c1aba400..5cd14ba7e 100644 --- a/Flow.Launcher/SettingPages/ViewModels/SettingsPanePluginsViewModel.cs +++ b/Flow.Launcher/SettingPages/ViewModels/SettingsPanePluginsViewModel.cs @@ -14,6 +14,75 @@ public class SettingsPanePluginsViewModel : BaseModel { private readonly Settings _settings; + private bool _isOnOffSelected = true; + public bool IsOnOffSelected + { + get => _isOnOffSelected; + set + { + if (_isOnOffSelected != value) + { + _isOnOffSelected = value; + OnPropertyChanged(nameof(IsOnOffSelected)); + UpdateDisplayMode(); + } + } + } + + private bool _isPrioritySelected; + public bool IsPrioritySelected + { + get => _isPrioritySelected; + set + { + if (_isPrioritySelected != value) + { + _isPrioritySelected = value; + OnPropertyChanged(nameof(IsPrioritySelected)); + UpdateDisplayMode(); + } + } + } + + private bool _isSearchDelaySelected; + public bool IsSearchDelaySelected + { + get => _isSearchDelaySelected; + set + { + if (_isSearchDelaySelected != value) + { + _isSearchDelaySelected = value; + OnPropertyChanged(nameof(IsSearchDelaySelected)); + UpdateDisplayMode(); + } + } + } + + 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; diff --git a/Flow.Launcher/SettingPages/Views/SettingsPanePlugins.xaml b/Flow.Launcher/SettingPages/Views/SettingsPanePlugins.xaml index 37079a46f..7580a5591 100644 --- a/Flow.Launcher/SettingPages/Views/SettingsPanePlugins.xaml +++ b/Flow.Launcher/SettingPages/Views/SettingsPanePlugins.xaml @@ -6,6 +6,7 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:ui="http://schemas.modernwpf.com/2019" + xmlns:converters="clr-namespace:Flow.Launcher.Converters" xmlns:viewModels="clr-namespace:Flow.Launcher.SettingPages.ViewModels" xmlns:cc="clr-namespace:Flow.Launcher.Resources.Controls" Title="Plugins" @@ -17,6 +18,7 @@ mc:Ignorable="d"> + @@ -31,51 +33,51 @@ Style="{StaticResource PageTitle}" Text="{DynamicResource plugins}" TextAlignment="Left" /> - - - - - + Orientation="Horizontal" + HorizontalAlignment="Right" + VerticalAlignment="Center"> + + + + + + + string.Join(Query.ActionKeywordSeparator, PluginPair.Metadata.ActionKeywords); - public int Priority => PluginPair.Metadata.Priority; + //public int Priority => PluginPair.Metadata.Priority; + private int _priority; + public int Priority + { + get => PluginPair.Metadata.Priority; + set + { + if (PluginPair.Metadata.Priority != value) + { + ChangePriority(value); + } + } + } public string SearchDelayTimeText => PluginPair.Metadata.SearchDelayTime == null ? App.API.GetTranslation("default") : App.API.GetTranslation($"SearchDelayTime{PluginPair.Metadata.SearchDelayTime}");