-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Code Quality: Improved Omnibar 14 #17248
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -78,6 +78,8 @@ public sealed partial class NavigationToolbarViewModel : ObservableObject, IAddr | |
|
|
||
| internal ObservableCollection<NavigationBarSuggestionItem> OmnibarCommandPaletteModeSuggestionItems { get; } = []; | ||
|
|
||
| internal ObservableCollection<SuggestionModel> OmnibarSearchModeSuggestionItems { get; } = []; | ||
|
|
||
| public bool IsSingleItemOverride { get; set; } | ||
|
|
||
| public bool SearchHasFocus { get; private set; } | ||
|
|
@@ -231,66 +233,14 @@ public string? PathText | |
| private string? _OmnibarCommandPaletteModeText; | ||
| public string? OmnibarCommandPaletteModeText { get => _OmnibarCommandPaletteModeText; set => SetProperty(ref _OmnibarCommandPaletteModeText, value); } | ||
|
|
||
| private bool _IsOmnibarFocused; | ||
| public bool IsOmnibarFocused | ||
| { | ||
| get => _IsOmnibarFocused; | ||
| set | ||
| { | ||
| // NOTE: Don't call ObservableObject.SetProperty() here since we don't want to change focus logic outside of the control. | ||
|
|
||
| _IsOmnibarFocused = value; | ||
|
|
||
| if (value) | ||
| { | ||
| switch (OmnibarCurrentSelectedModeName) | ||
| { | ||
| case OmnibarPathModeName: | ||
| PathText = | ||
| string.IsNullOrEmpty(ContentPageContext.ShellPage?.ShellViewModel?.WorkingDirectory) | ||
| ? Constants.UserEnvironmentPaths.HomePath | ||
| : ContentPageContext.ShellPage.ShellViewModel.WorkingDirectory; | ||
| _ = PopulateOmnibarSuggestionsForPathMode(); | ||
| break; | ||
| case OmnibarPaletteModeName: | ||
| PopulateOmnibarSuggestionsForCommandPaletteMode(); | ||
| break; | ||
| case OmnibarSearchModeName: | ||
| break; | ||
| default: | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| private string? _OmnibarSearchModeText; | ||
| public string? OmnibarSearchModeText { get => _OmnibarSearchModeText; set => SetProperty(ref _OmnibarSearchModeText, value); } | ||
|
|
||
| private string _OmnibarCurrentSelectedModeName = OmnibarPathModeName; | ||
| public string OmnibarCurrentSelectedModeName | ||
| { | ||
| get => _OmnibarCurrentSelectedModeName; | ||
| set | ||
| { | ||
| if (SetProperty(ref _OmnibarCurrentSelectedModeName, value) && IsOmnibarFocused) | ||
| { | ||
| switch (value) | ||
| { | ||
| case OmnibarPathModeName: | ||
| PathText = | ||
| string.IsNullOrEmpty(ContentPageContext.ShellPage?.ShellViewModel?.WorkingDirectory) | ||
| ? Constants.UserEnvironmentPaths.HomePath | ||
| : ContentPageContext.ShellPage.ShellViewModel.WorkingDirectory; | ||
| _ = PopulateOmnibarSuggestionsForPathMode(); | ||
| break; | ||
| case OmnibarPaletteModeName: | ||
| PopulateOmnibarSuggestionsForCommandPaletteMode(); | ||
| break; | ||
| case OmnibarSearchModeName: | ||
| break; | ||
| default: | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| set => SetProperty(ref _OmnibarCurrentSelectedModeName, value); | ||
| } | ||
|
|
||
| private CurrentInstanceViewModel _InstanceViewModel; | ||
|
|
@@ -1100,8 +1050,6 @@ private static async Task<bool> LaunchApplicationFromPath(string currentInput, s | |
|
|
||
| public async Task PopulateOmnibarSuggestionsForPathMode() | ||
| { | ||
| PathModeSuggestionItems.Clear(); | ||
|
|
||
| var result = await SafetyExtensions.IgnoreExceptions((Func<Task<bool>>)(async () => | ||
| { | ||
| List<OmnibarPathModeSuggestionModel>? newSuggestions = []; | ||
|
|
@@ -1200,49 +1148,41 @@ void AddNoResultsItem() | |
|
|
||
| public void PopulateOmnibarSuggestionsForCommandPaletteMode() | ||
| { | ||
| OmnibarCommandPaletteModeText ??= string.Empty; | ||
| OmnibarCommandPaletteModeSuggestionItems.Clear(); | ||
|
|
||
| if (ContentPageContext.SelectedItems.Count == 1 && ContentPageContext.SelectedItem is not null && !ContentPageContext.SelectedItem.IsFolder) | ||
| { | ||
| var dispatcherQueue = Microsoft.UI.Dispatching.DispatcherQueue.GetForCurrentThread(); | ||
|
|
||
| dispatcherQueue.TryEnqueue(() => | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I found that
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please look at the L439 of NavigationToolbar.xaml.cs, I've wrapped the whole method with it.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see, thanks.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like it's missing from the |
||
| try | ||
| { | ||
| try | ||
| var selectedItemPath = ContentPageContext.SelectedItem.ItemPath; | ||
| var fileActionEntity = ActionManager.Instance.EntityFactory.CreateFileEntity(selectedItemPath); | ||
| var actions = ActionManager.Instance.ActionRuntime.ActionCatalog.GetActionsForInputs(new[] { fileActionEntity }); | ||
|
|
||
| foreach (var action in actions.Where(a => a.Definition.Description.Contains(OmnibarCommandPaletteModeText, StringComparison.OrdinalIgnoreCase))) | ||
| { | ||
| var selectedItemPath = ContentPageContext.SelectedItem.ItemPath; | ||
| var fileActionEntity = ActionManager.Instance.EntityFactory.CreateFileEntity(selectedItemPath); | ||
| var actions = ActionManager.Instance.ActionRuntime.ActionCatalog.GetActionsForInputs(new[] { fileActionEntity }); | ||
| var newItem = new NavigationBarSuggestionItem | ||
| { | ||
| PrimaryDisplay = action.Definition.Description, | ||
| SearchText = OmnibarCommandPaletteModeText, | ||
| ActionInstance = action | ||
| }; | ||
|
|
||
| foreach (var action in actions.Where(a => a.Definition.Description.Contains(OmnibarCommandPaletteModeText, StringComparison.OrdinalIgnoreCase))) | ||
| if (Uri.TryCreate(action.Definition.IconFullPath, UriKind.RelativeOrAbsolute, out Uri? validUri)) | ||
| { | ||
| var newItem = new NavigationBarSuggestionItem | ||
| try | ||
| { | ||
| PrimaryDisplay = action.Definition.Description, | ||
| SearchText = OmnibarCommandPaletteModeText, | ||
| ActionInstance = action | ||
| }; | ||
|
|
||
| if (Uri.TryCreate(action.Definition.IconFullPath, UriKind.RelativeOrAbsolute, out Uri? validUri)) | ||
| newItem.ActionIconSource = new BitmapImage(validUri); | ||
| } | ||
| catch (Exception) | ||
| { | ||
| try | ||
| { | ||
| newItem.ActionIconSource = new BitmapImage(validUri); | ||
| } | ||
| catch (Exception) | ||
| { | ||
| } | ||
| } | ||
|
|
||
| OmnibarCommandPaletteModeSuggestionItems.Add(newItem); | ||
| } | ||
|
|
||
| OmnibarCommandPaletteModeSuggestionItems.Add(newItem); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| App.Logger.LogWarning(ex, ex.Message); | ||
| } | ||
| }); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| App.Logger.LogWarning(ex, ex.Message); | ||
| } | ||
| } | ||
|
|
||
| var suggestionItems = Commands | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.