Skip to content
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
1 change: 1 addition & 0 deletions src/Files.App.Controls/Files.App.Controls.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<Platforms>x86;x64;arm64</Platforms>
<RuntimeIdentifiers>win-x86;win-x64;win-arm64</RuntimeIdentifiers>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DefineConstants>$(DefineConstants);OMNIBAR_DEBUG</DefineConstants>
Copy link
Member

@yaira2 yaira2 Jul 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The spacing looks off

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WDYM?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might just be the GitHub UI.
image

</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Files.App.Controls
{
public static class Util
public static class GlobalHelper
{
/// <summary>
/// Sets cursor when hovering on a specific element.
Expand All @@ -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}]");
}
}
}
15 changes: 15 additions & 0 deletions src/Files.App.Controls/Omnibar/Omnibar.Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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();
}
Expand All @@ -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;
}

Expand All @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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;
Expand Down Expand Up @@ -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();
}

Expand Down
7 changes: 7 additions & 0 deletions src/Files.App.Controls/Omnibar/Omnibar.Properties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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);
Expand Down
11 changes: 11 additions & 0 deletions src/Files.App.Controls/Omnibar/Omnibar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public Omnibar()

Modes = [];
AutoSuggestBoxPadding = new(0, 0, 0, 0);

GlobalHelper.WriteDebugStringForOmnibar("Omnibar has been initialized.");
}

// Methods
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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;
}

Expand Down
8 changes: 8 additions & 0 deletions src/Files.App.Controls/Omnibar/OmnibarMode.Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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;
Expand All @@ -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);
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/Files.App.Controls/Omnibar/OmnibarMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public partial class OmnibarMode : ItemsControl
public OmnibarMode()
{
DefaultStyleKey = typeof(OmnibarMode);

GlobalHelper.WriteDebugStringForOmnibar($"Omnibar Mode ({this}) has been initialized.");
}

// Methods
Expand All @@ -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)
Expand Down Expand Up @@ -88,7 +92,7 @@ public void SetOwner(Omnibar owner)

public override string ToString()
{
return ModeName ?? string.Empty;
return Name ?? string.Empty;
}
}
}
Loading