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