[PTRun]Add setting to disable input delay (#18724)

* [PTRun]Add setting to disable input delay

* Address feedback and allow configuring delay

* Address PR feedback
This commit is contained in:
Jaime Bernardo 2022-06-12 14:12:10 +01:00 committed by GitHub
parent b33bc2ecd0
commit 1490fb300c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 185 additions and 7 deletions

View File

@ -36,6 +36,7 @@ namespace PowerLauncher
private Timer _firstDeleteTimer = new Timer();
private bool _coldStateHotkeyPressed;
private bool _disposedValue;
private IDisposable _reactiveSubscription;
public MainWindow(PowerToysRunSettings settings, MainViewModel mainVM)
: this()
@ -159,13 +160,18 @@ namespace PowerLauncher
SearchBox.QueryTextBox.DataContext = _viewModel;
SearchBox.QueryTextBox.PreviewKeyDown += Launcher_KeyDown;
Observable.FromEventPattern<TextChangedEventHandler, TextChangedEventArgs>(
add => SearchBox.QueryTextBox.TextChanged += add,
remove => SearchBox.QueryTextBox.TextChanged -= remove)
.Do(@event => ClearAutoCompleteText((TextBox)@event.Sender))
.Throttle(TimeSpan.FromMilliseconds(150))
.Do(@event => Dispatcher.InvokeAsync(() => PerformSearchQuery((TextBox)@event.Sender)))
.Subscribe();
SetupSearchTextBoxReactiveness(_viewModel.GetSearchQueryResultsWithDelaySetting(), _viewModel.GetSearchInputDelaySetting());
_viewModel.RegisterSettingsChangeListener(
(s, prop_e) =>
{
if (prop_e.PropertyName == nameof(PowerToysRunSettings.SearchQueryResultsWithDelay) || prop_e.PropertyName == nameof(PowerToysRunSettings.SearchInputDelay))
{
Application.Current.Dispatcher.Invoke(() =>
{
SetupSearchTextBoxReactiveness(_viewModel.GetSearchQueryResultsWithDelaySetting(), _viewModel.GetSearchInputDelaySetting());
});
}
});
// Set initial language flow direction
SearchBox_UpdateFlowDirection();
@ -186,6 +192,32 @@ namespace PowerLauncher
BringProcessToForeground();
}
private void SetupSearchTextBoxReactiveness(bool showResultsWithDelay, int searchInputDelayMs)
{
if (_reactiveSubscription != null)
{
_reactiveSubscription.Dispose();
_reactiveSubscription = null;
}
SearchBox.QueryTextBox.TextChanged -= QueryTextBox_TextChanged;
if (showResultsWithDelay)
{
_reactiveSubscription = Observable.FromEventPattern<TextChangedEventHandler, TextChangedEventArgs>(
add => SearchBox.QueryTextBox.TextChanged += add,
remove => SearchBox.QueryTextBox.TextChanged -= remove)
.Do(@event => ClearAutoCompleteText((TextBox)@event.Sender))
.Throttle(TimeSpan.FromMilliseconds(searchInputDelayMs))
.Do(@event => Dispatcher.InvokeAsync(() => PerformSearchQuery((TextBox)@event.Sender)))
.Subscribe();
}
else
{
SearchBox.QueryTextBox.TextChanged += QueryTextBox_TextChanged;
}
}
private void SuggestionsList_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
var result = ((FrameworkElement)e.OriginalSource).DataContext;
@ -428,6 +460,13 @@ namespace PowerLauncher
}
}
private void QueryTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
var textBox = (TextBox)sender;
ClearAutoCompleteText(textBox);
PerformSearchQuery(textBox);
}
private void ClearAutoCompleteText(TextBox textBox)
{
var text = textBox.Text;

View File

@ -105,6 +105,16 @@ namespace PowerLauncher
_settings.UseCentralizedKeyboardHook = overloadSettings.Properties.UseCentralizedKeyboardHook;
}
if (_settings.SearchQueryResultsWithDelay != overloadSettings.Properties.SearchQueryResultsWithDelay)
{
_settings.SearchQueryResultsWithDelay = overloadSettings.Properties.SearchQueryResultsWithDelay;
}
if (_settings.SearchInputDelay != overloadSettings.Properties.SearchInputDelay)
{
_settings.SearchInputDelay = overloadSettings.Properties.SearchInputDelay;
}
if (_settings.MaxResultsToShow != overloadSettings.Properties.MaximumNumberOfResults)
{
_settings.MaxResultsToShow = overloadSettings.Properties.MaximumNumberOfResults;

View File

@ -132,6 +132,11 @@ namespace PowerLauncher.ViewModel
// SetCustomPluginHotkey();
}
public void RegisterSettingsChangeListener(System.ComponentModel.PropertyChangedEventHandler handler)
{
_settings.PropertyChanged += handler;
}
private void RegisterResultsUpdatedEvent()
{
foreach (var pair in PluginManager.GetPluginsForInterface<IResultUpdated>())
@ -1102,5 +1107,15 @@ namespace PowerLauncher.ViewModel
_hotkeyTimer.Reset();
return recordedTime;
}
public bool GetSearchQueryResultsWithDelaySetting()
{
return _settings.SearchQueryResultsWithDelay;
}
public int GetSearchInputDelaySetting()
{
return _settings.SearchInputDelay;
}
}
}

View File

@ -61,6 +61,44 @@ namespace Wox.Infrastructure.UserSettings
}
}
private bool _searchQueryResultsWithDelay = true;
public bool SearchQueryResultsWithDelay
{
get
{
return _searchQueryResultsWithDelay;
}
set
{
if (_searchQueryResultsWithDelay != value)
{
_searchQueryResultsWithDelay = value;
OnPropertyChanged(nameof(SearchQueryResultsWithDelay));
}
}
}
private int _searchInputDelay = 150;
public int SearchInputDelay
{
get
{
return _searchInputDelay;
}
set
{
if (_searchInputDelay != value)
{
_searchInputDelay = value;
OnPropertyChanged(nameof(SearchInputDelay));
}
}
}
public string Language { get; set; } = "en";
public Theme Theme { get; set; } = Theme.System;

View File

@ -51,6 +51,12 @@ namespace Microsoft.PowerToys.Settings.UI.Library
[JsonPropertyName("use_centralized_keyboard_hook")]
public bool UseCentralizedKeyboardHook { get; set; }
[JsonPropertyName("search_query_results_with_delay")]
public bool SearchQueryResultsWithDelay { get; set; }
[JsonPropertyName("search_input_delay")]
public int SearchInputDelay { get; set; }
public PowerLauncherProperties()
{
OpenPowerLauncher = new HotkeySettings(false, false, true, false, 32);
@ -65,6 +71,8 @@ namespace Microsoft.PowerToys.Settings.UI.Library
Theme = Theme.System;
Position = StartupPosition.Cursor;
UseCentralizedKeyboardHook = false;
SearchQueryResultsWithDelay = true;
SearchInputDelay = 150;
}
}
}

View File

@ -296,6 +296,40 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
}
}
public bool SearchQueryResultsWithDelay
{
get
{
return settings.Properties.SearchQueryResultsWithDelay;
}
set
{
if (settings.Properties.SearchQueryResultsWithDelay != value)
{
settings.Properties.SearchQueryResultsWithDelay = value;
UpdateSettings();
}
}
}
public int SearchInputDelay
{
get
{
return settings.Properties.SearchInputDelay;
}
set
{
if (settings.Properties.SearchInputDelay != value)
{
settings.Properties.SearchInputDelay = value;
UpdateSettings();
}
}
}
public HotkeySettings OpenFileLocation
{
get

View File

@ -414,6 +414,17 @@
<data name="PowerLauncher_ClearInputOnLaunch.Content" xml:space="preserve">
<value>Clear the previous query on launch</value>
</data>
<data name="PowerLauncher_SearchQueryResultsWithDelay.Header" xml:space="preserve">
<value>Delay search</value>
<comment>This is about adding a delay to wait for more input before executing a search</comment>
</data>
<data name="PowerLauncher_SearchQueryResultsWithDelay.Description" xml:space="preserve">
<value>Add a delay to wait for more input before executing a search</value>
</data>
<data name="PowerLauncher_SearchInputDelayMs.Header" xml:space="preserve">
<value>Search delay (ms)</value>
<comment>ms = milliseconds</comment>
</data>
<data name="KeyboardManager_KeysMappingLayoutRightHeader.Text" xml:space="preserve">
<value>To:</value>
<comment>Keyboard Manager mapping keys view right header</comment>

View File

@ -94,6 +94,29 @@
<controls:SettingsGroup x:Uid="PowerLauncher_SearchResults" IsEnabled="{x:Bind Mode=OneWay, Path=ViewModel.EnablePowerLauncher}">
<controls:SettingExpander IsExpanded="True">
<controls:SettingExpander.Header>
<controls:Setting x:Uid="PowerLauncher_SearchQueryResultsWithDelay" Icon="&#xF182;" Style="{StaticResource ExpanderHeaderSettingStyle}" >
<controls:Setting.ActionContent>
<ToggleSwitch IsOn="{x:Bind Mode=TwoWay, Path=ViewModel.SearchQueryResultsWithDelay}"/>
</controls:Setting.ActionContent>
</controls:Setting>
</controls:SettingExpander.Header>
<controls:SettingExpander.Content>
<controls:Setting x:Uid="PowerLauncher_SearchInputDelayMs" IsEnabled="{x:Bind Mode=OneWay, Path=ViewModel.SearchQueryResultsWithDelay}" Style="{StaticResource ExpanderContentSettingStyle}">
<controls:Setting.ActionContent>
<muxc:NumberBox Minimum="0"
Maximum="1000"
Value="{x:Bind Mode=TwoWay, Path=ViewModel.SearchInputDelay}"
MinWidth="{StaticResource SettingActionControlMinWidth}"
SpinButtonPlacementMode="Compact"
HorizontalAlignment="Left"
SmallChange="10"
LargeChange="50"/>
</controls:Setting.ActionContent>
</controls:Setting>
</controls:SettingExpander.Content>
</controls:SettingExpander>
<controls:SettingExpander IsExpanded="True">
<controls:SettingExpander.Header>
<controls:Setting x:Uid="PowerLauncher_MaximumNumberOfResults" Icon="&#xE721;" Style="{StaticResource ExpanderHeaderSettingStyle}">