@@ -176,10 +176,18 @@ private void InitializeKeyCommands()
176176 }
177177 else
178178 {
179- UpdateLastQUeryMode ( ) ;
180- var overlayTask = Task . Delay ( 50 ) . ContinueWith ( _ => {
181- MainWindowVisibility = Visibility . Collapsed ;
182- } ) ;
179+ Hide ( ) ;
180+ }
181+ } ) ;
182+
183+ ClearQueryCommand = new RelayCommand ( _ =>
184+ {
185+ if ( ! string . IsNullOrEmpty ( QueryText ) )
186+ {
187+ ChangeQueryText ( string . Empty ) ;
188+
189+ // Push Event to UI SystemQuery has changed
190+ //OnPropertyChanged(nameof(SystemQueryText));
183191 }
184192 } ) ;
185193
@@ -217,7 +225,8 @@ private void InitializeKeyCommands()
217225
218226 if ( hideWindow )
219227 {
220- MainWindowVisibility = Visibility . Collapsed ;
228+ //MainWindowVisibility = Visibility.Collapsed;
229+ Hide ( ) ;
221230 }
222231
223232 if ( SelectedIsFromQueryResults ( ) )
@@ -267,7 +276,8 @@ private void InitializeKeyCommands()
267276 Owner = Application . Current . MainWindow
268277 } ;
269278
270- MainWindowVisibility = Visibility . Collapsed ;
279+ //MainWindowVisibility = Visibility.Collapsed;
280+ Hide ( ) ;
271281
272282 PluginManager
273283 . ReloadData ( )
@@ -372,6 +382,7 @@ private ResultsViewModel SelectedResults
372382 public ICommand LoadHistoryCommand { get ; set ; }
373383 public ICommand OpenResultCommand { get ; set ; }
374384 public ICommand ReloadPluginDataCommand { get ; set ; }
385+ public ICommand ClearQueryCommand { get ; private set ; }
375386
376387 public string OpenResultCommandModifiers { get ; private set ; }
377388
@@ -683,20 +694,83 @@ private void SetOpenResultModifiers()
683694 OpenResultCommandModifiers = _settings . OpenResultModifiers ?? DefaultOpenResultModifiers ;
684695 }
685696
686- internal void ToggleFlowLauncher ( )
697+ public void ToggleFlowLauncher ( )
687698 {
688699 if ( MainWindowVisibility != Visibility . Visible )
689700 {
690701 MainWindowVisibility = Visibility . Visible ;
691702 }
692703 else
693704 {
694- MainWindowVisibility = Visibility . Collapsed ;
705+ if ( _settings . LastQueryMode == LastQueryMode . Empty )
706+ {
707+ Application . Current . MainWindow . Opacity = 0 ; // Trick for no delay
708+ ClearQueryCommand . Execute ( null ) ;
709+ Task . Run ( ( ) =>
710+ {
711+ Thread . Sleep ( 100 ) ;
712+ Application . Current . Dispatcher . BeginInvoke ( DispatcherPriority . Normal , new Action ( ( ) =>
713+ {
714+ MainWindowVisibility = Visibility . Collapsed ;
715+ Application . Current . MainWindow . Opacity = 1 ;
716+ } ) ) ;
717+ } ) ;
718+ }
719+ else
720+ {
721+
722+ MainWindowVisibility = Visibility . Collapsed ;
723+ }
724+ }
725+ }
726+
727+ public void Hide ( )
728+ {
729+ if ( MainWindowVisibility != Visibility . Collapsed )
730+ {
731+ ToggleFlowLauncher ( ) ;
695732 }
696733 }
697734
698735 #endregion
699736
737+ public void OnHotkey ( )
738+ {
739+ if ( ! ShouldIgnoreHotkeys ( ) )
740+ {
741+
742+ if ( _settings . LastQueryMode == LastQueryMode . Empty )
743+ {
744+ ChangeQueryText ( string . Empty ) ;
745+ }
746+ else if ( _settings . LastQueryMode == LastQueryMode . Preserved )
747+ {
748+ LastQuerySelected = true ;
749+ }
750+ else if ( _settings . LastQueryMode == LastQueryMode . Selected )
751+ {
752+ LastQuerySelected = false ;
753+ }
754+ else
755+ {
756+ throw new ArgumentException ( $ "wrong LastQueryMode: <{ _settings . LastQueryMode } >") ;
757+ }
758+
759+ ToggleFlowLauncher ( ) ;
760+ }
761+ }
762+
763+
764+ /// <summary>
765+ /// Checks if Flow Launcher should ignore any hotkeys
766+ /// </summary>
767+ private bool ShouldIgnoreHotkeys ( )
768+ {
769+ return _settings . IgnoreHotkeysOnFullscreen && WindowsInteropHelper . IsWindowFullscreen ( ) ;
770+ }
771+
772+
773+
700774 #region Public Methods
701775
702776 public void Save ( )
0 commit comments