Skip to content

Feature: Introduced Omnibar 1 #17023

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

Merged
merged 4 commits into from
Apr 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/Files.App.Controls/Omnibar/Omnibar.Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ private void Omnibar_SizeChanged(object sender, SizeChangedEventArgs e)

private void AutoSuggestBox_GotFocus(object sender, RoutedEventArgs e)
{
_isFocused = true;
IsFocused = true;

VisualStateManager.GoToState(CurrentSelectedMode, "Focused", true);
VisualStateManager.GoToState(_textBox, "InputAreaVisible", true);
Expand All @@ -30,7 +30,7 @@ private void AutoSuggestBox_LostFocus(object sender, RoutedEventArgs e)
if (_textBox.ContextFlyout.IsOpen)
return;

_isFocused = false;
IsFocused = false;

if (CurrentSelectedMode?.ContentOnInactive is not null)
{
Expand Down Expand Up @@ -92,7 +92,8 @@ private void AutoSuggestBox_KeyDown(object sender, KeyRoutedEventArgs e)

private void AutoSuggestBox_TextChanged(object sender, TextChangedEventArgs e)
{
CurrentSelectedMode!.Text = _textBox.Text;
if (string.Compare(_textBox.Text, CurrentSelectedMode!.Text, StringComparison.OrdinalIgnoreCase) is not 0)
CurrentSelectedMode!.Text = _textBox.Text;

// UpdateSuggestionListView();

Expand Down
16 changes: 16 additions & 0 deletions src/Files.App.Controls/Omnibar/Omnibar.Properties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,23 @@ public partial class Omnibar
[GeneratedDependencyProperty]
public partial OmnibarMode? CurrentSelectedMode { get; set; }

[GeneratedDependencyProperty]
public partial string? CurrentSelectedModeName { get; set; }

[GeneratedDependencyProperty]
public partial Thickness AutoSuggestBoxPadding { get; set; }

[GeneratedDependencyProperty]
public partial bool IsFocused { get; set; }

partial void OnCurrentSelectedModeChanged(OmnibarMode? newValue)
{
CurrentSelectedModeName = newValue?.ModeName;
}

partial void OnIsFocusedChanged(bool newValue)
{
//_textBox?.Focus(newValue ? FocusState.Programmatic : FocusState.Unfocused);
}
}
}
23 changes: 12 additions & 11 deletions src/Files.App.Controls/Omnibar/Omnibar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public partial class Omnibar : Control
private Border _textBoxSuggestionsContainerBorder = null!;
private ListView _textBoxSuggestionsListView = null!;

private bool _isFocused;
private string _userInput = string.Empty;
private OmnibarTextChangeReason _textChangeReason = OmnibarTextChangeReason.None;

Expand Down Expand Up @@ -148,15 +147,15 @@ public void ChangeMode(OmnibarMode modeToExpand, bool shouldFocus = false, bool
CurrentSelectedMode = modeToExpand;

_textChangeReason = OmnibarTextChangeReason.ProgrammaticChange;
_textBox.Text = CurrentSelectedMode.Text ?? string.Empty;
ChangeTextBoxText(CurrentSelectedMode.Text ?? string.Empty);

// Move cursor of the TextBox to the tail
_textBox.Select(_textBox.Text.Length, 0);

VisualStateManager.GoToState(CurrentSelectedMode, "Focused", true);
CurrentSelectedMode.OnChangingCurrentMode(true);

if (_isFocused)
if (IsFocused)
{
VisualStateManager.GoToState(CurrentSelectedMode, "Focused", true);
VisualStateManager.GoToState(_textBox, "InputAreaVisible", true);
Expand All @@ -174,7 +173,7 @@ public void ChangeMode(OmnibarMode modeToExpand, bool shouldFocus = false, bool
if (shouldFocus)
_textBox.Focus(FocusState.Keyboard);

TryToggleIsSuggestionsPopupOpen(_isFocused && CurrentSelectedMode?.SuggestionItemsSource is not null);
TryToggleIsSuggestionsPopupOpen(IsFocused && CurrentSelectedMode?.SuggestionItemsSource is not null);

// Remove the reposition transition from the all modes
if (useTransition)
Expand All @@ -189,7 +188,7 @@ public void ChangeMode(OmnibarMode modeToExpand, bool shouldFocus = false, bool

public bool TryToggleIsSuggestionsPopupOpen(bool wantToOpen)
{
if (wantToOpen && (!_isFocused || CurrentSelectedMode?.SuggestionItemsSource is null))
if (wantToOpen && (!IsFocused || CurrentSelectedMode?.SuggestionItemsSource is null || (CurrentSelectedMode?.SuggestionItemsSource is IList collection && collection.Count is 0)))
return false;

_textBoxSuggestionsPopup.IsOpen = wantToOpen;
Expand All @@ -205,10 +204,15 @@ public void ChooseSuggestionItem(object obj)
if (CurrentSelectedMode.UpdateTextOnSelect)
{
_textChangeReason = OmnibarTextChangeReason.SuggestionChosen;
_textBox.Text = GetObjectText(obj);
ChangeTextBoxText(GetObjectText(obj));
}

SuggestionChosen?.Invoke(this, new(CurrentSelectedMode, obj));
}

internal protected void ChangeTextBoxText(string text)
{
_textBox.Text = text;

// Move the cursor to the end of the TextBox
_textBox?.Select(_textBox.Text.Length, 0);
Expand All @@ -233,7 +237,7 @@ private string GetObjectText(object obj)
return obj is string text
? text
: obj is IOmnibarTextMemberPathProvider textMemberPathProvider
? textMemberPathProvider.GetTextMemberPath(CurrentSelectedMode.DisplayMemberPath ?? string.Empty)
? textMemberPathProvider.GetTextMemberPath(CurrentSelectedMode.TextMemberPath ?? string.Empty)
: obj.ToString() ?? string.Empty;
}

Expand All @@ -245,10 +249,7 @@ private void RevertTextToUserInput()
_textBoxSuggestionsListView.SelectedIndex = -1;
_textChangeReason = OmnibarTextChangeReason.ProgrammaticChange;

_textBox.Text = _userInput ?? "";

// Move the cursor to the end of the TextBox
_textBox?.Select(_textBox.Text.Length, 0);
ChangeTextBoxText(_userInput ?? "");
}
}
}
1 change: 0 additions & 1 deletion src/Files.App.Controls/Omnibar/Omnibar.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@
Height="{TemplateBinding Height}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
Background="{TemplateBinding Background}"
CornerRadius="{TemplateBinding CornerRadius}"
TabFocusNavigation="Local">
<!-- Mode Button -->
<Border
Expand Down
13 changes: 12 additions & 1 deletion src/Files.App.Controls/Omnibar/OmnibarMode.Properties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,20 @@ public partial class OmnibarMode
public partial DataTemplate? SuggestionItemTemplate { get; set; }

[GeneratedDependencyProperty]
public partial string? DisplayMemberPath { get; set; }
/// <remark>
/// Implement <see cref="IOmnibarTextMemberPathProvider"/> in <see cref="SuggestionItemsSource"/> to get the text member path from the suggestion item correctly.
/// </remark>
public partial string? TextMemberPath { get; set; }

[GeneratedDependencyProperty(DefaultValue = true)]
public partial bool UpdateTextOnSelect { get; set; }

partial void OnTextChanged(string? newValue)
{
if (_ownerRef is null || _ownerRef.TryGetTarget(out var owner) is false)
return;

owner.ChangeTextBoxText(newValue ?? string.Empty);
}
}
}
1 change: 1 addition & 0 deletions src/Files.App/Data/Items/NavigationBarSuggestionItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace Files.App.Data.Items
{
[Obsolete("Remove once Omnibar goes out of experimental.")]
public sealed partial class NavigationBarSuggestionItem : ObservableObject
{
private string? _Text;
Expand Down
7 changes: 7 additions & 0 deletions src/Files.App/Data/Models/BreadcrumbBarItemModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Copyright (c) Files Community
// Licensed under the MIT License.

namespace Files.App.Data.Models
{
internal record BreadcrumbBarItemModel(string Text);
}
20 changes: 20 additions & 0 deletions src/Files.App/Data/Models/OmnibarPathModeSuggestionModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (c) Files Community
// Licensed under the MIT License.

using Files.App.Controls;

namespace Files.App.Data.Models
{
internal record OmnibarPathModeSuggestionModel(string Path, string DisplayName) : IOmnibarTextMemberPathProvider
{
public string GetTextMemberPath(string textMemberPath)
{
return textMemberPath switch
{
nameof(Path) => Path,
nameof(DisplayName) => DisplayName,
_ => string.Empty
};
}
}
}
11 changes: 10 additions & 1 deletion src/Files.App/Strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -4202,4 +4202,13 @@
<data name="EmptyShelfText" xml:space="preserve">
<value>Drag files or folders here to interact with them across different tabs</value>
</data>
</root>
<data name="OmnibarPathModeTextPlaceholder" xml:space="preserve">
<value>Enter a path to navigate to...</value>
</data>
<data name="OmnibarCommandPaletteModeTextPlaceholder" xml:space="preserve">
<value>Find features and commands...</value>
</data>
<data name="OmnibarSearchModeTextPlaceholder" xml:space="preserve">
<value>Search for files and folders...</value>
</data>
</root>
Loading
Loading