@@ -258,32 +258,38 @@ private void ClickablePath_GettingFocus(UIElement sender, GettingFocusEventArgs
258
258
259
259
private async void Omnibar_QuerySubmitted ( Omnibar sender , OmnibarQuerySubmittedEventArgs args )
260
260
{
261
- if ( Omnibar . CurrentSelectedMode == OmnibarPathMode )
261
+ var mode = Omnibar . CurrentSelectedMode ;
262
+
263
+ // Path mode
264
+ if ( mode == OmnibarPathMode )
262
265
{
263
266
await ViewModel . HandleItemNavigationAsync ( args . Text ) ;
264
267
( MainPageViewModel . SelectedTabItem ? . TabItemContent as Control ) ? . Focus ( FocusState . Programmatic ) ;
268
+ return ;
265
269
}
266
- else if ( Omnibar . CurrentSelectedMode == OmnibarCommandPaletteMode )
270
+
271
+ // Command palette mode
272
+ else if ( mode == OmnibarCommandPaletteMode )
267
273
{
268
- if ( args . Item is not NavigationBarSuggestionItem item )
269
- return ;
274
+ var item = args . Item as NavigationBarSuggestionItem ;
270
275
271
276
// Try invoking built-in command
272
- if ( item . Text is { } commandText )
277
+ foreach ( var command in Commands )
273
278
{
274
- var command = Commands [ commandText ] ;
275
279
if ( command == Commands . None )
276
- await DialogDisplayHelper . ShowDialogAsync ( Strings . InvalidCommand . GetLocalizedResource ( ) ,
277
- string . Format ( Strings . InvalidCommandContent . GetLocalizedResource ( ) , commandText ) ) ;
278
- else if ( ! command . IsExecutable )
279
- await DialogDisplayHelper . ShowDialogAsync ( Strings . CommandNotExecutable . GetLocalizedResource ( ) ,
280
- string . Format ( Strings . CommandNotExecutableContent . GetLocalizedResource ( ) , command . Code ) ) ;
281
- else
282
- await command . ExecuteAsync ( ) ;
280
+ continue ;
281
+
282
+ if ( ! string . Equals ( command . Description , item ? . Text , StringComparison . OrdinalIgnoreCase ) &&
283
+ ! string . Equals ( command . Description , args . Text , StringComparison . OrdinalIgnoreCase ) )
284
+ continue ;
285
+
286
+ await command . ExecuteAsync ( ) ;
287
+ ( MainPageViewModel . SelectedTabItem ? . TabItemContent as Control ) ? . Focus ( FocusState . Programmatic ) ;
288
+ return ;
283
289
}
284
290
285
291
// Try invoking Windows app action
286
- else if ( ActionManager . Instance . ActionRuntime is not null && item . ActionInstance is ActionInstance actionInstance )
292
+ if ( ActionManager . Instance . ActionRuntime is not null && item ? . ActionInstance is ActionInstance actionInstance )
287
293
{
288
294
// Workaround for https://github.com/microsoft/App-Actions-On-Windows-Samples/issues/7
289
295
var action = ActionManager . Instance . ActionRuntime . ActionCatalog . GetAllActions ( )
@@ -294,11 +300,20 @@ await DialogDisplayHelper.ShowDialogAsync(Strings.CommandNotExecutable.GetLocali
294
300
var overload = action . GetOverloads ( ) . FirstOrDefault ( ) ;
295
301
await overload ? . InvokeAsync ( actionInstance . Context ) ;
296
302
}
303
+
304
+ ( MainPageViewModel . SelectedTabItem ? . TabItemContent as Control ) ? . Focus ( FocusState . Programmatic ) ;
305
+ return ;
297
306
}
298
307
308
+ await DialogDisplayHelper . ShowDialogAsync ( Strings . InvalidCommand . GetLocalizedResource ( ) ,
309
+ string . Format ( Strings . InvalidCommandContent . GetLocalizedResource ( ) , args . Text ) ) ;
310
+
299
311
( MainPageViewModel . SelectedTabItem ? . TabItemContent as Control ) ? . Focus ( FocusState . Programmatic ) ;
312
+ return ;
300
313
}
301
- else if ( Omnibar . CurrentSelectedMode == OmnibarSearchMode )
314
+
315
+ // Search mode
316
+ else if ( mode == OmnibarSearchMode )
302
317
{
303
318
}
304
319
}
0 commit comments