mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Support changing plugin search delay
This commit is contained in:
parent
a3330412fd
commit
c925a7926a
6 changed files with 213 additions and 8 deletions
|
|
@ -365,6 +365,12 @@
|
|||
<system:String x:Key="completedSuccessfully">Completed successfully</system:String>
|
||||
<system:String x:Key="actionkeyword_tips">Enter the action keywords you like to use to start the plugin and use whitespace to divide them. Use * if you don't want to specify any, and the plugin will be triggered without any action keywords.</system:String>
|
||||
|
||||
<!-- Search Delay Settings Dialog -->
|
||||
<system:String x:Key="searchDelaySpeedTitle">Search Delay Speed Setting</system:String>
|
||||
<system:String x:Key="searchDelaySpeed_tips">Select the search delay speed you like to use for the plugin. Select Default if you don't want to specify any, and the plugin will use default search delay speed.</system:String>
|
||||
<system:String x:Key="currentSearchDelaySpeed">Current search delay speed</system:String>
|
||||
<system:String x:Key="newSearchDelaySpeed">New search delay speed</system:String>
|
||||
|
||||
<!-- Custom Query Hotkey Dialog -->
|
||||
<system:String x:Key="customeQueryHotkeyTitle">Custom Query Hotkey</system:String>
|
||||
<system:String x:Key="customeQueryHotkeyTips">Press a custom hotkey to open Flow Launcher and input the specified query automatically.</system:String>
|
||||
|
|
|
|||
138
Flow.Launcher/SearchDelaySpeedWindow.xaml
Normal file
138
Flow.Launcher/SearchDelaySpeedWindow.xaml
Normal file
|
|
@ -0,0 +1,138 @@
|
|||
<Window
|
||||
x:Class="Flow.Launcher.SearchDelaySpeedWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
Title="{DynamicResource searchDelaySpeedTitle}"
|
||||
Width="450"
|
||||
Background="{DynamicResource PopuBGColor}"
|
||||
Foreground="{DynamicResource PopupTextColor}"
|
||||
Icon="Images\app.png"
|
||||
Loaded="SearchDelaySpeed_OnLoaded"
|
||||
ResizeMode="NoResize"
|
||||
SizeToContent="Height"
|
||||
WindowStartupLocation="CenterScreen">
|
||||
<WindowChrome.WindowChrome>
|
||||
<WindowChrome CaptionHeight="32" ResizeBorderThickness="{x:Static SystemParameters.WindowResizeBorderThickness}" />
|
||||
</WindowChrome.WindowChrome>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition />
|
||||
<RowDefinition Height="80" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid>
|
||||
<StackPanel Grid.Row="0">
|
||||
<StackPanel>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Button
|
||||
Grid.Column="4"
|
||||
Click="BtnCancel_OnClick"
|
||||
Style="{StaticResource TitleBarCloseButtonStyle}">
|
||||
<Path
|
||||
Width="46"
|
||||
Height="32"
|
||||
Data="M 18,11 27,20 M 18,20 27,11"
|
||||
Stroke="{Binding Path=Foreground, RelativeSource={RelativeSource AncestorType={x:Type Button}}}"
|
||||
StrokeThickness="1">
|
||||
<Path.Style>
|
||||
<Style TargetType="Path">
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding Path=IsActive, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}" Value="False">
|
||||
<Setter Property="Opacity" Value="0.5" />
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</Path.Style>
|
||||
</Path>
|
||||
</Button>
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
<StackPanel Margin="26 12 26 0">
|
||||
<StackPanel Grid.Row="0" Margin="0 0 0 12">
|
||||
<TextBlock
|
||||
Grid.Column="0"
|
||||
Margin="0 0 0 0"
|
||||
FontSize="20"
|
||||
FontWeight="SemiBold"
|
||||
Text="{DynamicResource searchDelaySpeedTitle}"
|
||||
TextAlignment="Left" />
|
||||
</StackPanel>
|
||||
<StackPanel>
|
||||
<TextBlock
|
||||
FontSize="14"
|
||||
Text="{DynamicResource searchDelaySpeed_tips}"
|
||||
TextAlignment="Left"
|
||||
TextWrapping="WrapWithOverflow" />
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Margin="0 18 0 0" Orientation="Horizontal">
|
||||
<TextBlock
|
||||
Grid.Row="0"
|
||||
Grid.Column="1"
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Center"
|
||||
FontSize="14"
|
||||
Text="{DynamicResource currentSearchDelaySpeed}" />
|
||||
<TextBlock
|
||||
x:Name="tbOldSearchDelaySpeed"
|
||||
Grid.Row="0"
|
||||
Grid.Column="1"
|
||||
Margin="14 10 10 10"
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Center"
|
||||
FontSize="14"
|
||||
FontWeight="SemiBold"
|
||||
Foreground="{DynamicResource Color05B}" />
|
||||
</StackPanel>
|
||||
<StackPanel Margin="0 0 0 10" Orientation="Horizontal">
|
||||
<TextBlock
|
||||
Grid.Row="1"
|
||||
Grid.Column="1"
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Center"
|
||||
FontSize="14"
|
||||
Text="{DynamicResource newSearchDelaySpeed}" />
|
||||
<ComboBox
|
||||
x:Name="tbDelay"
|
||||
MaxWidth="200"
|
||||
Margin="10 10 15 10"
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Center"
|
||||
DisplayMemberPath="Display"
|
||||
SelectedValuePath="Value" />
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
<Border
|
||||
Grid.Row="1"
|
||||
Background="{DynamicResource PopupButtonAreaBGColor}"
|
||||
BorderBrush="{DynamicResource PopupButtonAreaBorderColor}"
|
||||
BorderThickness="0 1 0 0">
|
||||
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal">
|
||||
<Button
|
||||
x:Name="btnCancel"
|
||||
Width="145"
|
||||
Height="30"
|
||||
Margin="10 0 5 0"
|
||||
Click="BtnCancel_OnClick"
|
||||
Content="{DynamicResource cancel}" />
|
||||
<Button
|
||||
x:Name="btnDone"
|
||||
Width="145"
|
||||
Height="30"
|
||||
Margin="5 0 10 0"
|
||||
Click="btnDone_OnClick"
|
||||
Style="{StaticResource AccentButtonStyle}">
|
||||
<TextBlock x:Name="lblAdd" Text="{DynamicResource done}" />
|
||||
</Button>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</Grid>
|
||||
</Window>
|
||||
55
Flow.Launcher/SearchDelaySpeedWindow.xaml.cs
Normal file
55
Flow.Launcher/SearchDelaySpeedWindow.xaml.cs
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
using System.Linq;
|
||||
using System.Windows;
|
||||
using Flow.Launcher.Plugin;
|
||||
using Flow.Launcher.SettingPages.ViewModels;
|
||||
using Flow.Launcher.ViewModel;
|
||||
using static Flow.Launcher.SettingPages.ViewModels.SettingsPaneGeneralViewModel;
|
||||
|
||||
namespace Flow.Launcher;
|
||||
|
||||
public partial class SearchDelaySpeedWindow : Window
|
||||
{
|
||||
private readonly PluginViewModel _pluginViewModel;
|
||||
|
||||
public SearchDelaySpeedWindow(PluginViewModel pluginViewModel)
|
||||
{
|
||||
InitializeComponent();
|
||||
_pluginViewModel = pluginViewModel;
|
||||
}
|
||||
|
||||
private void SearchDelaySpeed_OnLoaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
tbOldSearchDelaySpeed.Text = _pluginViewModel.SearchDelaySpeedText;
|
||||
var searchDelaySpeeds = DropdownDataGeneric<SearchDelaySpeeds>.GetValues<SearchDelaySpeedData>("SearchDelaySpeed");
|
||||
SearchDelaySpeedData selected = null;
|
||||
// Because default value is SearchDelaySpeeds.Slow, we need to get selected value before adding default value
|
||||
if (_pluginViewModel.PluginSearchDelay != null)
|
||||
{
|
||||
selected = searchDelaySpeeds.FirstOrDefault(x => x.Value == _pluginViewModel.PluginSearchDelay);
|
||||
}
|
||||
// Add default value to the beginning of the list
|
||||
// This value should be null
|
||||
searchDelaySpeeds.Insert(0, new SearchDelaySpeedData { Display = App.API.GetTranslation(PluginViewModel.DefaultLocalizationKey), LocalizationKey = PluginViewModel.DefaultLocalizationKey });
|
||||
selected ??= searchDelaySpeeds.FirstOrDefault();
|
||||
tbDelay.ItemsSource = searchDelaySpeeds;
|
||||
tbDelay.SelectedItem = selected;
|
||||
tbDelay.Focus();
|
||||
}
|
||||
|
||||
private void BtnCancel_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
private void btnDone_OnClick(object sender, RoutedEventArgs _)
|
||||
{
|
||||
// Update search delay speed
|
||||
var selected = tbDelay.SelectedItem as SearchDelaySpeedData;
|
||||
SearchDelaySpeeds? changedValue = selected?.LocalizationKey != PluginViewModel.DefaultLocalizationKey ? selected.Value : null;
|
||||
_pluginViewModel.PluginSearchDelay = changedValue;
|
||||
|
||||
// Update search delay speed text and close window
|
||||
_pluginViewModel.OnSearchDelaySpeedChanged();
|
||||
Close();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Flow.Launcher.Core.Resource;
|
||||
using Flow.Launcher.Plugin;
|
||||
|
||||
namespace Flow.Launcher.SettingPages.ViewModels;
|
||||
|
|
@ -9,7 +8,7 @@ public class DropdownDataGeneric<TValue> : BaseModel where TValue : Enum
|
|||
{
|
||||
public string Display { get; set; }
|
||||
public TValue Value { get; private init; }
|
||||
private string LocalizationKey { get; init; }
|
||||
public string LocalizationKey { get; set; }
|
||||
|
||||
public static List<TR> GetValues<TR>(string keyPrefix) where TR : DropdownDataGeneric<TValue>, new()
|
||||
{
|
||||
|
|
@ -19,7 +18,7 @@ public class DropdownDataGeneric<TValue> : BaseModel where TValue : Enum
|
|||
foreach (var value in enumValues)
|
||||
{
|
||||
var key = keyPrefix + value;
|
||||
var display = InternationalizationManager.Instance.GetTranslation(key);
|
||||
var display = App.API.GetTranslation(key);
|
||||
data.Add(new TR { Display = display, Value = value, LocalizationKey = key });
|
||||
}
|
||||
|
||||
|
|
@ -30,7 +29,7 @@ public class DropdownDataGeneric<TValue> : BaseModel where TValue : Enum
|
|||
{
|
||||
foreach (var item in options)
|
||||
{
|
||||
item.Display = InternationalizationManager.Instance.GetTranslation(item.LocalizationKey);
|
||||
item.Display = App.API.GetTranslation(item.LocalizationKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -150,7 +150,7 @@ public partial class SettingsPaneGeneralViewModel : BaseModel
|
|||
public SearchDelaySpeedData SearchDelaySpeed
|
||||
{
|
||||
get => SearchDelaySpeeds.FirstOrDefault(x => x.Value == Settings.SearchDelaySpeed) ??
|
||||
SearchDelaySpeeds.FirstOrDefault(x => x.Value == Flow.Launcher.Plugin.SearchDelaySpeeds.Medium) ??
|
||||
SearchDelaySpeeds.FirstOrDefault(x => x.Value == Plugin.SearchDelaySpeeds.Medium) ??
|
||||
SearchDelaySpeeds.FirstOrDefault();
|
||||
set
|
||||
{
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@ namespace Flow.Launcher.ViewModel
|
|||
{
|
||||
public partial class PluginViewModel : BaseModel
|
||||
{
|
||||
public const string DefaultLocalizationKey = "default";
|
||||
|
||||
private readonly PluginPair _pluginPair;
|
||||
public PluginPair PluginPair
|
||||
{
|
||||
|
|
@ -127,7 +129,7 @@ namespace Flow.Launcher.ViewModel
|
|||
PluginPair.Metadata.AvgQueryTime + "ms";
|
||||
public string ActionKeywordsText => string.Join(Query.ActionKeywordSeparator, PluginPair.Metadata.ActionKeywords);
|
||||
public int Priority => PluginPair.Metadata.Priority;
|
||||
public string SearchDelaySpeedText => PluginPair.Metadata.SearchDelaySpeed == null ? App.API.GetTranslation("default") : App.API.GetTranslation($"SearchDelaySpeed{PluginPair.Metadata.SearchDelaySpeed}");
|
||||
public string SearchDelaySpeedText => PluginPair.Metadata.SearchDelaySpeed == null ? App.API.GetTranslation(DefaultLocalizationKey) : App.API.GetTranslation($"SearchDelaySpeed{PluginPair.Metadata.SearchDelaySpeed}");
|
||||
public Infrastructure.UserSettings.Plugin PluginSettingsObject{ get; init; }
|
||||
|
||||
public void OnActionKeywordsChanged()
|
||||
|
|
@ -135,6 +137,11 @@ namespace Flow.Launcher.ViewModel
|
|||
OnPropertyChanged(nameof(ActionKeywordsText));
|
||||
}
|
||||
|
||||
public void OnSearchDelaySpeedChanged()
|
||||
{
|
||||
OnPropertyChanged(nameof(SearchDelaySpeedText));
|
||||
}
|
||||
|
||||
public void ChangePriority(int newPriority)
|
||||
{
|
||||
PluginPair.Metadata.Priority = newPriority;
|
||||
|
|
@ -180,8 +187,8 @@ namespace Flow.Launcher.ViewModel
|
|||
[RelayCommand]
|
||||
private void SetSearchDelaySpeed()
|
||||
{
|
||||
/*var searchDelaySpeedWindow = new SearchDelaySpeedWindow(this);
|
||||
searchDelaySpeedWindow.ShowDialog();*/
|
||||
var searchDelaySpeedWindow = new SearchDelaySpeedWindow(this);
|
||||
searchDelaySpeedWindow.ShowDialog();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue