diff --git a/src/Files.App/Data/Items/NavigationBarSuggestionItem.cs b/src/Files.App/Data/Items/NavigationBarSuggestionItem.cs index 35970397d594..dbc4fb8c8f90 100644 --- a/src/Files.App/Data/Items/NavigationBarSuggestionItem.cs +++ b/src/Files.App/Data/Items/NavigationBarSuggestionItem.cs @@ -1,17 +1,22 @@ // Copyright (c) Files Community // Licensed under the MIT License. +using Files.App.Controls; +using Microsoft.UI.Xaml; + namespace Files.App.Data.Items { [Obsolete("Remove once Omnibar goes out of experimental.")] - public sealed partial class NavigationBarSuggestionItem : ObservableObject + public sealed partial class NavigationBarSuggestionItem : ObservableObject, IOmnibarTextMemberPathProvider { + private Style? _ThemedIconStyle; + public Style? ThemedIconStyle { get => _ThemedIconStyle; set => SetProperty(ref _ThemedIconStyle, value); } + + private string? _Glyph; + public string? Glyph { get => _Glyph; set => SetProperty(ref _Glyph, value); } + private string? _Text; - public string? Text - { - get => _Text; - set => SetProperty(ref _Text, value); - } + public string? Text { get => _Text; set => SetProperty(ref _Text, value); } private string? _PrimaryDisplay; public string? PrimaryDisplay @@ -88,5 +93,16 @@ private void UpdatePrimaryDisplay() } } } + + public string GetTextMemberPath(string textMemberPath) + { + return textMemberPath switch + { + nameof(Text) => Text, + nameof(PrimaryDisplay) => PrimaryDisplay, + nameof(SearchText) => SearchText, + _ => string.Empty + }; + } } } diff --git a/src/Files.App/UserControls/NavigationToolbar.xaml b/src/Files.App/UserControls/NavigationToolbar.xaml index 97b8062aa009..44e615ad6bb2 100644 --- a/src/Files.App/UserControls/NavigationToolbar.xaml +++ b/src/Files.App/UserControls/NavigationToolbar.xaml @@ -27,6 +27,7 @@ + @@ -367,42 +368,50 @@ IconOnActive="{controls:ThemedIconMarkup Style={StaticResource App.ThemedIcons.Omnibar.Commands}, IsFilled=True}" IconOnInactive="{controls:ThemedIconMarkup Style={StaticResource App.ThemedIcons.Omnibar.Commands}, IconType=Outline}" ModeName="{x:Bind Commands.OpenCommandPalette.LabelWithHotKey, Mode=OneWay}" - PlaceholderText="{helpers:ResourceString Name=OmnibarCommandPaletteModeTextPlaceholder}"> - - - - - --> + TextWrapping="NoWrap"> + + + + + + + + + --> - + - + @@ -590,7 +599,7 @@ - + @@ -598,7 +607,7 @@ - + @@ -608,7 +617,7 @@ - + diff --git a/src/Files.App/UserControls/NavigationToolbar.xaml.cs b/src/Files.App/UserControls/NavigationToolbar.xaml.cs index cb36f2f341b2..76d3b353459a 100644 --- a/src/Files.App/UserControls/NavigationToolbar.xaml.cs +++ b/src/Files.App/UserControls/NavigationToolbar.xaml.cs @@ -256,19 +256,61 @@ private void ClickablePath_GettingFocus(UIElement sender, GettingFocusEventArgs private async void Omnibar_QuerySubmitted(Omnibar sender, OmnibarQuerySubmittedEventArgs args) { - await ViewModel.HandleItemNavigationAsync(args.Text); + if (Omnibar.CurrentSelectedMode == OmnibarPathMode) + { + await ViewModel.HandleItemNavigationAsync(args.Text); + } + else if (Omnibar.CurrentSelectedMode == OmnibarCommandPaletteMode) + { + } + else if (Omnibar.CurrentSelectedMode == OmnibarSearchMode) + { + } } private async void Omnibar_SuggestionChosen(Omnibar sender, OmnibarSuggestionChosenEventArgs args) { - if (args.SelectedItem is OmnibarPathModeSuggestionModel item && - !string.IsNullOrEmpty(item.Path)) - await ViewModel.HandleItemNavigationAsync(item.Path); + if (Omnibar.CurrentSelectedMode == OmnibarPathMode) + { + if (args.SelectedItem is OmnibarPathModeSuggestionModel item && + !string.IsNullOrEmpty(item.Path)) + await ViewModel.HandleItemNavigationAsync(item.Path); + } + else if (Omnibar.CurrentSelectedMode == OmnibarCommandPaletteMode) + { + if (args.SelectedItem is not NavigationBarSuggestionItem item || item.Text is not { } commandText) + return; + + var command = Commands[commandText]; + if (command == Commands.None) + await DialogDisplayHelper.ShowDialogAsync(Strings.InvalidCommand.GetLocalizedResource(), + string.Format(Strings.InvalidCommandContent.GetLocalizedResource(), commandText)); + else if (!command.IsExecutable) + await DialogDisplayHelper.ShowDialogAsync(Strings.CommandNotExecutable.GetLocalizedResource(), + string.Format(Strings.CommandNotExecutableContent.GetLocalizedResource(), command.Code)); + else + await command.ExecuteAsync(); + + Omnibar.ChangeMode(OmnibarPathMode); + } + else if (Omnibar.CurrentSelectedMode == OmnibarSearchMode) + { + } } private async void Omnibar_TextChanged(Omnibar sender, OmnibarTextChangedEventArgs args) { - await ViewModel.PopulateOmnibarSuggestionsForPathMode(); + if (Omnibar.CurrentSelectedMode == OmnibarPathMode) + { + await ViewModel.PopulateOmnibarSuggestionsForPathMode(); + } + else if (Omnibar.CurrentSelectedMode == OmnibarCommandPaletteMode) + { + ViewModel.PopulateOmnibarSuggestionsForCommandPaletteMode(); + } + else if (Omnibar.CurrentSelectedMode == OmnibarSearchMode) + { + } } private async void BreadcrumbBar_ItemClicked(Controls.BreadcrumbBar sender, Controls.BreadcrumbBarItemClickedEventArgs args) diff --git a/src/Files.App/ViewModels/UserControls/NavigationToolbarViewModel.cs b/src/Files.App/ViewModels/UserControls/NavigationToolbarViewModel.cs index 6ebe943cc44f..8eae4938644f 100644 --- a/src/Files.App/ViewModels/UserControls/NavigationToolbarViewModel.cs +++ b/src/Files.App/ViewModels/UserControls/NavigationToolbarViewModel.cs @@ -71,6 +71,8 @@ public sealed partial class NavigationToolbarViewModel : ObservableObject, IAddr internal ObservableCollection PathModeSuggestionItems { get; } = []; + internal ObservableCollection OmnibarCommandPaletteModeSuggestionItems { get; } = []; + public bool IsSingleItemOverride { get; set; } public bool SearchHasFocus { get; private set; } @@ -218,6 +220,8 @@ public string? PathText } } + private string? _OmnibarCommandPaletteModeText; + public string? OmnibarCommandPaletteModeText { get => _OmnibarCommandPaletteModeText; set => SetProperty(ref _OmnibarCommandPaletteModeText, value); } private bool _IsOmnibarFocused; public bool IsOmnibarFocused @@ -239,6 +243,8 @@ public bool IsOmnibarFocused _ = PopulateOmnibarSuggestionsForPathMode(); break; case OmnibarPaletteModeName: + if (OmnibarCommandPaletteModeSuggestionItems.Count is 0) + PopulateOmnibarSuggestionsForCommandPaletteMode(); break; case OmnibarSearchModeName: break; @@ -1126,6 +1132,30 @@ void AddNoResultsItem() } } + public void PopulateOmnibarSuggestionsForCommandPaletteMode() + { + OmnibarCommandPaletteModeText ??= string.Empty; + OmnibarCommandPaletteModeSuggestionItems.Clear(); + + var suggestionItems = Commands.Where(command => + command.IsExecutable && + command.IsAccessibleGlobally && + (command.Description.Contains(OmnibarCommandPaletteModeText, StringComparison.OrdinalIgnoreCase) || + command.Code.ToString().Contains(OmnibarCommandPaletteModeText, StringComparison.OrdinalIgnoreCase))) + .Select(command => new NavigationBarSuggestionItem() + { + ThemedIconStyle = command.Glyph.ToThemedIconStyle(), + Glyph = command.Glyph.BaseGlyph, + Text = command.Code.ToString(), + PrimaryDisplay = command.Description, + HotKeys = command.HotKeys, + SearchText = OmnibarCommandPaletteModeText, + }); + + foreach (var item in suggestionItems) + OmnibarCommandPaletteModeSuggestionItems.Add(item); + } + [Obsolete("Remove once Omnibar goes out of experimental.")] public async Task SetAddressBarSuggestionsAsync(AutoSuggestBox sender, IShellPage shellpage) {