mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-12-05 04:39:08 +08:00
Fixing gap in logic where query was triggering when programatically setting text.
Updating the binding and settext both will trigger the TextChanged event on a seperate event dispatcher. For this reason we dynamically detect which eventhandler is most approapriate on the textchanging event.
This commit is contained in:
parent
15b7b20500
commit
aa79325d76
@ -375,7 +375,6 @@
|
||||
x:FieldModifier="public"
|
||||
Style="{StaticResource CustomAutoSuggestBoxTextBoxStyle}"
|
||||
PlaceholderText="Start typing"
|
||||
Text="{Binding QueryText}"
|
||||
Height="60"
|
||||
ScrollViewer.BringIntoViewOnFocusChange="False"
|
||||
Canvas.ZIndex="0"
|
||||
|
@ -22,6 +22,7 @@ using System.Threading.Tasks;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Core;
|
||||
using System.Windows.Media;
|
||||
using Windows.UI.Xaml.Data;
|
||||
|
||||
namespace PowerLauncher
|
||||
{
|
||||
@ -33,11 +34,10 @@ namespace PowerLauncher
|
||||
private readonly Storyboard _progressBarStoryboard = new Storyboard();
|
||||
private Settings _settings;
|
||||
private MainViewModel _viewModel;
|
||||
|
||||
private bool _isTextSetProgramatically;
|
||||
const int ROW_COUNT = 4;
|
||||
const int ROW_HEIGHT = 75;
|
||||
const int MAX_LIST_HEIGHT = 300;
|
||||
|
||||
#endregion
|
||||
|
||||
public MainWindow(Settings settings, MainViewModel mainVM)
|
||||
@ -60,6 +60,7 @@ namespace PowerLauncher
|
||||
|
||||
private void OnInitialized(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void OnLoaded(object sender, System.Windows.RoutedEventArgs _)
|
||||
@ -153,7 +154,7 @@ namespace PowerLauncher
|
||||
_launcher = (PowerLauncher.UI.LauncherControl)host.Child;
|
||||
_launcher.DataContext = _viewModel;
|
||||
_launcher.KeyDown += _launcher_KeyDown;
|
||||
_launcher.TextBox.TextChanged += QueryTextBox_TextChanged;
|
||||
_launcher.TextBox.TextChanging += QueryTextBox_TextChanging;
|
||||
_launcher.TextBox.Loaded += TextBox_Loaded;
|
||||
_launcher.PropertyChanged += UserControl_PropertyChanged;
|
||||
_viewModel.PropertyChanged += (o, e) =>
|
||||
@ -177,9 +178,16 @@ namespace PowerLauncher
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(e.PropertyName == nameof(MainViewModel.SystemQueryText))
|
||||
{
|
||||
this._isTextSetProgramatically = true;
|
||||
_launcher.TextBox.Text = _viewModel.SystemQueryText;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void UserControl_PropertyChanged(object sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName == "SolidBorderBrush")
|
||||
@ -347,8 +355,36 @@ namespace PowerLauncher
|
||||
return String.Empty;
|
||||
}
|
||||
|
||||
private void QueryTextBox_TextChanging(TextBox sender, TextBoxTextChangingEventArgs args)
|
||||
{
|
||||
ClearAllQueryTextChangedHanlders();
|
||||
|
||||
private void QueryTextBox_TextChanged(object sender, Windows.UI.Xaml.Controls.TextChangedEventArgs e)
|
||||
if(this._isTextSetProgramatically)
|
||||
{
|
||||
this._launcher.TextBox.TextChanged += QueryTextBox_TextChangedProgramatically;
|
||||
}
|
||||
else
|
||||
{
|
||||
this._launcher.TextBox.TextChanged += QueryTextBox_TextChangedByUserInput;
|
||||
}
|
||||
}
|
||||
|
||||
private void ClearAllQueryTextChangedHanlders()
|
||||
{
|
||||
this._launcher.TextBox.TextChanged -= QueryTextBox_TextChangedProgramatically;
|
||||
this._launcher.TextBox.TextChanged -= QueryTextBox_TextChangedByUserInput;
|
||||
}
|
||||
|
||||
private void QueryTextBox_TextChangedProgramatically(object sender, Windows.UI.Xaml.Controls.TextChangedEventArgs e)
|
||||
{
|
||||
var textBox = ((Windows.UI.Xaml.Controls.TextBox)sender);
|
||||
textBox.SelectionStart = textBox.Text.Length;
|
||||
|
||||
this._isTextSetProgramatically = false;
|
||||
}
|
||||
|
||||
|
||||
private void QueryTextBox_TextChangedByUserInput(object sender, Windows.UI.Xaml.Controls.TextChangedEventArgs e)
|
||||
{
|
||||
var text = ((Windows.UI.Xaml.Controls.TextBox)sender).Text;
|
||||
//To clear the auto-suggest immediately instead of waiting for selection changed
|
||||
@ -357,20 +393,12 @@ namespace PowerLauncher
|
||||
_launcher.AutoCompleteTextBox.PlaceholderText = String.Empty;
|
||||
}
|
||||
|
||||
if (_viewModel.QueryTextUpdateBySystem)
|
||||
{
|
||||
_launcher.TextBox.SelectionStart = _launcher.TextBox.Text.Length;
|
||||
_viewModel.QueryTextUpdateBySystem = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
_viewModel.QueryText = text;
|
||||
var latestTimeOfTyping = DateTime.Now;
|
||||
|
||||
Task.Run(() => DelayedCheck(latestTimeOfTyping, text));
|
||||
s_lastTimeOfTyping = latestTimeOfTyping;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task DelayedCheck(DateTime latestTimeOfTyping, string text)
|
||||
{
|
||||
@ -384,7 +412,7 @@ namespace PowerLauncher
|
||||
}
|
||||
}
|
||||
|
||||
private void WindowsXamlHost_PreviewMouseDown(object sender, MouseButtonEventArgs e)
|
||||
private void WindowsXamlHost_PreviewMouseDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
// if (sender != null && e.OriginalSource != null)
|
||||
// {
|
||||
|
@ -236,16 +236,15 @@ namespace Wox.ViewModel
|
||||
/// <param name="requery">Optional Parameter that if true, will automatically execute a query against the updated text</param>
|
||||
public void ChangeQueryText(string queryText, bool requery=false)
|
||||
{
|
||||
QueryTextUpdateBySystem = true;
|
||||
QueryText = queryText;
|
||||
SystemQueryText = queryText;
|
||||
|
||||
if(requery)
|
||||
{
|
||||
QueryText = queryText;
|
||||
Query();
|
||||
}
|
||||
}
|
||||
public bool LastQuerySelected { get; set; }
|
||||
public bool QueryTextUpdateBySystem { get; set; }
|
||||
|
||||
private ResultsViewModel _selectedResults;
|
||||
private ResultsViewModel SelectedResults
|
||||
|
Loading…
Reference in New Issue
Block a user