@@ -77,7 +77,6 @@ public MainViewModel(Settings settings)
77
77
_userSelectedRecord = _userSelectedRecordStorage . Load ( ) ;
78
78
_topMostRecord = _topMostRecordStorage . Load ( ) ;
79
79
80
- InitializeKeyCommands ( ) ;
81
80
82
81
ContextMenu = new ResultsViewModel ( Settings )
83
82
{
@@ -167,160 +166,164 @@ private void RegisterResultsUpdatedEvent()
167
166
}
168
167
}
169
168
169
+ [ RelayCommand ]
170
+ private async Task ReloadPluginDataAsync ( )
171
+ {
172
+ Hide ( ) ;
170
173
171
-
172
- private void InitializeKeyCommands ( )
174
+ await PluginManager . ReloadDataAsync ( ) . ConfigureAwait ( false ) ;
175
+ Notification . Show ( InternationalizationManager . Instance . GetTranslation ( "success" ) , InternationalizationManager . Instance . GetTranslation ( "completedSuccessfully" ) ) ;
176
+ }
177
+ [ RelayCommand ]
178
+ private void LoadHistory ( )
173
179
{
174
- EscCommand = new RelayCommand ( _ =>
180
+ if ( SelectedIsFromQueryResults ( ) )
175
181
{
176
- if ( ! SelectedIsFromQueryResults ( ) )
177
- {
178
- SelectedResults = Results ;
179
- }
180
- else
181
- {
182
- Hide ( ) ;
183
- }
184
- } ) ;
185
-
186
- ClearQueryCommand = new RelayCommand ( _ =>
182
+ SelectedResults = History ;
183
+ History . SelectedIndex = _history . Items . Count - 1 ;
184
+ }
185
+ else
187
186
{
188
- if ( ! string . IsNullOrEmpty ( QueryText ) )
189
- {
190
- ChangeQueryText ( string . Empty ) ;
191
-
192
- // Push Event to UI SystemQuery has changed
193
- //OnPropertyChanged(nameof(SystemQueryText));
194
- }
195
- } ) ;
196
-
197
- SelectNextItemCommand = new RelayCommand ( _ => { SelectedResults . SelectNextResult ( ) ; } ) ;
198
-
199
- SelectPrevItemCommand = new RelayCommand ( _ => { SelectedResults . SelectPrevResult ( ) ; } ) ;
200
-
201
- SelectNextPageCommand = new RelayCommand ( _ => { SelectedResults . SelectNextPage ( ) ; } ) ;
187
+ SelectedResults = Results ;
188
+ }
189
+ }
190
+ [ RelayCommand ]
191
+ private void LoadContextMenu ( )
192
+ {
193
+ if ( SelectedIsFromQueryResults ( ) )
194
+ {
195
+ // When switch to ContextMenu from QueryResults, but no item being chosen, should do nothing
196
+ // i.e. Shift+Enter/Ctrl+O right after Alt + Space should do nothing
197
+ if ( SelectedResults . SelectedItem != null )
198
+ SelectedResults = ContextMenu ;
199
+ }
200
+ else
201
+ {
202
+ SelectedResults = Results ;
203
+ }
204
+ }
205
+ [ RelayCommand ]
206
+ private void Backspace ( object index )
207
+ {
208
+ var query = QueryBuilder . Build ( QueryText . Trim ( ) , PluginManager . NonGlobalPlugins ) ;
202
209
203
- SelectPrevPageCommand = new RelayCommand ( _ => { SelectedResults . SelectPrevPage ( ) ; } ) ;
210
+ // GetPreviousExistingDirectory does not require trailing '\', otherwise will return empty string
211
+ var path = FilesFolders . GetPreviousExistingDirectory ( ( _ ) => true , query . Search . TrimEnd ( '\\ ' ) ) ;
204
212
205
- SelectFirstResultCommand = new RelayCommand ( _ => SelectedResults . SelectFirstResult ( ) ) ;
213
+ var actionKeyword = string . IsNullOrEmpty ( query . ActionKeyword ) ? string . Empty : $ " { query . ActionKeyword } " ;
206
214
207
- StartHelpCommand = new RelayCommand ( _ =>
208
- {
209
- PluginManager . API . OpenUrl ( "https://github.com/Flow-Launcher/Flow.Launcher/wiki/Flow-Launcher/" ) ;
210
- } ) ;
211
- OpenSettingCommand = new RelayCommand ( _ => { App . API . OpenSettingDialog ( ) ; } ) ;
212
- OpenResultCommand = new AsyncRelayCommand ( async _ =>
215
+ ChangeQueryText ( $ "{ actionKeyword } { path } ") ;
216
+ }
217
+ [ RelayCommand ]
218
+ private void AutocompleteQuery ( )
219
+ {
220
+ var result = SelectedResults . SelectedItem ? . Result ;
221
+ if ( result != null && SelectedIsFromQueryResults ( ) ) // SelectedItem returns null if selection is empty.
213
222
{
214
- var results = SelectedResults ;
223
+ var autoCompleteText = result . Title ;
215
224
216
- var result = results . SelectedItem ? . Result ;
217
- if ( result == null )
225
+ if ( ! string . IsNullOrEmpty ( result . AutoCompleteText ) )
218
226
{
219
- return ;
227
+ autoCompleteText = result . AutoCompleteText ;
220
228
}
221
- var hideWindow = await result . ExecuteAsync ( new ActionContext
222
- {
223
- SpecialKeyState = GlobalHotkey . CheckModifiers ( )
224
- } ) . ConfigureAwait ( false ) ;
225
-
226
- if ( hideWindow )
229
+ else if ( ! string . IsNullOrEmpty ( SelectedResults . SelectedItem ? . QuerySuggestionText ) )
227
230
{
228
- Hide ( ) ;
231
+ autoCompleteText = SelectedResults . SelectedItem . QuerySuggestionText ;
229
232
}
230
233
231
- if ( SelectedIsFromQueryResults ( ) )
234
+ var specialKeyState = GlobalHotkey . CheckModifiers ( ) ;
235
+ if ( specialKeyState . ShiftPressed )
232
236
{
233
- _userSelectedRecord . Add ( result ) ;
234
- _history . Add ( result . OriginQuery . RawQuery ) ;
237
+ autoCompleteText = result . SubTitle ;
235
238
}
236
- else
237
- {
238
- SelectedResults = Results ;
239
- }
240
- } ) ;
241
239
242
- AutocompleteQueryCommand = new RelayCommand ( _ =>
240
+ ChangeQueryText ( autoCompleteText ) ;
241
+ }
242
+ }
243
+ [ RelayCommand ]
244
+ private async Task OpenResultAsync ( string index )
245
+ {
246
+ var results = SelectedResults ;
247
+ if ( index is not null )
248
+ {
249
+ results . SelectedIndex = int . Parse ( index ) ;
250
+ }
251
+ var result = results . SelectedItem ? . Result ;
252
+ if ( result == null )
243
253
{
244
- var result = SelectedResults . SelectedItem ? . Result ;
245
- if ( result != null && SelectedIsFromQueryResults ( ) ) // SelectedItem returns null if selection is empty.
254
+ return ;
255
+ }
256
+ var hideWindow = await result . ExecuteAsync ( new ActionContext
246
257
{
247
- var autoCompleteText = result . Title ;
248
-
249
- if ( ! string . IsNullOrEmpty ( result . AutoCompleteText ) )
250
- {
251
- autoCompleteText = result . AutoCompleteText ;
252
- }
253
- else if ( ! string . IsNullOrEmpty ( SelectedResults . SelectedItem ? . QuerySuggestionText ) )
254
- {
255
- autoCompleteText = SelectedResults . SelectedItem . QuerySuggestionText ;
256
- }
257
-
258
- var specialKeyState = GlobalHotkey . CheckModifiers ( ) ;
259
- if ( specialKeyState . ShiftPressed )
260
- {
261
- autoCompleteText = result . SubTitle ;
262
- }
263
-
264
- ChangeQueryText ( autoCompleteText ) ;
265
- }
266
- } ) ;
258
+ SpecialKeyState = GlobalHotkey . CheckModifiers ( )
259
+ } )
260
+ . ConfigureAwait ( false ) ;
267
261
268
- BackspaceCommand = new RelayCommand ( index =>
262
+ if ( hideWindow )
269
263
{
270
- var query = QueryBuilder . Build ( QueryText . Trim ( ) , PluginManager . NonGlobalPlugins ) ;
264
+ Hide ( ) ;
265
+ }
271
266
272
- // GetPreviousExistingDirectory does not require trailing '\', otherwise will return empty string
273
- var path = FilesFolders . GetPreviousExistingDirectory ( ( _ ) => true , query . Search . TrimEnd ( '\\ ' ) ) ;
267
+ if ( SelectedIsFromQueryResults ( ) )
268
+ {
269
+ _userSelectedRecord . Add ( result ) ;
270
+ _history . Add ( result . OriginQuery . RawQuery ) ;
271
+ }
272
+ else
273
+ {
274
+ SelectedResults = Results ;
275
+ }
276
+ }
277
+ [ RelayCommand ]
278
+ private void OpenSetting ( )
279
+ {
280
+ App . API . OpenSettingDialog ( ) ;
281
+ }
274
282
275
- var actionKeyword = string . IsNullOrEmpty ( query . ActionKeyword ) ? string . Empty : $ "{ query . ActionKeyword } ";
283
+ [ RelayCommand ]
284
+ private void SelectHelp ( )
285
+ {
286
+ PluginManager . API . OpenUrl ( "https://www.flowlauncher.com/docs/#/usage-tips" ) ;
287
+ }
276
288
277
- ChangeQueryText ( $ "{ actionKeyword } { path } ") ;
278
- } ) ;
289
+ [ RelayCommand ]
290
+ private void SelectFirstResult ( )
291
+ {
292
+ SelectedResults . SelectFirstResult ( ) ;
293
+ }
294
+ [ RelayCommand ]
295
+ private void SelectPrevPage ( )
296
+ {
297
+ SelectedResults . SelectPrevPage ( ) ;
298
+ }
279
299
280
- LoadContextMenuCommand = new RelayCommand ( _ =>
281
- {
282
- if ( SelectedIsFromQueryResults ( ) )
283
- {
284
- // When switch to ContextMenu from QueryResults, but no item being chosen, should do nothing
285
- // i.e. Shift+Enter/Ctrl+O right after Alt + Space should do nothing
286
- if ( SelectedResults . SelectedItem != null )
287
- SelectedResults = ContextMenu ;
288
- }
289
- else
290
- {
291
- SelectedResults = Results ;
292
- }
293
- } ) ;
300
+ [ RelayCommand ]
301
+ private void SelectNextPage ( )
302
+ {
303
+ SelectedResults . SelectNextPage ( ) ;
304
+ }
305
+ [ RelayCommand ]
306
+ private void SelectPrevItem ( )
307
+ {
308
+ SelectedResults . SelectPrevResult ( ) ;
309
+ }
310
+ [ RelayCommand ]
311
+ private void SelectNextItem ( )
312
+ {
313
+ SelectedResults . SelectNextResult ( ) ;
314
+ }
294
315
295
- LoadHistoryCommand = new RelayCommand ( _ =>
316
+ [ RelayCommand ]
317
+ private void Esc ( )
318
+ {
319
+ if ( ! SelectedIsFromQueryResults ( ) )
296
320
{
297
- if ( SelectedIsFromQueryResults ( ) )
298
- {
299
- SelectedResults = History ;
300
- History . SelectedIndex = _history . Items . Count - 1 ;
301
- }
302
- else
303
- {
304
- SelectedResults = Results ;
305
- }
306
- } ) ;
307
-
308
- ReloadPluginDataCommand = new RelayCommand ( _ =>
321
+ SelectedResults = Results ;
322
+ }
323
+ else
309
324
{
310
325
Hide ( ) ;
311
-
312
- _ = PluginManager
313
- . ReloadDataAsync ( )
314
- . ContinueWith ( _ =>
315
- Application . Current . Dispatcher . Invoke ( ( ) =>
316
- {
317
- Notification . Show (
318
- InternationalizationManager . Instance . GetTranslation ( "success" ) ,
319
- InternationalizationManager . Instance . GetTranslation ( "completedSuccessfully" )
320
- ) ;
321
- } ) , TaskScheduler . Default )
322
- . ConfigureAwait ( false ) ;
323
- } ) ;
326
+ }
324
327
}
325
328
326
329
#endregion
@@ -416,6 +419,7 @@ private void DecreaseMaxResult()
416
419
/// but we don't want to move cursor to end when query is updated from TextBox
417
420
/// </summary>
418
421
/// <param name="queryText"></param>
422
+ /// <param name="reQuery">Force query even when Query Text doesn't change</param>
419
423
public void ChangeQueryText ( string queryText , bool reQuery = false )
420
424
{
421
425
if ( QueryText != queryText )
@@ -494,25 +498,6 @@ public double MainWindowWidth
494
498
495
499
public string PluginIconPath { get ; set ; } = null ;
496
500
497
- public ICommand EscCommand { get ; set ; }
498
- public ICommand BackspaceCommand { get ; set ; }
499
- public ICommand SelectNextItemCommand { get ; set ; }
500
- public ICommand SelectPrevItemCommand { get ; set ; }
501
- public ICommand SelectNextPageCommand { get ; set ; }
502
- public ICommand SelectPrevPageCommand { get ; set ; }
503
- public ICommand SelectFirstResultCommand { get ; set ; }
504
- public ICommand StartHelpCommand { get ; set ; }
505
- public ICommand LoadContextMenuCommand { get ; set ; }
506
- public ICommand LoadHistoryCommand { get ; set ; }
507
- public ICommand OpenResultCommand { get ; set ; }
508
- public ICommand OpenSettingCommand { get ; set ; }
509
- public ICommand ReloadPluginDataCommand { get ; set ; }
510
- public ICommand ClearQueryCommand { get ; private set ; }
511
-
512
- public ICommand CopyToClipboard { get ; set ; }
513
-
514
- public ICommand AutocompleteQueryCommand { get ; set ; }
515
-
516
501
public string OpenResultCommandModifiers { get ; private set ; }
517
502
518
503
public string Image => Constant . QueryTextBoxIconImagePath ;
0 commit comments