Skip to content

Commit bd2f5f1

Browse files
authored
Code Quality: Added debug logs for Omnibar (#17231)
1 parent d7fd218 commit bd2f5f1

File tree

7 files changed

+54
-2
lines changed

7 files changed

+54
-2
lines changed

src/Files.App.Controls/Files.App.Controls.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<Platforms>x86;x64;arm64</Platforms>
1111
<RuntimeIdentifiers>win-x86;win-x64;win-arm64</RuntimeIdentifiers>
1212
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
13+
<DefineConstants>$(DefineConstants);OMNIBAR_DEBUG</DefineConstants>
1314
</PropertyGroup>
1415

1516
<ItemGroup>

src/Files.App.Controls/Util.cs renamed to src/Files.App.Controls/GlobalHelper.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace Files.App.Controls
55
{
6-
public static class Util
6+
public static class GlobalHelper
77
{
88
/// <summary>
99
/// Sets cursor when hovering on a specific element.
@@ -22,5 +22,11 @@ public static void ChangeCursor(this UIElement uiElement, InputCursor cursor)
2222
[cursor]
2323
);
2424
}
25+
26+
[Conditional("OMNIBAR_DEBUG")]
27+
public static void WriteDebugStringForOmnibar(string? message)
28+
{
29+
Debug.WriteLine($"OMNIBAR DEBUG: [{message}]");
30+
}
2531
}
2632
}

src/Files.App.Controls/Omnibar/Omnibar.Events.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ private void AutoSuggestBox_GettingFocus(UIElement sender, GettingFocusEventArgs
2121
if (args.OldFocusedElement is null)
2222
return;
2323

24+
GlobalHelper.WriteDebugStringForOmnibar("The TextBox is getting the focus.");
25+
2426
_previouslyFocusedElement = new(args.OldFocusedElement as UIElement);
2527
}
2628

@@ -36,6 +38,8 @@ private void AutoSuggestBox_LosingFocus(UIElement sender, LosingFocusEventArgs a
3638

3739
private void AutoSuggestBox_GotFocus(object sender, RoutedEventArgs e)
3840
{
41+
GlobalHelper.WriteDebugStringForOmnibar("The TextBox got the focus.");
42+
3943
IsFocused = true;
4044
_textBox.SelectAll();
4145
}
@@ -46,6 +50,8 @@ private void AutoSuggestBox_LostFocus(object sender, RoutedEventArgs e)
4650
if (_textBox.ContextFlyout.IsOpen)
4751
return;
4852

53+
GlobalHelper.WriteDebugStringForOmnibar("The TextBox lost the focus.");
54+
4955
IsFocused = false;
5056
}
5157

@@ -55,12 +61,16 @@ private async void AutoSuggestBox_KeyDown(object sender, KeyRoutedEventArgs e)
5561
{
5662
e.Handled = true;
5763

64+
GlobalHelper.WriteDebugStringForOmnibar("The TextBox accepted the Enter key.");
65+
5866
SubmitQuery(_textBoxSuggestionsPopup.IsOpen && _textBoxSuggestionsListView.SelectedIndex is not -1 ? _textBoxSuggestionsListView.SelectedItem : null);
5967
}
6068
else if ((e.Key == VirtualKey.Up || e.Key == VirtualKey.Down) && _textBoxSuggestionsPopup.IsOpen)
6169
{
6270
e.Handled = true;
6371

72+
GlobalHelper.WriteDebugStringForOmnibar("The TextBox accepted the Up/Down key while the suggestions pop-up is open.");
73+
6474
var currentIndex = _textBoxSuggestionsListView.SelectedIndex;
6575
var nextIndex = currentIndex;
6676
var suggestionsCount = _textBoxSuggestionsListView.Items.Count;
@@ -89,6 +99,8 @@ private async void AutoSuggestBox_KeyDown(object sender, KeyRoutedEventArgs e)
8999
{
90100
e.Handled = true;
91101

102+
GlobalHelper.WriteDebugStringForOmnibar("The TextBox accepted the Esc key.");
103+
92104
if (_textBoxSuggestionsPopup.IsOpen)
93105
{
94106
RevertTextToUserInput();
@@ -102,6 +114,8 @@ private async void AutoSuggestBox_KeyDown(object sender, KeyRoutedEventArgs e)
102114
}
103115
else if (e.Key == VirtualKey.Tab && !InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.Shift).HasFlag(CoreVirtualKeyStates.Down))
104116
{
117+
GlobalHelper.WriteDebugStringForOmnibar("The TextBox accepted the Tab key.");
118+
105119
// Focus on inactive content when pressing Tab instead of moving to the next control in the tab order
106120
e.Handled = true;
107121
IsFocused = false;
@@ -136,6 +150,7 @@ private void AutoSuggestBox_TextChanged(object sender, TextChangedEventArgs e)
136150

137151
private void AutoSuggestBoxSuggestionsPopup_GettingFocus(UIElement sender, GettingFocusEventArgs args)
138152
{
153+
// The suggestions popup is never wanted to be focused when it come to open.
139154
args.TryCancel();
140155
}
141156

src/Files.App.Controls/Omnibar/Omnibar.Properties.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ partial void OnCurrentSelectedModePropertyChanged(DependencyPropertyChangedEvent
2727
if (e.NewValue is not OmnibarMode newMode)
2828
return;
2929

30+
if (e.OldValue is OmnibarMode oldMode)
31+
GlobalHelper.WriteDebugStringForOmnibar($"The mode change from {oldMode} to {newMode} has been requested.");
32+
else
33+
GlobalHelper.WriteDebugStringForOmnibar($"The mode change to {newMode} has been requested.");
34+
3035
ChangeMode(e.OldValue as OmnibarMode, newMode);
3136
CurrentSelectedModeName = newMode.Name;
3237
}
@@ -51,6 +56,8 @@ partial void OnIsFocusedChanged(bool newValue)
5156
if (CurrentSelectedMode is null || _textBox is null)
5257
return;
5358

59+
GlobalHelper.WriteDebugStringForOmnibar($"{nameof(IsFocused)} has been changed to {IsFocused}");
60+
5461
if (newValue)
5562
{
5663
VisualStateManager.GoToState(CurrentSelectedMode, "Focused", true);

src/Files.App.Controls/Omnibar/Omnibar.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ public Omnibar()
5151

5252
Modes = [];
5353
AutoSuggestBoxPadding = new(0, 0, 0, 0);
54+
55+
GlobalHelper.WriteDebugStringForOmnibar("Omnibar has been initialized.");
5456
}
5557

5658
// Methods
@@ -86,6 +88,8 @@ protected override void OnApplyTemplate()
8688

8789
// Set the default width
8890
_textBoxSuggestionsContainerBorder.Width = ActualWidth;
91+
92+
GlobalHelper.WriteDebugStringForOmnibar("The template and the events have been initialized.");
8993
}
9094

9195
public void PopulateModes()
@@ -195,6 +199,8 @@ protected void ChangeMode(OmnibarMode? oldMode, OmnibarMode newMode)
195199
mode.Transitions.Clear();
196200
mode.UpdateLayout();
197201
}
202+
203+
GlobalHelper.WriteDebugStringForOmnibar($"Successfully changed Mode from {oldMode} to {newMode}");
198204
}
199205

200206
internal protected void FocusTextBox()
@@ -210,11 +216,16 @@ internal protected bool TryToggleIsSuggestionsPopupOpen(bool wantToOpen)
210216
if (wantToOpen && (!IsFocused || CurrentSelectedMode?.ItemsSource is null || (CurrentSelectedMode?.ItemsSource is IList collection && collection.Count is 0)))
211217
{
212218
_textBoxSuggestionsPopup.IsOpen = false;
219+
220+
GlobalHelper.WriteDebugStringForOmnibar("The suggestions pop-up closed.");
221+
213222
return false;
214223
}
215224

216225
_textBoxSuggestionsPopup.IsOpen = wantToOpen;
217226

227+
GlobalHelper.WriteDebugStringForOmnibar("The suggestions pop-up is open.");
228+
218229
return false;
219230
}
220231

src/Files.App.Controls/Omnibar/OmnibarMode.Events.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ private void ModeButton_PointerEntered(object sender, PointerRoutedEventArgs e)
1212
if (_ownerRef is null || _ownerRef.TryGetTarget(out var owner) is false || owner.CurrentSelectedMode == this)
1313
return;
1414

15+
GlobalHelper.WriteDebugStringForOmnibar($"The mouse pointer has entered the UI area of this Mode ({this})");
16+
1517
VisualStateManager.GoToState(this, "PointerOver", true);
1618
}
1719

@@ -20,6 +22,8 @@ private void ModeButton_PointerPressed(object sender, PointerRoutedEventArgs e)
2022
if (_ownerRef is null || _ownerRef.TryGetTarget(out var owner) is false || owner.CurrentSelectedMode == this)
2123
return;
2224

25+
GlobalHelper.WriteDebugStringForOmnibar($"The mouse pointer has been pressed on the UI area of this Mode ({this})");
26+
2327
VisualStateManager.GoToState(this, "PointerPressed", true);
2428
}
2529

@@ -28,6 +32,8 @@ private void ModeButton_PointerReleased(object sender, PointerRoutedEventArgs e)
2832
if (_ownerRef is null || _ownerRef.TryGetTarget(out var owner) is false || owner.CurrentSelectedMode == this)
2933
return;
3034

35+
GlobalHelper.WriteDebugStringForOmnibar($"The mouse pointer has been unpressed from the UI area of this Mode ({this})");
36+
3137
VisualStateManager.GoToState(this, "PointerOver", true);
3238

3339
owner.IsModeButtonPressed = true;
@@ -38,6 +44,8 @@ private void ModeButton_PointerReleased(object sender, PointerRoutedEventArgs e)
3844

3945
private void ModeButton_PointerExited(object sender, PointerRoutedEventArgs e)
4046
{
47+
GlobalHelper.WriteDebugStringForOmnibar($"The mouse pointer has moved away from the UI area of this Mode ({this})");
48+
4149
VisualStateManager.GoToState(this, "PointerNormal", true);
4250
}
4351
}

src/Files.App.Controls/Omnibar/OmnibarMode.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ public partial class OmnibarMode : ItemsControl
2323
public OmnibarMode()
2424
{
2525
DefaultStyleKey = typeof(OmnibarMode);
26+
27+
GlobalHelper.WriteDebugStringForOmnibar($"Omnibar Mode ({this}) has been initialized.");
2628
}
2729

2830
// Methods
@@ -39,6 +41,8 @@ protected override void OnApplyTemplate()
3941
_modeButton.PointerPressed += ModeButton_PointerPressed;
4042
_modeButton.PointerReleased += ModeButton_PointerReleased;
4143
_modeButton.PointerExited += ModeButton_PointerExited;
44+
45+
GlobalHelper.WriteDebugStringForOmnibar($"The template and the events of the Omnibar Mode ({this}) have been initialized.");
4246
}
4347

4448
protected override void OnKeyUp(KeyRoutedEventArgs args)
@@ -88,7 +92,7 @@ public void SetOwner(Omnibar owner)
8892

8993
public override string ToString()
9094
{
91-
return ModeName ?? string.Empty;
95+
return Name ?? string.Empty;
9296
}
9397
}
9498
}

0 commit comments

Comments
 (0)