Skip to content

Commit c925a79

Browse files
committed
Support changing plugin search delay
1 parent a333041 commit c925a79

File tree

6 files changed

+213
-8
lines changed

6 files changed

+213
-8
lines changed

Flow.Launcher/Languages/en.xaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,12 @@
365365
<system:String x:Key="completedSuccessfully">Completed successfully</system:String>
366366
<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>
367367

368+
<!-- Search Delay Settings Dialog -->
369+
<system:String x:Key="searchDelaySpeedTitle">Search Delay Speed Setting</system:String>
370+
<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>
371+
<system:String x:Key="currentSearchDelaySpeed">Current search delay speed</system:String>
372+
<system:String x:Key="newSearchDelaySpeed">New search delay speed</system:String>
373+
368374
<!-- Custom Query Hotkey Dialog -->
369375
<system:String x:Key="customeQueryHotkeyTitle">Custom Query Hotkey</system:String>
370376
<system:String x:Key="customeQueryHotkeyTips">Press a custom hotkey to open Flow Launcher and input the specified query automatically.</system:String>
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
<Window
2+
x:Class="Flow.Launcher.SearchDelaySpeedWindow"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
Title="{DynamicResource searchDelaySpeedTitle}"
6+
Width="450"
7+
Background="{DynamicResource PopuBGColor}"
8+
Foreground="{DynamicResource PopupTextColor}"
9+
Icon="Images\app.png"
10+
Loaded="SearchDelaySpeed_OnLoaded"
11+
ResizeMode="NoResize"
12+
SizeToContent="Height"
13+
WindowStartupLocation="CenterScreen">
14+
<WindowChrome.WindowChrome>
15+
<WindowChrome CaptionHeight="32" ResizeBorderThickness="{x:Static SystemParameters.WindowResizeBorderThickness}" />
16+
</WindowChrome.WindowChrome>
17+
<Grid>
18+
<Grid.RowDefinitions>
19+
<RowDefinition />
20+
<RowDefinition Height="80" />
21+
</Grid.RowDefinitions>
22+
<Grid>
23+
<StackPanel Grid.Row="0">
24+
<StackPanel>
25+
<Grid>
26+
<Grid.ColumnDefinitions>
27+
<ColumnDefinition Width="Auto" />
28+
<ColumnDefinition Width="*" />
29+
<ColumnDefinition Width="Auto" />
30+
<ColumnDefinition Width="Auto" />
31+
<ColumnDefinition Width="Auto" />
32+
</Grid.ColumnDefinitions>
33+
<Button
34+
Grid.Column="4"
35+
Click="BtnCancel_OnClick"
36+
Style="{StaticResource TitleBarCloseButtonStyle}">
37+
<Path
38+
Width="46"
39+
Height="32"
40+
Data="M 18,11 27,20 M 18,20 27,11"
41+
Stroke="{Binding Path=Foreground, RelativeSource={RelativeSource AncestorType={x:Type Button}}}"
42+
StrokeThickness="1">
43+
<Path.Style>
44+
<Style TargetType="Path">
45+
<Style.Triggers>
46+
<DataTrigger Binding="{Binding Path=IsActive, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}" Value="False">
47+
<Setter Property="Opacity" Value="0.5" />
48+
</DataTrigger>
49+
</Style.Triggers>
50+
</Style>
51+
</Path.Style>
52+
</Path>
53+
</Button>
54+
</Grid>
55+
</StackPanel>
56+
<StackPanel Margin="26 12 26 0">
57+
<StackPanel Grid.Row="0" Margin="0 0 0 12">
58+
<TextBlock
59+
Grid.Column="0"
60+
Margin="0 0 0 0"
61+
FontSize="20"
62+
FontWeight="SemiBold"
63+
Text="{DynamicResource searchDelaySpeedTitle}"
64+
TextAlignment="Left" />
65+
</StackPanel>
66+
<StackPanel>
67+
<TextBlock
68+
FontSize="14"
69+
Text="{DynamicResource searchDelaySpeed_tips}"
70+
TextAlignment="Left"
71+
TextWrapping="WrapWithOverflow" />
72+
</StackPanel>
73+
74+
<StackPanel Margin="0 18 0 0" Orientation="Horizontal">
75+
<TextBlock
76+
Grid.Row="0"
77+
Grid.Column="1"
78+
HorizontalAlignment="Left"
79+
VerticalAlignment="Center"
80+
FontSize="14"
81+
Text="{DynamicResource currentSearchDelaySpeed}" />
82+
<TextBlock
83+
x:Name="tbOldSearchDelaySpeed"
84+
Grid.Row="0"
85+
Grid.Column="1"
86+
Margin="14 10 10 10"
87+
HorizontalAlignment="Left"
88+
VerticalAlignment="Center"
89+
FontSize="14"
90+
FontWeight="SemiBold"
91+
Foreground="{DynamicResource Color05B}" />
92+
</StackPanel>
93+
<StackPanel Margin="0 0 0 10" Orientation="Horizontal">
94+
<TextBlock
95+
Grid.Row="1"
96+
Grid.Column="1"
97+
HorizontalAlignment="Left"
98+
VerticalAlignment="Center"
99+
FontSize="14"
100+
Text="{DynamicResource newSearchDelaySpeed}" />
101+
<ComboBox
102+
x:Name="tbDelay"
103+
MaxWidth="200"
104+
Margin="10 10 15 10"
105+
HorizontalAlignment="Left"
106+
VerticalAlignment="Center"
107+
DisplayMemberPath="Display"
108+
SelectedValuePath="Value" />
109+
</StackPanel>
110+
</StackPanel>
111+
</StackPanel>
112+
</Grid>
113+
<Border
114+
Grid.Row="1"
115+
Background="{DynamicResource PopupButtonAreaBGColor}"
116+
BorderBrush="{DynamicResource PopupButtonAreaBorderColor}"
117+
BorderThickness="0 1 0 0">
118+
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal">
119+
<Button
120+
x:Name="btnCancel"
121+
Width="145"
122+
Height="30"
123+
Margin="10 0 5 0"
124+
Click="BtnCancel_OnClick"
125+
Content="{DynamicResource cancel}" />
126+
<Button
127+
x:Name="btnDone"
128+
Width="145"
129+
Height="30"
130+
Margin="5 0 10 0"
131+
Click="btnDone_OnClick"
132+
Style="{StaticResource AccentButtonStyle}">
133+
<TextBlock x:Name="lblAdd" Text="{DynamicResource done}" />
134+
</Button>
135+
</StackPanel>
136+
</Border>
137+
</Grid>
138+
</Window>
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using System.Linq;
2+
using System.Windows;
3+
using Flow.Launcher.Plugin;
4+
using Flow.Launcher.SettingPages.ViewModels;
5+
using Flow.Launcher.ViewModel;
6+
using static Flow.Launcher.SettingPages.ViewModels.SettingsPaneGeneralViewModel;
7+
8+
namespace Flow.Launcher;
9+
10+
public partial class SearchDelaySpeedWindow : Window
11+
{
12+
private readonly PluginViewModel _pluginViewModel;
13+
14+
public SearchDelaySpeedWindow(PluginViewModel pluginViewModel)
15+
{
16+
InitializeComponent();
17+
_pluginViewModel = pluginViewModel;
18+
}
19+
20+
private void SearchDelaySpeed_OnLoaded(object sender, RoutedEventArgs e)
21+
{
22+
tbOldSearchDelaySpeed.Text = _pluginViewModel.SearchDelaySpeedText;
23+
var searchDelaySpeeds = DropdownDataGeneric<SearchDelaySpeeds>.GetValues<SearchDelaySpeedData>("SearchDelaySpeed");
24+
SearchDelaySpeedData selected = null;
25+
// Because default value is SearchDelaySpeeds.Slow, we need to get selected value before adding default value
26+
if (_pluginViewModel.PluginSearchDelay != null)
27+
{
28+
selected = searchDelaySpeeds.FirstOrDefault(x => x.Value == _pluginViewModel.PluginSearchDelay);
29+
}
30+
// Add default value to the beginning of the list
31+
// This value should be null
32+
searchDelaySpeeds.Insert(0, new SearchDelaySpeedData { Display = App.API.GetTranslation(PluginViewModel.DefaultLocalizationKey), LocalizationKey = PluginViewModel.DefaultLocalizationKey });
33+
selected ??= searchDelaySpeeds.FirstOrDefault();
34+
tbDelay.ItemsSource = searchDelaySpeeds;
35+
tbDelay.SelectedItem = selected;
36+
tbDelay.Focus();
37+
}
38+
39+
private void BtnCancel_OnClick(object sender, RoutedEventArgs e)
40+
{
41+
Close();
42+
}
43+
44+
private void btnDone_OnClick(object sender, RoutedEventArgs _)
45+
{
46+
// Update search delay speed
47+
var selected = tbDelay.SelectedItem as SearchDelaySpeedData;
48+
SearchDelaySpeeds? changedValue = selected?.LocalizationKey != PluginViewModel.DefaultLocalizationKey ? selected.Value : null;
49+
_pluginViewModel.PluginSearchDelay = changedValue;
50+
51+
// Update search delay speed text and close window
52+
_pluginViewModel.OnSearchDelaySpeedChanged();
53+
Close();
54+
}
55+
}

Flow.Launcher/SettingPages/ViewModels/DropdownDataGeneric.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.Collections.Generic;
3-
using Flow.Launcher.Core.Resource;
43
using Flow.Launcher.Plugin;
54

65
namespace Flow.Launcher.SettingPages.ViewModels;
@@ -9,7 +8,7 @@ public class DropdownDataGeneric<TValue> : BaseModel where TValue : Enum
98
{
109
public string Display { get; set; }
1110
public TValue Value { get; private init; }
12-
private string LocalizationKey { get; init; }
11+
public string LocalizationKey { get; set; }
1312

1413
public static List<TR> GetValues<TR>(string keyPrefix) where TR : DropdownDataGeneric<TValue>, new()
1514
{
@@ -19,7 +18,7 @@ public class DropdownDataGeneric<TValue> : BaseModel where TValue : Enum
1918
foreach (var value in enumValues)
2019
{
2120
var key = keyPrefix + value;
22-
var display = InternationalizationManager.Instance.GetTranslation(key);
21+
var display = App.API.GetTranslation(key);
2322
data.Add(new TR { Display = display, Value = value, LocalizationKey = key });
2423
}
2524

@@ -30,7 +29,7 @@ public static void UpdateLabels<TR>(List<TR> options) where TR : DropdownDataGen
3029
{
3130
foreach (var item in options)
3231
{
33-
item.Display = InternationalizationManager.Instance.GetTranslation(item.LocalizationKey);
32+
item.Display = App.API.GetTranslation(item.LocalizationKey);
3433
}
3534
}
3635
}

Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public bool PortableMode
150150
public SearchDelaySpeedData SearchDelaySpeed
151151
{
152152
get => SearchDelaySpeeds.FirstOrDefault(x => x.Value == Settings.SearchDelaySpeed) ??
153-
SearchDelaySpeeds.FirstOrDefault(x => x.Value == Flow.Launcher.Plugin.SearchDelaySpeeds.Medium) ??
153+
SearchDelaySpeeds.FirstOrDefault(x => x.Value == Plugin.SearchDelaySpeeds.Medium) ??
154154
SearchDelaySpeeds.FirstOrDefault();
155155
set
156156
{

Flow.Launcher/ViewModel/PluginViewModel.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ namespace Flow.Launcher.ViewModel
1313
{
1414
public partial class PluginViewModel : BaseModel
1515
{
16+
public const string DefaultLocalizationKey = "default";
17+
1618
private readonly PluginPair _pluginPair;
1719
public PluginPair PluginPair
1820
{
@@ -127,14 +129,19 @@ public Control SettingControl
127129
PluginPair.Metadata.AvgQueryTime + "ms";
128130
public string ActionKeywordsText => string.Join(Query.ActionKeywordSeparator, PluginPair.Metadata.ActionKeywords);
129131
public int Priority => PluginPair.Metadata.Priority;
130-
public string SearchDelaySpeedText => PluginPair.Metadata.SearchDelaySpeed == null ? App.API.GetTranslation("default") : App.API.GetTranslation($"SearchDelaySpeed{PluginPair.Metadata.SearchDelaySpeed}");
132+
public string SearchDelaySpeedText => PluginPair.Metadata.SearchDelaySpeed == null ? App.API.GetTranslation(DefaultLocalizationKey) : App.API.GetTranslation($"SearchDelaySpeed{PluginPair.Metadata.SearchDelaySpeed}");
131133
public Infrastructure.UserSettings.Plugin PluginSettingsObject{ get; init; }
132134

133135
public void OnActionKeywordsChanged()
134136
{
135137
OnPropertyChanged(nameof(ActionKeywordsText));
136138
}
137139

140+
public void OnSearchDelaySpeedChanged()
141+
{
142+
OnPropertyChanged(nameof(SearchDelaySpeedText));
143+
}
144+
138145
public void ChangePriority(int newPriority)
139146
{
140147
PluginPair.Metadata.Priority = newPriority;
@@ -180,8 +187,8 @@ private void SetActionKeywords()
180187
[RelayCommand]
181188
private void SetSearchDelaySpeed()
182189
{
183-
/*var searchDelaySpeedWindow = new SearchDelaySpeedWindow(this);
184-
searchDelaySpeedWindow.ShowDialog();*/
190+
var searchDelaySpeedWindow = new SearchDelaySpeedWindow(this);
191+
searchDelaySpeedWindow.ShowDialog();
185192
}
186193
}
187194
}

0 commit comments

Comments
 (0)