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

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

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

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

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

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

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

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

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

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

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

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

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

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

public override string ToString()
{
return Name ?? string.Empty;
return ModeName ?? string.Empty;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Files.App.Controls
{
public static class GlobalHelper
public static class Util
{
/// <summary>
/// Sets cursor when hovering on a specific element.
Expand All @@ -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}]");
}
}
}
2 changes: 1 addition & 1 deletion src/Files.App/UserControls/NavigationToolbar.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down
20 changes: 15 additions & 5 deletions src/Files.App/UserControls/NavigationToolbar.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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)
Expand Down
Loading