Change to search delay time

This commit is contained in:
Jack251970 2025-03-31 13:26:09 +08:00
parent dec1e77b0c
commit c4cd51c312
14 changed files with 115 additions and 118 deletions

View file

@ -51,7 +51,7 @@ namespace Flow.Launcher.Infrastructure.UserSettings
settings.Version = metadata.Version;
}
settings.DefaultActionKeywords = metadata.ActionKeywords; // metadata provides default values
settings.DefaultSearchDelaySpeed = metadata.SearchDelaySpeed; // metadata provides default values
settings.DefaultSearchDelayTime = metadata.SearchDelayTime; // metadata provides default values
// update metadata values with settings
if (settings.ActionKeywords?.Count > 0)
@ -66,7 +66,7 @@ namespace Flow.Launcher.Infrastructure.UserSettings
}
metadata.Disabled = settings.Disabled;
metadata.Priority = settings.Priority;
metadata.SearchDelaySpeed = settings.SearchDelaySpeed;
metadata.SearchDelayTime = settings.SearchDelayTime;
}
else
{
@ -80,8 +80,8 @@ namespace Flow.Launcher.Infrastructure.UserSettings
ActionKeywords = metadata.ActionKeywords, // use default value
Disabled = metadata.Disabled,
Priority = metadata.Priority,
DefaultSearchDelaySpeed = metadata.SearchDelaySpeed, // metadata provides default values
SearchDelaySpeed = metadata.SearchDelaySpeed, // use default value
DefaultSearchDelayTime = metadata.SearchDelayTime, // metadata provides default values
SearchDelayTime = metadata.SearchDelayTime, // use default value
};
}
}
@ -120,10 +120,10 @@ namespace Flow.Launcher.Infrastructure.UserSettings
public int Priority { get; set; }
[JsonIgnore]
public SearchDelaySpeeds? DefaultSearchDelaySpeed { get; set; }
public SearchDelayTime? DefaultSearchDelayTime { get; set; }
[JsonConverter(typeof(JsonStringEnumConverter))]
public SearchDelaySpeeds? SearchDelaySpeed { get; set; }
public SearchDelayTime? SearchDelayTime { get; set; }
/// <summary>
/// Used only to save the state of the plugin in settings

View file

@ -323,7 +323,7 @@ namespace Flow.Launcher.Infrastructure.UserSettings
public bool SearchQueryResultsWithDelay { get; set; }
[JsonConverter(typeof(JsonStringEnumConverter))]
public SearchDelaySpeeds SearchDelaySpeed { get; set; } = SearchDelaySpeeds.Medium;
public SearchDelayTime SearchDelayTime { get; set; } = SearchDelayTime.Medium;
[JsonConverter(typeof(JsonStringEnumConverter))]
public SearchWindowScreens SearchWindowScreen { get; set; } = SearchWindowScreens.Cursor;

View file

@ -99,10 +99,10 @@ namespace Flow.Launcher.Plugin
public bool HideActionKeywordPanel { get; set; }
/// <summary>
/// Plugin search delay speed. Null means use default search delay.
/// Plugin search delay time. Null means use default search delay time.
/// </summary>
[JsonConverter(typeof(JsonStringEnumConverter))]
public SearchDelaySpeeds? SearchDelaySpeed { get; set; } = null;
public SearchDelayTime? SearchDelayTime { get; set; } = null;
/// <summary>
/// Plugin icon path.

View file

@ -1,32 +0,0 @@
namespace Flow.Launcher.Plugin;
/// <summary>
/// Enum for search delay speeds
/// </summary>
public enum SearchDelaySpeeds
{
/// <summary>
/// Slow search delay speed. 50ms.
/// </summary>
Slow,
/// <summary>
/// Moderately slow search delay speed. 100ms.
/// </summary>
ModeratelySlow,
/// <summary>
/// Medium search delay speed. 150ms. Default value.
/// </summary>
Medium,
/// <summary>
/// Moderately fast search delay speed. 200ms.
/// </summary>
ModeratelyFast,
/// <summary>
/// Fast search delay speed. 250ms.
/// </summary>
Fast
}

View file

@ -0,0 +1,32 @@
namespace Flow.Launcher.Plugin;
/// <summary>
/// Enum for search delay time
/// </summary>
public enum SearchDelayTime
{
/// <summary>
/// Long search delay time. 250ms.
/// </summary>
Long,
/// <summary>
/// Moderately long search delay time. 200ms.
/// </summary>
ModeratelyLong,
/// <summary>
/// Medium search delay time. 150ms. Default value.
/// </summary>
Medium,
/// <summary>
/// Moderately short search delay time. 100ms.
/// </summary>
ModeratelyShort,
/// <summary>
/// Short search delay time. 50ms.
/// </summary>
Short
}

View file

@ -104,13 +104,13 @@
<system:String x:Key="shadowEffectNotAllowed">Shadow effect is not allowed while current theme has blur effect enabled</system:String>
<system:String x:Key="searchDelay">Search Delay</system:String>
<system:String x:Key="searchDelayToolTip">Delay for a while to search when typing. This reduces interface jumpiness and result load.</system:String>
<system:String x:Key="searchDelaySpeed">Default Search Delay Speed</system:String>
<system:String x:Key="searchDelaySpeedToolTip">Plugins default delay time after which search results appear when typing is stopped. Default is medium.</system:String>
<system:String x:Key="SearchDelaySpeedSlow">Slow</system:String>
<system:String x:Key="SearchDelaySpeedModeratelySlow">Moderately slow</system:String>
<system:String x:Key="SearchDelaySpeedMedium">Medium</system:String>
<system:String x:Key="SearchDelaySpeedModeratelyFast">Moderately fast</system:String>
<system:String x:Key="SearchDelaySpeedFast">Fast</system:String>
<system:String x:Key="searchDelayTime">Default Search Delay Time</system:String>
<system:String x:Key="searchDelayTimeToolTip">Plugin default delay time after which search results appear when typing is stopped. Default is "Medium".</system:String>
<system:String x:Key="SearchDelayTimeLong">Long</system:String>
<system:String x:Key="SearchDelayTimeModeratelyLong">Moderately long</system:String>
<system:String x:Key="SearchDelayTimeMedium">Medium</system:String>
<system:String x:Key="SearchDelayTimeModeratelyShort">Moderately short</system:String>
<system:String x:Key="SearchDelayTimeShort">Short</system:String>
<!-- Setting Plugin -->
<system:String x:Key="searchplugin">Search Plugin</system:String>
@ -127,8 +127,8 @@
<system:String x:Key="currentActionKeywords">Current action keyword</system:String>
<system:String x:Key="newActionKeyword">New action keyword</system:String>
<system:String x:Key="actionKeywordsTooltip">Change Action Keywords</system:String>
<system:String x:Key="pluginSearchDelaySpeed">Plugin seach delay speed</system:String>
<system:String x:Key="pluginSearchDelaySpeedTooltip">Change Plugin Seach Delay Speed</system:String>
<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="currentPriority">Current Priority</system:String>
<system:String x:Key="newPriority">New Priority</system:String>
<system:String x:Key="priority">Priority</system:String>
@ -366,10 +366,10 @@
<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>
<system:String x:Key="searchDelayTimeTitle">Search Delay Time Setting</system:String>
<system:String x:Key="searchDelayTime_tips">Select the search delay time you like to use for the plugin. Select "{0}" if you don't want to specify any, and the plugin will use default search delay time.</system:String>
<system:String x:Key="currentSearchDelayTime">Current search delay time</system:String>
<system:String x:Key="newSearchDelayTime">New search delay time</system:String>
<!-- Custom Query Hotkey Dialog -->
<system:String x:Key="customeQueryHotkeyTitle">Custom Query Hotkey</system:String>

View file

@ -32,18 +32,18 @@
VerticalAlignment="Center"
DockPanel.Dock="Left"
Style="{DynamicResource SettingTitleLabel}"
Text="{DynamicResource pluginSearchDelaySpeed}" />
Text="{DynamicResource pluginSearchDelayTime}" />
<!-- Here Margin="0 -4.5 0 -4.5" is to remove redundant top bottom margin from Margin="{StaticResource SettingPanelMargin}" -->
<Button
Width="100"
Margin="0 -4.5 0 -4.5"
HorizontalAlignment="Right"
Command="{Binding SetSearchDelaySpeedCommand}"
Content="{Binding SearchDelaySpeedText}"
Command="{Binding SetSearchDelayTimeCommand}"
Content="{Binding SearchDelayTimeText}"
Cursor="Hand"
DockPanel.Dock="Right"
FontWeight="Bold"
ToolTip="{DynamicResource pluginSearchDelaySpeedTooltip}" />
ToolTip="{DynamicResource pluginSearchDelayTimeTooltip}" />
</DockPanel>
</Border>
</UserControl>

View file

@ -1,13 +1,13 @@
<Window
x:Class="Flow.Launcher.SearchDelaySpeedWindow"
x:Class="Flow.Launcher.SearchDelayTimeWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="{DynamicResource searchDelaySpeedTitle}"
Title="{DynamicResource searchDelayTimeTitle}"
Width="450"
Background="{DynamicResource PopuBGColor}"
Foreground="{DynamicResource PopupTextColor}"
Icon="Images\app.png"
Loaded="SearchDelaySpeed_OnLoaded"
Loaded="SearchDelayTimeWindow_OnLoaded"
ResizeMode="NoResize"
SizeToContent="Height"
WindowStartupLocation="CenterScreen">
@ -60,13 +60,13 @@
Margin="0 0 0 0"
FontSize="20"
FontWeight="SemiBold"
Text="{DynamicResource searchDelaySpeedTitle}"
Text="{DynamicResource searchDelayTimeTitle}"
TextAlignment="Left" />
</StackPanel>
<StackPanel>
<TextBlock
FontSize="14"
Text="{DynamicResource searchDelaySpeed_tips}"
Text="{DynamicResource searchDelayTime_tips}"
TextAlignment="Left"
TextWrapping="WrapWithOverflow" />
</StackPanel>
@ -78,9 +78,9 @@
HorizontalAlignment="Left"
VerticalAlignment="Center"
FontSize="14"
Text="{DynamicResource currentSearchDelaySpeed}" />
Text="{DynamicResource currentSearchDelayTime}" />
<TextBlock
x:Name="tbOldSearchDelaySpeed"
x:Name="tbOldSearchDelayTime"
Grid.Row="0"
Grid.Column="1"
Margin="14 10 10 10"
@ -97,7 +97,7 @@
HorizontalAlignment="Left"
VerticalAlignment="Center"
FontSize="14"
Text="{DynamicResource newSearchDelaySpeed}" />
Text="{DynamicResource newSearchDelayTime}" />
<ComboBox
x:Name="tbDelay"
MaxWidth="200"

View file

@ -7,31 +7,31 @@ using static Flow.Launcher.SettingPages.ViewModels.SettingsPaneGeneralViewModel;
namespace Flow.Launcher;
public partial class SearchDelaySpeedWindow : Window
public partial class SearchDelayTimeWindow : Window
{
private readonly PluginViewModel _pluginViewModel;
public SearchDelaySpeedWindow(PluginViewModel pluginViewModel)
public SearchDelayTimeWindow(PluginViewModel pluginViewModel)
{
InitializeComponent();
_pluginViewModel = pluginViewModel;
}
private void SearchDelaySpeed_OnLoaded(object sender, RoutedEventArgs e)
private void SearchDelayTimeWindow_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)
tbOldSearchDelayTime.Text = _pluginViewModel.SearchDelayTimeText;
var searchDelayTimes = DropdownDataGeneric<SearchDelayTime>.GetValues<SearchDelayTimeData>("SearchDelayTime");
SearchDelayTimeData selected = null;
// Because default value is SearchDelayTime.Slow, we need to get selected value before adding default value
if (_pluginViewModel.PluginSearchDelayTime != null)
{
selected = searchDelaySpeeds.FirstOrDefault(x => x.Value == _pluginViewModel.PluginSearchDelay);
selected = searchDelayTimes.FirstOrDefault(x => x.Value == _pluginViewModel.PluginSearchDelayTime);
}
// Add default value to the beginning of the list
// When _pluginViewModel.PluginSearchDelay equals null, we will select this
searchDelaySpeeds.Insert(0, new SearchDelaySpeedData { Display = App.API.GetTranslation(PluginViewModel.DefaultLocalizationKey), LocalizationKey = PluginViewModel.DefaultLocalizationKey });
selected ??= searchDelaySpeeds.FirstOrDefault();
tbDelay.ItemsSource = searchDelaySpeeds;
searchDelayTimes.Insert(0, new SearchDelayTimeData { Display = App.API.GetTranslation("default"), LocalizationKey = "default" });
selected ??= searchDelayTimes.FirstOrDefault();
tbDelay.ItemsSource = searchDelayTimes;
tbDelay.SelectedItem = selected;
tbDelay.Focus();
}
@ -43,13 +43,13 @@ public partial class SearchDelaySpeedWindow : Window
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 time
var selected = tbDelay.SelectedItem as SearchDelayTimeData;
SearchDelayTime? changedValue = selected?.LocalizationKey != "default" ? selected.Value : null;
_pluginViewModel.PluginSearchDelayTime = changedValue;
// Update search delay speed text and close window
_pluginViewModel.OnSearchDelaySpeedChanged();
// Update search delay time text and close window
_pluginViewModel.OnSearchDelayTimeChanged();
Close();
}
}

View file

@ -31,7 +31,7 @@ public partial class SettingsPaneGeneralViewModel : BaseModel
public class SearchWindowAlignData : DropdownDataGeneric<SearchWindowAligns> { }
public class SearchPrecisionData : DropdownDataGeneric<SearchPrecisionScore> { }
public class LastQueryModeData : DropdownDataGeneric<LastQueryMode> { }
public class SearchDelaySpeedData : DropdownDataGeneric<SearchDelaySpeeds> { }
public class SearchDelayTimeData : DropdownDataGeneric<SearchDelayTime> { }
public bool StartFlowLauncherOnSystemStartup
{
@ -144,22 +144,22 @@ public partial class SettingsPaneGeneralViewModel : BaseModel
public List<LastQueryModeData> LastQueryModes { get; } =
DropdownDataGeneric<LastQueryMode>.GetValues<LastQueryModeData>("LastQuery");
public List<SearchDelaySpeedData> SearchDelaySpeeds { get; } =
DropdownDataGeneric<SearchDelaySpeeds>.GetValues<SearchDelaySpeedData>("SearchDelaySpeed");
public List<SearchDelayTimeData> SearchDelayTimes { get; } =
DropdownDataGeneric<SearchDelayTime>.GetValues<SearchDelayTimeData>("SearchDelayTime");
public SearchDelaySpeedData SearchDelaySpeed
public SearchDelayTimeData SearchDelayTime
{
get => SearchDelaySpeeds.FirstOrDefault(x => x.Value == Settings.SearchDelaySpeed) ??
SearchDelaySpeeds.FirstOrDefault(x => x.Value == Plugin.SearchDelaySpeeds.Medium) ??
SearchDelaySpeeds.FirstOrDefault();
get => SearchDelayTimes.FirstOrDefault(x => x.Value == Settings.SearchDelayTime) ??
SearchDelayTimes.FirstOrDefault(x => x.Value == Plugin.SearchDelayTime.Medium) ??
SearchDelayTimes.FirstOrDefault();
set
{
if (value == null)
return;
if (Settings.SearchDelaySpeed != value.Value)
if (Settings.SearchDelayTime != value.Value)
{
Settings.SearchDelaySpeed = value.Value;
Settings.SearchDelayTime = value.Value;
}
}
}
@ -170,7 +170,7 @@ public partial class SettingsPaneGeneralViewModel : BaseModel
DropdownDataGeneric<SearchWindowAligns>.UpdateLabels(SearchWindowAligns);
DropdownDataGeneric<SearchPrecisionScore>.UpdateLabels(SearchPrecisionScores);
DropdownDataGeneric<LastQueryMode>.UpdateLabels(LastQueryModes);
DropdownDataGeneric<SearchDelaySpeeds>.UpdateLabels(SearchDelaySpeeds);
DropdownDataGeneric<SearchDelayTime>.UpdateLabels(SearchDelayTimes);
}
public string Language

View file

@ -184,14 +184,14 @@
</cc:Card>
<cc:Card
Title="{DynamicResource searchDelaySpeed}"
Title="{DynamicResource searchDelayTime}"
Icon="&#xE916;"
Sub="{DynamicResource searchDelaySpeedToolTip}">
Sub="{DynamicResource searchDelayTimeToolTip}">
<ComboBox
MaxWidth="200"
DisplayMemberPath="Display"
ItemsSource="{Binding SearchDelaySpeeds}"
SelectedItem="{Binding SearchDelaySpeed}"
ItemsSource="{Binding SearchDelayTimes}"
SelectedItem="{Binding SearchDelayTime}"
SelectedValuePath="Value" />
</cc:Card>
</cc:CardGroup>

View file

@ -1271,14 +1271,13 @@ namespace Flow.Launcher.ViewModel
{
if (searchDelay)
{
var searchDelaySpeed = plugin.Metadata.SearchDelaySpeed ?? Settings.SearchDelaySpeed;
var searchDelayTime = searchDelaySpeed switch
var searchDelayTime = (plugin.Metadata.SearchDelayTime ?? Settings.SearchDelayTime) switch
{
SearchDelaySpeeds.Slow => 250,
SearchDelaySpeeds.ModeratelySlow => 200,
SearchDelaySpeeds.Medium => 150,
SearchDelaySpeeds.ModeratelyFast => 100,
SearchDelaySpeeds.Fast => 50,
SearchDelayTime.Long => 250,
SearchDelayTime.ModeratelyLong => 200,
SearchDelayTime.Medium => 150,
SearchDelayTime.ModeratelyShort => 100,
SearchDelayTime.Short => 50,
_ => 150
};

View file

@ -13,8 +13,6 @@ namespace Flow.Launcher.ViewModel
{
public partial class PluginViewModel : BaseModel
{
public const string DefaultLocalizationKey = "default";
private readonly PluginPair _pluginPair;
public PluginPair PluginPair
{
@ -85,13 +83,13 @@ namespace Flow.Launcher.ViewModel
}
}
public SearchDelaySpeeds? PluginSearchDelay
public SearchDelayTime? PluginSearchDelayTime
{
get => PluginPair.Metadata.SearchDelaySpeed;
get => PluginPair.Metadata.SearchDelayTime;
set
{
PluginPair.Metadata.SearchDelaySpeed = value;
PluginSettingsObject.SearchDelaySpeed = value;
PluginPair.Metadata.SearchDelayTime = value;
PluginSettingsObject.SearchDelayTime = value;
}
}
@ -129,7 +127,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(DefaultLocalizationKey) : App.API.GetTranslation($"SearchDelaySpeed{PluginPair.Metadata.SearchDelaySpeed}");
public string SearchDelayTimeText => PluginPair.Metadata.SearchDelayTime == null ? App.API.GetTranslation("default") : App.API.GetTranslation($"SearchDelayTime{PluginPair.Metadata.SearchDelayTime}");
public Infrastructure.UserSettings.Plugin PluginSettingsObject{ get; init; }
public void OnActionKeywordsChanged()
@ -137,9 +135,9 @@ namespace Flow.Launcher.ViewModel
OnPropertyChanged(nameof(ActionKeywordsText));
}
public void OnSearchDelaySpeedChanged()
public void OnSearchDelayTimeChanged()
{
OnPropertyChanged(nameof(SearchDelaySpeedText));
OnPropertyChanged(nameof(SearchDelayTimeText));
}
public void ChangePriority(int newPriority)
@ -185,10 +183,10 @@ namespace Flow.Launcher.ViewModel
}
[RelayCommand]
private void SetSearchDelaySpeed()
private void SetSearchDelayTime()
{
var searchDelaySpeedWindow = new SearchDelaySpeedWindow(this);
searchDelaySpeedWindow.ShowDialog();
var searchDelayTimeWindow = new SearchDelayTimeWindow(this);
searchDelayTimeWindow.ShowDialog();
}
}
}

View file

@ -32,5 +32,5 @@
"Website": "https://github.com/Flow-Launcher/Flow.Launcher",
"ExecuteFileName": "Flow.Launcher.Plugin.WebSearch.dll",
"IcoPath": "Images\\web_search.png",
"SearchDelaySpeed": "Slow"
"SearchDelayTime": "Long"
}