Skip to content
Merged
11 changes: 11 additions & 0 deletions Flow.Launcher/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
using Flow.Launcher.Plugin.SharedModels;
using Flow.Launcher.ViewModel;
using iNKORE.UI.WPF.Modern;
using iNKORE.UI.WPF.Modern.Controls;

Check warning on line 29 in Flow.Launcher/MainWindow.xaml.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`NKORE` is not a recognized word. (unrecognized-spelling)
using DataObject = System.Windows.DataObject;
using Key = System.Windows.Input.Key;
using MouseButtons = System.Windows.Forms.MouseButtons;
Expand Down Expand Up @@ -76,6 +76,9 @@
private const double DefaultRightMargin = 66; //* this value from base.xaml
private bool _isClockPanelAnimating = false;

// Search Delay
private bool _ignoreTextChange = false;

// IDisposable
private bool _disposed = false;

Expand Down Expand Up @@ -116,7 +119,7 @@
{
var handle = Win32Helper.GetWindowHandle(this, true);
_hwndSource = HwndSource.FromHwnd(handle);
_hwndSource.AddHook(WndProc);

Check warning on line 122 in Flow.Launcher/MainWindow.xaml.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`Wnd` is not a recognized word. (unrecognized-spelling)
Win32Helper.HideFromAltTab(this);
Win32Helper.DisableControlBox(this);
}
Expand Down Expand Up @@ -374,7 +377,7 @@
{
try
{
_hwndSource.RemoveHook(WndProc);

Check warning on line 380 in Flow.Launcher/MainWindow.xaml.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`Wnd` is not a recognized word. (unrecognized-spelling)
}
catch (Exception)
{
Expand Down Expand Up @@ -587,9 +590,9 @@

#endregion

#region Window WndProc

Check warning on line 593 in Flow.Launcher/MainWindow.xaml.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`Wnd` is not a recognized word. (unrecognized-spelling)

private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)

Check warning on line 595 in Flow.Launcher/MainWindow.xaml.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`Wnd` is not a recognized word. (unrecognized-spelling)
{
switch (msg)
{
Expand Down Expand Up @@ -813,17 +816,17 @@
Header = Localize.iconTrayOpen() + " (" + _settings.Hotkey + ")",
Icon = openIcon
};
var gamemodeIcon = new FontIcon { Glyph = "\ue7fc" };

Check warning on line 819 in Flow.Launcher/MainWindow.xaml.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`gamemode` is not a recognized word. (unrecognized-spelling)
var gamemode = new MenuItem

Check warning on line 820 in Flow.Launcher/MainWindow.xaml.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`gamemode` is not a recognized word. (unrecognized-spelling)
{
Header = Localize.GameMode(),
Icon = gamemodeIcon

Check warning on line 823 in Flow.Launcher/MainWindow.xaml.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`gamemode` is not a recognized word. (unrecognized-spelling)
};
var positionresetIcon = new FontIcon { Glyph = "\ue73f" };
var positionreset = new MenuItem

Check warning on line 826 in Flow.Launcher/MainWindow.xaml.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`positionreset` is not a recognized word. (unrecognized-spelling)
{
Header = Localize.PositionReset(),
Icon = positionresetIcon

Check warning on line 829 in Flow.Launcher/MainWindow.xaml.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`positionreset` is not a recognized word. (unrecognized-spelling)
};
var settingsIcon = new FontIcon { Glyph = "\ue713" };
var settings = new MenuItem
Expand Down Expand Up @@ -1421,11 +1424,19 @@

private void QueryTextBox_TextChanged1(object sender, TextChangedEventArgs e)
{
if (_ignoreTextChange) return;
var textBox = (TextBox)sender;
_viewModel.QueryText = textBox.Text;
_viewModel.Query(_settings.SearchQueryResultsWithDelay);
}

public void SetQueryTextBoxText(string text)
{
_ignoreTextChange = true;
QueryTextBox.Text = text;
_ignoreTextChange = false;
}

#endregion

#region Dialog Jump
Expand Down
27 changes: 24 additions & 3 deletions Flow.Launcher/ViewModel/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,14 @@ public void ChangeQueryText(string queryText, bool isReQuery = false)
if (QueryText != queryText)
{
// Change query text first
QueryText = queryText;
// We use private field and manually set QueryTextBox instead of QueryText setter
// so that QueryTextBox_TextChanged1 will not be invoked to avoid duplicated Query calls
_queryText = queryText;
if (Application.Current?.MainWindow is MainWindow mainWindow)
{
mainWindow.SetQueryTextBoxText(queryText);
}

// When we are changing query from codes, we should not delay the query
Query(false, isReQuery: false);

Expand Down Expand Up @@ -791,7 +798,14 @@ private async Task ChangeQueryTextAsync(string queryText, bool isReQuery = false
if (QueryText != queryText)
{
// Change query text first
QueryText = queryText;
// We use private field and manually set QueryTextBox instead of QueryText setter
// so that QueryTextBox_TextChanged1 will not be invoked to avoid duplicated Query calls
_queryText = queryText;
if (Application.Current?.MainWindow is MainWindow mainWindow)
{
mainWindow.SetQueryTextBoxText(queryText);
}

// When we are changing query from codes, we should not delay the query
await QueryAsync(false, isReQuery: false);

Expand Down Expand Up @@ -870,11 +884,18 @@ private ResultsViewModel SelectedResults
}
_queryTextBeforeLeaveResults = QueryText;

// We use private field and manually set QueryTextBox instead of QueryText setter
// so that QueryTextBox_TextChanged1 will not be invoked to avoid duplicated Query calls
_queryText = string.Empty;
if (Application.Current?.MainWindow is MainWindow mainWindow)
{
mainWindow.SetQueryTextBoxText(string.Empty);
}

// Because of Fody's optimization
// setter won't be called when property value is not changed.
// so we need manually call Query()
// http://stackoverflow.com/posts/25895769/revisions
QueryText = string.Empty;
// When we are changing query because selected results are changed to history or context menu,
// we should not delay the query
Query(false);
Expand Down
Loading