21
21
using System . Threading . Channels ;
22
22
using ISavable = Flow . Launcher . Plugin . ISavable ;
23
23
using System . Windows . Threading ;
24
+ using NHotkey ;
25
+
24
26
25
27
namespace Flow . Launcher . ViewModel
26
28
{
@@ -108,7 +110,9 @@ async Task updateAction()
108
110
}
109
111
110
112
Log . Error ( "MainViewModel" , "Unexpected ResultViewUpdate ends" ) ;
111
- } ;
113
+ }
114
+
115
+ ;
112
116
113
117
void continueAction ( Task t )
114
118
{
@@ -145,6 +149,24 @@ private void RegisterResultsUpdatedEvent()
145
149
}
146
150
}
147
151
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
+ }
148
170
149
171
private void InitializeKeyCommands ( )
150
172
{
@@ -156,7 +178,18 @@ private void InitializeKeyCommands()
156
178
}
157
179
else
158
180
{
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));
160
193
}
161
194
} ) ;
162
195
@@ -194,7 +227,7 @@ private void InitializeKeyCommands()
194
227
195
228
if ( hideWindow )
196
229
{
197
- MainWindowVisibility = Visibility . Collapsed ;
230
+ Hide ( ) ;
198
231
}
199
232
200
233
if ( SelectedIsFromQueryResults ( ) )
@@ -244,7 +277,7 @@ private void InitializeKeyCommands()
244
277
Owner = Application . Current . MainWindow
245
278
} ;
246
279
247
- MainWindowVisibility = Visibility . Collapsed ;
280
+ Hide ( ) ;
248
281
249
282
PluginManager
250
283
. ReloadData ( )
@@ -343,7 +376,6 @@ private ResultsViewModel SelectedResults
343
376
}
344
377
345
378
public Visibility ProgressBarVisibility { get ; set ; }
346
-
347
379
public Visibility MainWindowVisibility { get ; set ; }
348
380
349
381
public ICommand EscCommand { get ; set ; }
@@ -357,6 +389,7 @@ private ResultsViewModel SelectedResults
357
389
public ICommand LoadHistoryCommand { get ; set ; }
358
390
public ICommand OpenResultCommand { get ; set ; }
359
391
public ICommand ReloadPluginDataCommand { get ; set ; }
392
+ public ICommand ClearQueryCommand { get ; private set ; }
360
393
361
394
public string OpenResultCommandModifiers { get ; private set ; }
362
395
@@ -668,20 +701,56 @@ private void SetOpenResultModifiers()
668
701
OpenResultCommandModifiers = _settings . OpenResultModifiers ?? DefaultOpenResultModifiers ;
669
702
}
670
703
671
- internal void ToggleFlowLauncher ( )
704
+ public async void ToggleFlowLauncher ( )
672
705
{
673
706
if ( MainWindowVisibility != Visibility . Visible )
674
707
{
675
708
MainWindowVisibility = Visibility . Visible ;
676
709
}
677
710
else
678
711
{
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
+ }
679
729
MainWindowVisibility = Visibility . Collapsed ;
680
730
}
681
731
}
682
732
733
+ public void Hide ( )
734
+ {
735
+ if ( MainWindowVisibility != Visibility . Collapsed )
736
+ {
737
+ ToggleFlowLauncher ( ) ;
738
+ }
739
+ }
740
+
683
741
#endregion
684
742
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
+
685
754
#region Public Methods
686
755
687
756
public void Save ( )
0 commit comments