diff --git a/src/Files.App.Controls/Files.App.Controls.csproj b/src/Files.App.Controls/Files.App.Controls.csproj
index 9e7631dc70e9..e2f44e087d4d 100644
--- a/src/Files.App.Controls/Files.App.Controls.csproj
+++ b/src/Files.App.Controls/Files.App.Controls.csproj
@@ -10,7 +10,6 @@
x86;x64;arm64
win-x86;win-x64;win-arm64
true
- $(DefineConstants);OMNIBAR_DEBUG
diff --git a/src/Files.App.Controls/Omnibar/Omnibar.Events.cs b/src/Files.App.Controls/Omnibar/Omnibar.Events.cs
index 9b224f0f442f..613f77572824 100644
--- a/src/Files.App.Controls/Omnibar/Omnibar.Events.cs
+++ b/src/Files.App.Controls/Omnibar/Omnibar.Events.cs
@@ -15,14 +15,18 @@ private void Omnibar_SizeChanged(object sender, SizeChangedEventArgs e)
// Popup width has to be set manually because it doesn't stretch with the parent
_textBoxSuggestionsContainerBorder.Width = ActualWidth;
}
+
+ private void Omnibar_LostFocus(object sender, RoutedEventArgs e)
+ {
+ // Reset to the default mode when Omnibar loses focus
+ CurrentSelectedMode = Modes?.FirstOrDefault();
+ }
private void AutoSuggestBox_GettingFocus(UIElement sender, GettingFocusEventArgs args)
{
if (args.OldFocusedElement is null)
return;
- GlobalHelper.WriteDebugStringForOmnibar("The TextBox is getting the focus.");
-
_previouslyFocusedElement = new(args.OldFocusedElement as UIElement);
}
@@ -38,8 +42,6 @@ private void AutoSuggestBox_LosingFocus(UIElement sender, LosingFocusEventArgs a
private void AutoSuggestBox_GotFocus(object sender, RoutedEventArgs e)
{
- GlobalHelper.WriteDebugStringForOmnibar("The TextBox got the focus.");
-
IsFocused = true;
_textBox.SelectAll();
}
@@ -50,8 +52,6 @@ private void AutoSuggestBox_LostFocus(object sender, RoutedEventArgs e)
if (_textBox.ContextFlyout.IsOpen)
return;
- GlobalHelper.WriteDebugStringForOmnibar("The TextBox lost the focus.");
-
IsFocused = false;
}
@@ -61,16 +61,12 @@ private async void AutoSuggestBox_KeyDown(object sender, KeyRoutedEventArgs e)
{
e.Handled = true;
- GlobalHelper.WriteDebugStringForOmnibar("The TextBox accepted the Enter key.");
-
SubmitQuery(_textBoxSuggestionsPopup.IsOpen && _textBoxSuggestionsListView.SelectedIndex is not -1 ? _textBoxSuggestionsListView.SelectedItem : null);
}
else if ((e.Key == VirtualKey.Up || e.Key == VirtualKey.Down) && _textBoxSuggestionsPopup.IsOpen)
{
e.Handled = true;
- GlobalHelper.WriteDebugStringForOmnibar("The TextBox accepted the Up/Down key while the suggestions pop-up is open.");
-
var currentIndex = _textBoxSuggestionsListView.SelectedIndex;
var nextIndex = currentIndex;
var suggestionsCount = _textBoxSuggestionsListView.Items.Count;
@@ -99,8 +95,6 @@ private async void AutoSuggestBox_KeyDown(object sender, KeyRoutedEventArgs e)
{
e.Handled = true;
- GlobalHelper.WriteDebugStringForOmnibar("The TextBox accepted the Esc key.");
-
if (_textBoxSuggestionsPopup.IsOpen)
{
RevertTextToUserInput();
@@ -112,16 +106,6 @@ private async void AutoSuggestBox_KeyDown(object sender, KeyRoutedEventArgs e)
previouslyFocusedElement?.Focus(FocusState.Programmatic);
}
}
- else if (e.Key == VirtualKey.Tab && !InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.Shift).HasFlag(CoreVirtualKeyStates.Down))
- {
- GlobalHelper.WriteDebugStringForOmnibar("The TextBox accepted the Tab key.");
-
- // Focus on inactive content when pressing Tab instead of moving to the next control in the tab order
- e.Handled = true;
- IsFocused = false;
- await Task.Delay(15);
- CurrentSelectedMode?.ContentOnInactive?.Focus(FocusState.Keyboard);
- }
else
{
_textChangeReason = OmnibarTextChangeReason.UserInput;
@@ -141,6 +125,8 @@ private void AutoSuggestBox_TextChanged(object sender, TextChangedEventArgs e)
_textChangeReason = OmnibarTextChangeReason.UserInput;
_userInput = _textBox.Text;
}
+ else if (_textChangeReason is OmnibarTextChangeReason.ProgrammaticChange)
+ _textBox.SelectAll();
TextChanged?.Invoke(this, new(CurrentSelectedMode, _textChangeReason));
@@ -150,7 +136,6 @@ private void AutoSuggestBox_TextChanged(object sender, TextChangedEventArgs e)
private void AutoSuggestBoxSuggestionsPopup_GettingFocus(UIElement sender, GettingFocusEventArgs args)
{
- // The suggestions popup is never wanted to be focused when it come to open.
args.TryCancel();
}
diff --git a/src/Files.App.Controls/Omnibar/Omnibar.Properties.cs b/src/Files.App.Controls/Omnibar/Omnibar.Properties.cs
index 1ee98de0c802..cd156dc4cea2 100644
--- a/src/Files.App.Controls/Omnibar/Omnibar.Properties.cs
+++ b/src/Files.App.Controls/Omnibar/Omnibar.Properties.cs
@@ -27,11 +27,6 @@ partial void OnCurrentSelectedModePropertyChanged(DependencyPropertyChangedEvent
if (e.NewValue is not OmnibarMode newMode)
return;
- if (e.OldValue is OmnibarMode oldMode)
- GlobalHelper.WriteDebugStringForOmnibar($"The mode change from {oldMode} to {newMode} has been requested.");
- else
- GlobalHelper.WriteDebugStringForOmnibar($"The mode change to {newMode} has been requested.");
-
ChangeMode(e.OldValue as OmnibarMode, newMode);
CurrentSelectedModeName = newMode.Name;
}
@@ -56,8 +51,6 @@ partial void OnIsFocusedChanged(bool newValue)
if (CurrentSelectedMode is null || _textBox is null)
return;
- GlobalHelper.WriteDebugStringForOmnibar($"{nameof(IsFocused)} has been changed to {IsFocused}");
-
if (newValue)
{
VisualStateManager.GoToState(CurrentSelectedMode, "Focused", true);
diff --git a/src/Files.App.Controls/Omnibar/Omnibar.cs b/src/Files.App.Controls/Omnibar/Omnibar.cs
index ff02da54c508..65c9e4ae275e 100644
--- a/src/Files.App.Controls/Omnibar/Omnibar.cs
+++ b/src/Files.App.Controls/Omnibar/Omnibar.cs
@@ -51,8 +51,6 @@ public Omnibar()
Modes = [];
AutoSuggestBoxPadding = new(0, 0, 0, 0);
-
- GlobalHelper.WriteDebugStringForOmnibar("Omnibar has been initialized.");
}
// Methods
@@ -75,6 +73,7 @@ protected override void OnApplyTemplate()
PopulateModes();
SizeChanged += Omnibar_SizeChanged;
+ LostFocus += Omnibar_LostFocus;
_textBox.GettingFocus += AutoSuggestBox_GettingFocus;
_textBox.GotFocus += AutoSuggestBox_GotFocus;
_textBox.LosingFocus += AutoSuggestBox_LosingFocus;
@@ -88,8 +87,6 @@ protected override void OnApplyTemplate()
// Set the default width
_textBoxSuggestionsContainerBorder.Width = ActualWidth;
-
- GlobalHelper.WriteDebugStringForOmnibar("The template and the events have been initialized.");
}
public void PopulateModes()
@@ -199,8 +196,6 @@ protected void ChangeMode(OmnibarMode? oldMode, OmnibarMode newMode)
mode.Transitions.Clear();
mode.UpdateLayout();
}
-
- GlobalHelper.WriteDebugStringForOmnibar($"Successfully changed Mode from {oldMode} to {newMode}");
}
internal protected void FocusTextBox()
@@ -216,16 +211,11 @@ internal protected bool TryToggleIsSuggestionsPopupOpen(bool wantToOpen)
if (wantToOpen && (!IsFocused || CurrentSelectedMode?.ItemsSource is null || (CurrentSelectedMode?.ItemsSource is IList collection && collection.Count is 0)))
{
_textBoxSuggestionsPopup.IsOpen = false;
-
- GlobalHelper.WriteDebugStringForOmnibar("The suggestions pop-up closed.");
-
return false;
}
_textBoxSuggestionsPopup.IsOpen = wantToOpen;
- GlobalHelper.WriteDebugStringForOmnibar("The suggestions pop-up is open.");
-
return false;
}
diff --git a/src/Files.App.Controls/Omnibar/OmnibarMode.Events.cs b/src/Files.App.Controls/Omnibar/OmnibarMode.Events.cs
index 39fed9ea25b1..fdc6fa6b3c7f 100644
--- a/src/Files.App.Controls/Omnibar/OmnibarMode.Events.cs
+++ b/src/Files.App.Controls/Omnibar/OmnibarMode.Events.cs
@@ -12,8 +12,6 @@ private void ModeButton_PointerEntered(object sender, PointerRoutedEventArgs e)
if (_ownerRef is null || _ownerRef.TryGetTarget(out var owner) is false || owner.CurrentSelectedMode == this)
return;
- GlobalHelper.WriteDebugStringForOmnibar($"The mouse pointer has entered the UI area of this Mode ({this})");
-
VisualStateManager.GoToState(this, "PointerOver", true);
}
@@ -22,8 +20,6 @@ private void ModeButton_PointerPressed(object sender, PointerRoutedEventArgs e)
if (_ownerRef is null || _ownerRef.TryGetTarget(out var owner) is false || owner.CurrentSelectedMode == this)
return;
- GlobalHelper.WriteDebugStringForOmnibar($"The mouse pointer has been pressed on the UI area of this Mode ({this})");
-
VisualStateManager.GoToState(this, "PointerPressed", true);
}
@@ -32,8 +28,6 @@ private void ModeButton_PointerReleased(object sender, PointerRoutedEventArgs e)
if (_ownerRef is null || _ownerRef.TryGetTarget(out var owner) is false || owner.CurrentSelectedMode == this)
return;
- GlobalHelper.WriteDebugStringForOmnibar($"The mouse pointer has been unpressed from the UI area of this Mode ({this})");
-
VisualStateManager.GoToState(this, "PointerOver", true);
owner.IsModeButtonPressed = true;
@@ -44,8 +38,6 @@ private void ModeButton_PointerReleased(object sender, PointerRoutedEventArgs e)
private void ModeButton_PointerExited(object sender, PointerRoutedEventArgs e)
{
- GlobalHelper.WriteDebugStringForOmnibar($"The mouse pointer has moved away from the UI area of this Mode ({this})");
-
VisualStateManager.GoToState(this, "PointerNormal", true);
}
}
diff --git a/src/Files.App.Controls/Omnibar/OmnibarMode.cs b/src/Files.App.Controls/Omnibar/OmnibarMode.cs
index f75bffcb9412..1a3b49e975d9 100644
--- a/src/Files.App.Controls/Omnibar/OmnibarMode.cs
+++ b/src/Files.App.Controls/Omnibar/OmnibarMode.cs
@@ -23,8 +23,6 @@ public partial class OmnibarMode : ItemsControl
public OmnibarMode()
{
DefaultStyleKey = typeof(OmnibarMode);
-
- GlobalHelper.WriteDebugStringForOmnibar($"Omnibar Mode ({this}) has been initialized.");
}
// Methods
@@ -41,8 +39,6 @@ protected override void OnApplyTemplate()
_modeButton.PointerPressed += ModeButton_PointerPressed;
_modeButton.PointerReleased += ModeButton_PointerReleased;
_modeButton.PointerExited += ModeButton_PointerExited;
-
- GlobalHelper.WriteDebugStringForOmnibar($"The template and the events of the Omnibar Mode ({this}) have been initialized.");
}
protected override void OnKeyUp(KeyRoutedEventArgs args)
@@ -92,7 +88,7 @@ public void SetOwner(Omnibar owner)
public override string ToString()
{
- return Name ?? string.Empty;
+ return ModeName ?? string.Empty;
}
}
}
diff --git a/src/Files.App.Controls/GlobalHelper.cs b/src/Files.App.Controls/Util.cs
similarity index 76%
rename from src/Files.App.Controls/GlobalHelper.cs
rename to src/Files.App.Controls/Util.cs
index 62c27e0b7462..e9866d156880 100644
--- a/src/Files.App.Controls/GlobalHelper.cs
+++ b/src/Files.App.Controls/Util.cs
@@ -3,7 +3,7 @@
namespace Files.App.Controls
{
- public static class GlobalHelper
+ public static class Util
{
///
/// Sets cursor when hovering on a specific element.
@@ -22,11 +22,5 @@ public static void ChangeCursor(this UIElement uiElement, InputCursor cursor)
[cursor]
);
}
-
- [Conditional("OMNIBAR_DEBUG")]
- public static void WriteDebugStringForOmnibar(string? message)
- {
- Debug.WriteLine($"OMNIBAR DEBUG: [{message}]");
- }
}
}
diff --git a/src/Files.App/UserControls/NavigationToolbar.xaml b/src/Files.App/UserControls/NavigationToolbar.xaml
index acf1697fc5f4..5d4a2db52e38 100644
--- a/src/Files.App/UserControls/NavigationToolbar.xaml
+++ b/src/Files.App/UserControls/NavigationToolbar.xaml
@@ -351,7 +351,7 @@
x:Load="{x:Bind ViewModel.EnableOmnibar, Mode=OneWay}"
CurrentSelectedModeName="{x:Bind ViewModel.OmnibarCurrentSelectedModeName, Mode=TwoWay}"
IsFocused="{x:Bind ViewModel.IsOmnibarFocused, Mode=TwoWay}"
- LostFocus="Omnibar_LostFocus"
+ ModeChanged="Omnibar_ModeChanged"
PreviewKeyDown="Omnibar_PreviewKeyDown"
QuerySubmitted="Omnibar_QuerySubmitted"
TextChanged="Omnibar_TextChanged">
diff --git a/src/Files.App/UserControls/NavigationToolbar.xaml.cs b/src/Files.App/UserControls/NavigationToolbar.xaml.cs
index 900d19f769d6..d13cba57089a 100644
--- a/src/Files.App/UserControls/NavigationToolbar.xaml.cs
+++ b/src/Files.App/UserControls/NavigationToolbar.xaml.cs
@@ -12,6 +12,7 @@
using Microsoft.UI.Xaml.Navigation;
using Windows.AI.Actions.Hosting;
using Windows.System;
+using Windows.UI.Core;
namespace Files.App.UserControls
{
@@ -427,22 +428,31 @@ private void BreadcrumbBar_ItemDropDownFlyoutClosed(object sender, BreadcrumbBar
e.Flyout.Items.Clear();
}
- private void Omnibar_LostFocus(object sender, RoutedEventArgs e)
+ private void Omnibar_ModeChanged(object sender, OmnibarModeChangedEventArgs e)
{
+ // Reset the command palette text when switching modes
if (Omnibar.CurrentSelectedMode == OmnibarCommandPaletteMode)
- {
- Omnibar.CurrentSelectedMode = OmnibarPathMode;
ViewModel.OmnibarCommandPaletteModeText = string.Empty;
- }
}
- private void Omnibar_PreviewKeyDown(object sender, KeyRoutedEventArgs e)
+ private async void Omnibar_PreviewKeyDown(object sender, KeyRoutedEventArgs e)
{
if (e.Key is VirtualKey.Escape)
{
Omnibar.IsFocused = false;
(MainPageViewModel.SelectedTabItem?.TabItemContent as Control)?.Focus(FocusState.Programmatic);
}
+ else if (e.Key is VirtualKey.Tab && Omnibar.IsFocused && !InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.Shift).HasFlag(CoreVirtualKeyStates.Down))
+ {
+ var currentSelectedMode = Omnibar.CurrentSelectedMode;
+ Omnibar.IsFocused = false;
+ await Task.Delay(15);
+
+ if (currentSelectedMode == OmnibarPathMode)
+ BreadcrumbBar.Focus(FocusState.Keyboard);
+ else if (Omnibar.CurrentSelectedMode == OmnibarCommandPaletteMode)
+ OmnibarCommandPaletteMode.Focus(FocusState.Keyboard);
+ }
}
private void NavigationButtonOverflowFlyoutButton_LosingFocus(UIElement sender, LosingFocusEventArgs args)