Merge pull request #749 from onesounds/FixEmptyQuery

Fix empty query
This commit is contained in:
Kevin Zhang 2021-10-19 22:23:10 -05:00 committed by GitHub
commit e69b454139
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 87 additions and 48 deletions

View file

@ -6,6 +6,8 @@ using NHotkey.Wpf;
using Flow.Launcher.Core.Resource;
using System.Windows;
using Flow.Launcher.ViewModel;
using System.Threading.Tasks;
using System.Threading;
namespace Flow.Launcher.Helper
{
@ -19,10 +21,15 @@ namespace Flow.Launcher.Helper
mainViewModel = mainVM;
settings = mainViewModel._settings;
SetHotkey(settings.Hotkey, OnHotkey);
SetHotkey(settings.Hotkey, OnToggleHotkey);
LoadCustomPluginHotkey();
}
internal static void OnToggleHotkey(object sender, HotkeyEventArgs args)
{
mainViewModel.ToggleFlowLauncher();
}
private static void SetHotkey(string hotkeyStr, EventHandler<HotkeyEventArgs> action)
{
var hotkey = new HotkeyModel(hotkeyStr);
@ -53,44 +60,6 @@ namespace Flow.Launcher.Helper
}
}
internal static void OnHotkey(object sender, HotkeyEventArgs e)
{
if (!ShouldIgnoreHotkeys())
{
UpdateLastQUeryMode();
mainViewModel.ToggleFlowLauncher();
e.Handled = true;
}
}
/// <summary>
/// Checks if Flow Launcher should ignore any hotkeys
/// </summary>
private static bool ShouldIgnoreHotkeys()
{
return settings.IgnoreHotkeysOnFullscreen && WindowsInteropHelper.IsWindowFullscreen();
}
private static void UpdateLastQUeryMode()
{
switch(settings.LastQueryMode)
{
case LastQueryMode.Empty:
mainViewModel.ChangeQueryText(string.Empty);
break;
case LastQueryMode.Preserved:
mainViewModel.LastQuerySelected = true;
break;
case LastQueryMode.Selected:
mainViewModel.LastQuerySelected = false;
break;
default:
throw new ArgumentException($"wrong LastQueryMode: <{settings.LastQueryMode}>");
}
}
internal static void LoadCustomPluginHotkey()
{
if (settings.CustomPluginHotkeys == null)
@ -106,7 +75,7 @@ namespace Flow.Launcher.Helper
{
SetHotkey(hotkey.Hotkey, (s, e) =>
{
if (ShouldIgnoreHotkeys())
if (mainViewModel.ShouldIgnoreHotkeys())
return;
mainViewModel.MainWindowVisibility = Visibility.Visible;

View file

@ -262,7 +262,7 @@ namespace Flow.Launcher
{
if (_settings.HideWhenDeactive)
{
Hide();
_viewModel.Hide();
}
}

View file

@ -23,6 +23,7 @@ namespace Flow.Launcher
public readonly IPublicAPI API;
private Settings settings;
private SettingWindowViewModel viewModel;
private static MainViewModel mainViewModel;
public SettingWindow(IPublicAPI api, SettingWindowViewModel viewModel)
{
@ -126,7 +127,7 @@ namespace Flow.Launcher
if (HotkeyControl.CurrentHotkeyAvailable)
{
HotKeyMapper.SetHotkey(HotkeyControl.CurrentHotkey, HotKeyMapper.OnHotkey);
HotKeyMapper.SetHotkey(HotkeyControl.CurrentHotkey, HotKeyMapper.OnToggleHotkey);
HotKeyMapper.RemoveHotkey(settings.Hotkey);
settings.Hotkey = HotkeyControl.CurrentHotkey.ToString();
}

View file

@ -21,6 +21,8 @@ using Microsoft.VisualStudio.Threading;
using System.Threading.Channels;
using ISavable = Flow.Launcher.Plugin.ISavable;
using System.Windows.Threading;
using NHotkey;
namespace Flow.Launcher.ViewModel
{
@ -108,7 +110,9 @@ namespace Flow.Launcher.ViewModel
}
Log.Error("MainViewModel", "Unexpected ResultViewUpdate ends");
};
}
;
void continueAction(Task t)
{
@ -145,6 +149,24 @@ namespace Flow.Launcher.ViewModel
}
}
private void UpdateLastQUeryMode()
{
switch (_settings.LastQueryMode)
{
case LastQueryMode.Empty:
ChangeQueryText(string.Empty);
break;
case LastQueryMode.Preserved:
LastQuerySelected = true;
break;
case LastQueryMode.Selected:
LastQuerySelected = false;
break;
default:
throw new ArgumentException($"wrong LastQueryMode: <{_settings.LastQueryMode}>");
}
}
private void InitializeKeyCommands()
{
@ -156,7 +178,18 @@ namespace Flow.Launcher.ViewModel
}
else
{
MainWindowVisibility = Visibility.Collapsed;
Hide();
}
});
ClearQueryCommand = new RelayCommand(_ =>
{
if (!string.IsNullOrEmpty(QueryText))
{
ChangeQueryText(string.Empty);
// Push Event to UI SystemQuery has changed
//OnPropertyChanged(nameof(SystemQueryText));
}
});
@ -194,7 +227,7 @@ namespace Flow.Launcher.ViewModel
if (hideWindow)
{
MainWindowVisibility = Visibility.Collapsed;
Hide();
}
if (SelectedIsFromQueryResults())
@ -244,7 +277,7 @@ namespace Flow.Launcher.ViewModel
Owner = Application.Current.MainWindow
};
MainWindowVisibility = Visibility.Collapsed;
Hide();
PluginManager
.ReloadData()
@ -343,7 +376,6 @@ namespace Flow.Launcher.ViewModel
}
public Visibility ProgressBarVisibility { get; set; }
public Visibility MainWindowVisibility { get; set; }
public ICommand EscCommand { get; set; }
@ -357,6 +389,7 @@ namespace Flow.Launcher.ViewModel
public ICommand LoadHistoryCommand { get; set; }
public ICommand OpenResultCommand { get; set; }
public ICommand ReloadPluginDataCommand { get; set; }
public ICommand ClearQueryCommand { get; private set; }
public string OpenResultCommandModifiers { get; private set; }
@ -668,7 +701,7 @@ namespace Flow.Launcher.ViewModel
OpenResultCommandModifiers = _settings.OpenResultModifiers ?? DefaultOpenResultModifiers;
}
internal void ToggleFlowLauncher()
public async void ToggleFlowLauncher()
{
if (MainWindowVisibility != Visibility.Visible)
{
@ -676,12 +709,48 @@ namespace Flow.Launcher.ViewModel
}
else
{
switch (_settings.LastQueryMode)
{
case LastQueryMode.Empty:
ChangeQueryText(string.Empty);
Application.Current.MainWindow.Opacity = 0; // Trick for no delay
await Task.Delay(100);
Application.Current.MainWindow.Opacity = 1;
break;
case LastQueryMode.Preserved:
LastQuerySelected = true;
break;
case LastQueryMode.Selected:
LastQuerySelected = false;
break;
default:
throw new ArgumentException($"wrong LastQueryMode: <{_settings.LastQueryMode}>");
}
MainWindowVisibility = Visibility.Collapsed;
}
}
public void Hide()
{
if (MainWindowVisibility != Visibility.Collapsed)
{
ToggleFlowLauncher();
}
}
#endregion
/// <summary>
/// Checks if Flow Launcher should ignore any hotkeys
/// </summary>
public bool ShouldIgnoreHotkeys()
{
return _settings.IgnoreHotkeysOnFullscreen && WindowsInteropHelper.IsWindowFullscreen();
}
#region Public Methods
public void Save()