diff --git a/src/Files.App.Controls/Files.App.Controls.csproj b/src/Files.App.Controls/Files.App.Controls.csproj index e2f44e087d4d..9e7631dc70e9 100644 --- a/src/Files.App.Controls/Files.App.Controls.csproj +++ b/src/Files.App.Controls/Files.App.Controls.csproj @@ -10,6 +10,7 @@ x86;x64;arm64 win-x86;win-x64;win-arm64 true + $(DefineConstants);OMNIBAR_DEBUG diff --git a/src/Files.App.Controls/Util.cs b/src/Files.App.Controls/GlobalHelper.cs similarity index 76% rename from src/Files.App.Controls/Util.cs rename to src/Files.App.Controls/GlobalHelper.cs index e9866d156880..62c27e0b7462 100644 --- a/src/Files.App.Controls/Util.cs +++ b/src/Files.App.Controls/GlobalHelper.cs @@ -3,7 +3,7 @@ namespace Files.App.Controls { - public static class Util + public static class GlobalHelper { /// /// Sets cursor when hovering on a specific element. @@ -22,5 +22,11 @@ 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.Controls/Omnibar/Omnibar.Events.cs b/src/Files.App.Controls/Omnibar/Omnibar.Events.cs index f3f0459d0624..9b224f0f442f 100644 --- a/src/Files.App.Controls/Omnibar/Omnibar.Events.cs +++ b/src/Files.App.Controls/Omnibar/Omnibar.Events.cs @@ -21,6 +21,8 @@ private void AutoSuggestBox_GettingFocus(UIElement sender, GettingFocusEventArgs if (args.OldFocusedElement is null) return; + GlobalHelper.WriteDebugStringForOmnibar("The TextBox is getting the focus."); + _previouslyFocusedElement = new(args.OldFocusedElement as UIElement); } @@ -36,6 +38,8 @@ 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(); } @@ -46,6 +50,8 @@ private void AutoSuggestBox_LostFocus(object sender, RoutedEventArgs e) if (_textBox.ContextFlyout.IsOpen) return; + GlobalHelper.WriteDebugStringForOmnibar("The TextBox lost the focus."); + IsFocused = false; } @@ -55,12 +61,16 @@ 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; @@ -89,6 +99,8 @@ private async void AutoSuggestBox_KeyDown(object sender, KeyRoutedEventArgs e) { e.Handled = true; + GlobalHelper.WriteDebugStringForOmnibar("The TextBox accepted the Esc key."); + if (_textBoxSuggestionsPopup.IsOpen) { RevertTextToUserInput(); @@ -102,6 +114,8 @@ private async void AutoSuggestBox_KeyDown(object sender, KeyRoutedEventArgs e) } 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; @@ -136,6 +150,7 @@ 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 cd156dc4cea2..1ee98de0c802 100644 --- a/src/Files.App.Controls/Omnibar/Omnibar.Properties.cs +++ b/src/Files.App.Controls/Omnibar/Omnibar.Properties.cs @@ -27,6 +27,11 @@ 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; } @@ -51,6 +56,8 @@ 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 f404a66e3381..ff02da54c508 100644 --- a/src/Files.App.Controls/Omnibar/Omnibar.cs +++ b/src/Files.App.Controls/Omnibar/Omnibar.cs @@ -51,6 +51,8 @@ public Omnibar() Modes = []; AutoSuggestBoxPadding = new(0, 0, 0, 0); + + GlobalHelper.WriteDebugStringForOmnibar("Omnibar has been initialized."); } // Methods @@ -86,6 +88,8 @@ protected override void OnApplyTemplate() // Set the default width _textBoxSuggestionsContainerBorder.Width = ActualWidth; + + GlobalHelper.WriteDebugStringForOmnibar("The template and the events have been initialized."); } public void PopulateModes() @@ -195,6 +199,8 @@ 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() @@ -210,11 +216,16 @@ 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 fdc6fa6b3c7f..39fed9ea25b1 100644 --- a/src/Files.App.Controls/Omnibar/OmnibarMode.Events.cs +++ b/src/Files.App.Controls/Omnibar/OmnibarMode.Events.cs @@ -12,6 +12,8 @@ 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); } @@ -20,6 +22,8 @@ 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); } @@ -28,6 +32,8 @@ 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; @@ -38,6 +44,8 @@ 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 1a3b49e975d9..f75bffcb9412 100644 --- a/src/Files.App.Controls/Omnibar/OmnibarMode.cs +++ b/src/Files.App.Controls/Omnibar/OmnibarMode.cs @@ -23,6 +23,8 @@ public partial class OmnibarMode : ItemsControl public OmnibarMode() { DefaultStyleKey = typeof(OmnibarMode); + + GlobalHelper.WriteDebugStringForOmnibar($"Omnibar Mode ({this}) has been initialized."); } // Methods @@ -39,6 +41,8 @@ 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) @@ -88,7 +92,7 @@ public void SetOwner(Omnibar owner) public override string ToString() { - return ModeName ?? string.Empty; + return Name ?? string.Empty; } } }