From 5dd9e8d963e8e941b401980010f30c0e9c8af9c6 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Tue, 18 Mar 2025 09:11:15 +0800 Subject: [PATCH] Add plugin search delay settings panel --- .../UserSettings/PluginSettings.cs | 7 ++- .../UserSettings/Settings.cs | 12 +++++ Flow.Launcher.Plugin/PluginMetadata.cs | 2 + Flow.Launcher/Languages/en.xaml | 1 + .../Controls/InstalledPluginDisplay.xaml | 2 + .../Controls/InstalledPluginSearchDelay.xaml | 46 +++++++++++++++++++ .../InstalledPluginSearchDelay.xaml.cs | 11 +++++ .../SettingsPaneGeneralViewModel.cs | 5 +- Flow.Launcher/ViewModel/PluginViewModel.cs | 21 ++++++++- 9 files changed, 100 insertions(+), 7 deletions(-) create mode 100644 Flow.Launcher/Resources/Controls/InstalledPluginSearchDelay.xaml create mode 100644 Flow.Launcher/Resources/Controls/InstalledPluginSearchDelay.xaml.cs diff --git a/Flow.Launcher.Infrastructure/UserSettings/PluginSettings.cs b/Flow.Launcher.Infrastructure/UserSettings/PluginSettings.cs index 98f4dccda..0ebbdb318 100644 --- a/Flow.Launcher.Infrastructure/UserSettings/PluginSettings.cs +++ b/Flow.Launcher.Infrastructure/UserSettings/PluginSettings.cs @@ -51,6 +51,7 @@ namespace Flow.Launcher.Infrastructure.UserSettings } metadata.Disabled = settings.Disabled; metadata.Priority = settings.Priority; + metadata.SearchDelayTime = settings.SearchDelayTime; } else { @@ -59,9 +60,10 @@ namespace Flow.Launcher.Infrastructure.UserSettings ID = metadata.ID, Name = metadata.Name, Version = metadata.Version, - ActionKeywords = metadata.ActionKeywords, + ActionKeywords = metadata.ActionKeywords, Disabled = metadata.Disabled, - Priority = metadata.Priority + Priority = metadata.Priority, + SearchDelayTime = metadata.SearchDelayTime, }; } } @@ -74,6 +76,7 @@ namespace Flow.Launcher.Infrastructure.UserSettings public string Version { get; set; } public List ActionKeywords { get; set; } // a reference of the action keywords from plugin manager public int Priority { get; set; } + public int SearchDelayTime { get; set; } /// /// Used only to save the state of the plugin in settings diff --git a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs index df49630c5..82e4468d4 100644 --- a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs +++ b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs @@ -287,6 +287,18 @@ namespace Flow.Launcher.Infrastructure.UserSettings } public int SearchInputDelay { get; set; } = 120; + [JsonIgnore] + public List SearchInputDelayRange { get; } = new() + { + 30, 60, 90, 120, 150, 180, 210, 240, 270, 300 + }; + + [JsonIgnore] + public List PluginSearchInputDelayRange { get; } = new() + { + 0, 30, 60, 90, 120, 150 + }; + [JsonConverter(typeof(JsonStringEnumConverter))] public SearchWindowScreens SearchWindowScreen { get; set; } = SearchWindowScreens.Cursor; diff --git a/Flow.Launcher.Plugin/PluginMetadata.cs b/Flow.Launcher.Plugin/PluginMetadata.cs index b4e06913e..3cb025c77 100644 --- a/Flow.Launcher.Plugin/PluginMetadata.cs +++ b/Flow.Launcher.Plugin/PluginMetadata.cs @@ -34,6 +34,8 @@ namespace Flow.Launcher.Plugin public List ActionKeywords { get; set; } + public int SearchDelayTime { get; set; } + public string IcoPath { get; set;} public override string ToString() diff --git a/Flow.Launcher/Languages/en.xaml b/Flow.Launcher/Languages/en.xaml index 2426d90af..83f0df08d 100644 --- a/Flow.Launcher/Languages/en.xaml +++ b/Flow.Launcher/Languages/en.xaml @@ -124,6 +124,7 @@ Current action keyword New action keyword Change Action Keywords + Change Seach Delay Time Current Priority New Priority Priority diff --git a/Flow.Launcher/Resources/Controls/InstalledPluginDisplay.xaml b/Flow.Launcher/Resources/Controls/InstalledPluginDisplay.xaml index ed3c29690..e27a15784 100644 --- a/Flow.Launcher/Resources/Controls/InstalledPluginDisplay.xaml +++ b/Flow.Launcher/Resources/Controls/InstalledPluginDisplay.xaml @@ -95,6 +95,8 @@ + + + + + +  + + + + + + diff --git a/Flow.Launcher/Resources/Controls/InstalledPluginSearchDelay.xaml.cs b/Flow.Launcher/Resources/Controls/InstalledPluginSearchDelay.xaml.cs new file mode 100644 index 000000000..ad9284074 --- /dev/null +++ b/Flow.Launcher/Resources/Controls/InstalledPluginSearchDelay.xaml.cs @@ -0,0 +1,11 @@ +using System.Windows.Controls; + +namespace Flow.Launcher.Resources.Controls; + +public partial class InstalledPluginSearchDelay : UserControl +{ + public InstalledPluginSearchDelay() + { + InitializeComponent(); + } +} diff --git a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs index ced565bc2..6e97543db 100644 --- a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs +++ b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs @@ -139,10 +139,7 @@ public partial class SettingsPaneGeneralViewModel : BaseModel } } - public IEnumerable SearchInputDelayRange => new List() - { - 30, 60, 90, 120, 150, 180, 210, 240, 270, 300 - }; + public IEnumerable SearchInputDelayRange => Settings.SearchInputDelayRange; public List LastQueryModes { get; } = DropdownDataGeneric.GetValues("LastQuery"); diff --git a/Flow.Launcher/ViewModel/PluginViewModel.cs b/Flow.Launcher/ViewModel/PluginViewModel.cs index 209a81395..230a76e7a 100644 --- a/Flow.Launcher/ViewModel/PluginViewModel.cs +++ b/Flow.Launcher/ViewModel/PluginViewModel.cs @@ -8,6 +8,9 @@ using System.Windows.Controls; using CommunityToolkit.Mvvm.Input; using Flow.Launcher.Core.Resource; using Flow.Launcher.Resources.Controls; +using System.Collections.Generic; +using CommunityToolkit.Mvvm.DependencyInjection; +using Flow.Launcher.Infrastructure.UserSettings; namespace Flow.Launcher.ViewModel { @@ -81,6 +84,19 @@ namespace Flow.Launcher.ViewModel } } + public IEnumerable PluginSearchInputDelayRange { get; } = + Ioc.Default.GetRequiredService().PluginSearchInputDelayRange; + + public int PluginSearchDelayTime + { + get => PluginPair.Metadata.SearchDelayTime; + set + { + PluginPair.Metadata.SearchDelayTime = value; + PluginSettingsObject.SearchDelayTime = value; + } + } + private Control _settingControl; private bool _isExpanded; @@ -88,7 +104,10 @@ namespace Flow.Launcher.ViewModel public Control BottomPart1 => IsExpanded ? _bottomPart1 ??= new InstalledPluginDisplayKeyword() : null; private Control _bottomPart2; - public Control BottomPart2 => IsExpanded ? _bottomPart2 ??= new InstalledPluginDisplayBottomData() : null; + public Control BottomPart2 => IsExpanded ? _bottomPart2 ??= new InstalledPluginSearchDelay() : null; + + private Control _bottomPart3; + public Control BottomPart3 => IsExpanded ? _bottomPart3 ??= new InstalledPluginDisplayBottomData() : null; public bool HasSettingControl => PluginPair.Plugin is ISettingProvider && (PluginPair.Plugin is not JsonRPCPluginBase jsonRPCPluginBase || jsonRPCPluginBase.NeedCreateSettingPanel()); public Control SettingControl