Skip to content

Commit e69b454

Browse files
authored
Merge pull request #749 from onesounds/FixEmptyQuery
Fix empty query
2 parents f6f306e + 9a53015 commit e69b454

File tree

4 files changed

+87
-48
lines changed

4 files changed

+87
-48
lines changed

Flow.Launcher/Helper/HotKeyMapper.cs

Lines changed: 9 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
using Flow.Launcher.Core.Resource;
77
using System.Windows;
88
using Flow.Launcher.ViewModel;
9+
using System.Threading.Tasks;
10+
using System.Threading;
911

1012
namespace Flow.Launcher.Helper
1113
{
@@ -19,10 +21,15 @@ internal static void Initialize(MainViewModel mainVM)
1921
mainViewModel = mainVM;
2022
settings = mainViewModel._settings;
2123

22-
SetHotkey(settings.Hotkey, OnHotkey);
24+
SetHotkey(settings.Hotkey, OnToggleHotkey);
2325
LoadCustomPluginHotkey();
2426
}
2527

28+
internal static void OnToggleHotkey(object sender, HotkeyEventArgs args)
29+
{
30+
mainViewModel.ToggleFlowLauncher();
31+
}
32+
2633
private static void SetHotkey(string hotkeyStr, EventHandler<HotkeyEventArgs> action)
2734
{
2835
var hotkey = new HotkeyModel(hotkeyStr);
@@ -53,44 +60,6 @@ internal static void RemoveHotkey(string hotkeyStr)
5360
}
5461
}
5562

56-
internal static void OnHotkey(object sender, HotkeyEventArgs e)
57-
{
58-
if (!ShouldIgnoreHotkeys())
59-
{
60-
UpdateLastQUeryMode();
61-
62-
mainViewModel.ToggleFlowLauncher();
63-
e.Handled = true;
64-
}
65-
}
66-
67-
/// <summary>
68-
/// Checks if Flow Launcher should ignore any hotkeys
69-
/// </summary>
70-
private static bool ShouldIgnoreHotkeys()
71-
{
72-
return settings.IgnoreHotkeysOnFullscreen && WindowsInteropHelper.IsWindowFullscreen();
73-
}
74-
75-
private static void UpdateLastQUeryMode()
76-
{
77-
switch(settings.LastQueryMode)
78-
{
79-
case LastQueryMode.Empty:
80-
mainViewModel.ChangeQueryText(string.Empty);
81-
break;
82-
case LastQueryMode.Preserved:
83-
mainViewModel.LastQuerySelected = true;
84-
break;
85-
case LastQueryMode.Selected:
86-
mainViewModel.LastQuerySelected = false;
87-
break;
88-
default:
89-
throw new ArgumentException($"wrong LastQueryMode: <{settings.LastQueryMode}>");
90-
91-
}
92-
}
93-
9463
internal static void LoadCustomPluginHotkey()
9564
{
9665
if (settings.CustomPluginHotkeys == null)
@@ -106,7 +75,7 @@ internal static void SetCustomQueryHotkey(CustomPluginHotkey hotkey)
10675
{
10776
SetHotkey(hotkey.Hotkey, (s, e) =>
10877
{
109-
if (ShouldIgnoreHotkeys())
78+
if (mainViewModel.ShouldIgnoreHotkeys())
11079
return;
11180

11281
mainViewModel.MainWindowVisibility = Visibility.Visible;

Flow.Launcher/MainWindow.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ private void OnDeactivated(object sender, EventArgs e)
262262
{
263263
if (_settings.HideWhenDeactive)
264264
{
265-
Hide();
265+
_viewModel.Hide();
266266
}
267267
}
268268

Flow.Launcher/SettingWindow.xaml.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public partial class SettingWindow
2323
public readonly IPublicAPI API;
2424
private Settings settings;
2525
private SettingWindowViewModel viewModel;
26+
private static MainViewModel mainViewModel;
2627

2728
public SettingWindow(IPublicAPI api, SettingWindowViewModel viewModel)
2829
{
@@ -126,7 +127,7 @@ void OnHotkeyChanged(object sender, EventArgs e)
126127
if (HotkeyControl.CurrentHotkeyAvailable)
127128
{
128129

129-
HotKeyMapper.SetHotkey(HotkeyControl.CurrentHotkey, HotKeyMapper.OnHotkey);
130+
HotKeyMapper.SetHotkey(HotkeyControl.CurrentHotkey, HotKeyMapper.OnToggleHotkey);
130131
HotKeyMapper.RemoveHotkey(settings.Hotkey);
131132
settings.Hotkey = HotkeyControl.CurrentHotkey.ToString();
132133
}

Flow.Launcher/ViewModel/MainViewModel.cs

Lines changed: 75 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
using System.Threading.Channels;
2222
using ISavable = Flow.Launcher.Plugin.ISavable;
2323
using System.Windows.Threading;
24+
using NHotkey;
25+
2426

2527
namespace Flow.Launcher.ViewModel
2628
{
@@ -108,7 +110,9 @@ async Task updateAction()
108110
}
109111

110112
Log.Error("MainViewModel", "Unexpected ResultViewUpdate ends");
111-
};
113+
}
114+
115+
;
112116

113117
void continueAction(Task t)
114118
{
@@ -145,6 +149,24 @@ private void RegisterResultsUpdatedEvent()
145149
}
146150
}
147151

152+
private void UpdateLastQUeryMode()
153+
{
154+
switch (_settings.LastQueryMode)
155+
{
156+
case LastQueryMode.Empty:
157+
ChangeQueryText(string.Empty);
158+
break;
159+
case LastQueryMode.Preserved:
160+
LastQuerySelected = true;
161+
break;
162+
case LastQueryMode.Selected:
163+
LastQuerySelected = false;
164+
break;
165+
default:
166+
throw new ArgumentException($"wrong LastQueryMode: <{_settings.LastQueryMode}>");
167+
168+
}
169+
}
148170

149171
private void InitializeKeyCommands()
150172
{
@@ -156,7 +178,18 @@ private void InitializeKeyCommands()
156178
}
157179
else
158180
{
159-
MainWindowVisibility = Visibility.Collapsed;
181+
Hide();
182+
}
183+
});
184+
185+
ClearQueryCommand = new RelayCommand(_ =>
186+
{
187+
if (!string.IsNullOrEmpty(QueryText))
188+
{
189+
ChangeQueryText(string.Empty);
190+
191+
// Push Event to UI SystemQuery has changed
192+
//OnPropertyChanged(nameof(SystemQueryText));
160193
}
161194
});
162195

@@ -194,7 +227,7 @@ private void InitializeKeyCommands()
194227

195228
if (hideWindow)
196229
{
197-
MainWindowVisibility = Visibility.Collapsed;
230+
Hide();
198231
}
199232

200233
if (SelectedIsFromQueryResults())
@@ -244,7 +277,7 @@ private void InitializeKeyCommands()
244277
Owner = Application.Current.MainWindow
245278
};
246279

247-
MainWindowVisibility = Visibility.Collapsed;
280+
Hide();
248281

249282
PluginManager
250283
.ReloadData()
@@ -343,7 +376,6 @@ private ResultsViewModel SelectedResults
343376
}
344377

345378
public Visibility ProgressBarVisibility { get; set; }
346-
347379
public Visibility MainWindowVisibility { get; set; }
348380

349381
public ICommand EscCommand { get; set; }
@@ -357,6 +389,7 @@ private ResultsViewModel SelectedResults
357389
public ICommand LoadHistoryCommand { get; set; }
358390
public ICommand OpenResultCommand { get; set; }
359391
public ICommand ReloadPluginDataCommand { get; set; }
392+
public ICommand ClearQueryCommand { get; private set; }
360393

361394
public string OpenResultCommandModifiers { get; private set; }
362395

@@ -668,20 +701,56 @@ private void SetOpenResultModifiers()
668701
OpenResultCommandModifiers = _settings.OpenResultModifiers ?? DefaultOpenResultModifiers;
669702
}
670703

671-
internal void ToggleFlowLauncher()
704+
public async void ToggleFlowLauncher()
672705
{
673706
if (MainWindowVisibility != Visibility.Visible)
674707
{
675708
MainWindowVisibility = Visibility.Visible;
676709
}
677710
else
678711
{
712+
switch (_settings.LastQueryMode)
713+
{
714+
case LastQueryMode.Empty:
715+
ChangeQueryText(string.Empty);
716+
Application.Current.MainWindow.Opacity = 0; // Trick for no delay
717+
await Task.Delay(100);
718+
Application.Current.MainWindow.Opacity = 1;
719+
break;
720+
case LastQueryMode.Preserved:
721+
LastQuerySelected = true;
722+
break;
723+
case LastQueryMode.Selected:
724+
LastQuerySelected = false;
725+
break;
726+
default:
727+
throw new ArgumentException($"wrong LastQueryMode: <{_settings.LastQueryMode}>");
728+
}
679729
MainWindowVisibility = Visibility.Collapsed;
680730
}
681731
}
682732

733+
public void Hide()
734+
{
735+
if (MainWindowVisibility != Visibility.Collapsed)
736+
{
737+
ToggleFlowLauncher();
738+
}
739+
}
740+
683741
#endregion
684742

743+
744+
/// <summary>
745+
/// Checks if Flow Launcher should ignore any hotkeys
746+
/// </summary>
747+
public bool ShouldIgnoreHotkeys()
748+
{
749+
return _settings.IgnoreHotkeysOnFullscreen && WindowsInteropHelper.IsWindowFullscreen();
750+
}
751+
752+
753+
685754
#region Public Methods
686755

687756
public void Save()

0 commit comments

Comments
 (0)