Skip to content

Commit 802302e

Browse files
committed
Init
1 parent 14040dc commit 802302e

File tree

4 files changed

+25
-13
lines changed

4 files changed

+25
-13
lines changed

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ args.InputDevice is FocusInputDeviceKind.Keyboard ||
3737

3838
private void AutoSuggestBox_GotFocus(object sender, RoutedEventArgs e)
3939
{
40+
if (IsFocused)
41+
return;
42+
4043
GlobalHelper.WriteDebugStringForOmnibar("The TextBox got the focus.");
4144

4245
IsFocused = true;
@@ -48,8 +51,8 @@ private void AutoSuggestBox_GotFocus(object sender, RoutedEventArgs e)
4851
private void AutoSuggestBox_LostFocus(object sender, RoutedEventArgs e)
4952
{
5053
// TextBox still has focus if the context menu for selected text is open
51-
var element = Microsoft.UI.Xaml.Input.FocusManager.GetFocusedElement(this.XamlRoot);
52-
if (element is FlyoutBase or Popup)
54+
var element = FocusManager.GetFocusedElement(this.XamlRoot);
55+
if (element is FlyoutBase or Popup || !IsFocused)
5356
return;
5457

5558
GlobalHelper.WriteDebugStringForOmnibar("The TextBox lost the focus.");
@@ -66,7 +69,7 @@ private void AutoSuggestBox_LostFocus(object sender, RoutedEventArgs e)
6669
}
6770
}
6871

69-
private async void AutoSuggestBox_KeyDown(object sender, KeyRoutedEventArgs e)
72+
private void AutoSuggestBox_KeyDown(object sender, KeyRoutedEventArgs e)
7073
{
7174
if (e.Key is VirtualKey.Enter)
7275
{
@@ -137,10 +140,15 @@ private void AutoSuggestBox_TextChanged(object sender, TextChangedEventArgs e)
137140
// UpdateSuggestionListView();
138141

139142
if (_textChangeReason is OmnibarTextChangeReason.ProgrammaticChange)
143+
{
140144
_textBox.SelectAll();
145+
}
141146
else
142147
{
143148
_userInput = _textBox.Text;
149+
150+
if (_textChangeReason is OmnibarTextChangeReason.None)
151+
_textChangeReason = OmnibarTextChangeReason.UserInput;
144152
}
145153

146154
TextChanged?.Invoke(this, new(CurrentSelectedMode, _textChangeReason));

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,24 +36,27 @@ partial void OnCurrentSelectedModePropertyChanged(DependencyPropertyChangedEvent
3636
CurrentSelectedModeName = newMode.Name;
3737
}
3838

39-
partial void OnCurrentSelectedModeNameChanged(string? newValue)
39+
partial void OnCurrentSelectedModeNamePropertyChanged(DependencyPropertyChangedEventArgs e)
4040
{
41-
if (string.IsNullOrEmpty(newValue) ||
41+
if (e.OldValue is not string oldValue ||
42+
e.NewValue is not string newValue ||
43+
string.IsNullOrEmpty(newValue) ||
4244
string.IsNullOrEmpty(CurrentSelectedMode?.Name) ||
43-
CurrentSelectedMode.Name.Equals(newValue) ||
45+
CurrentSelectedMode.Name.Equals(newValue, StringComparison.OrdinalIgnoreCase) ||
46+
oldValue.Equals(newValue, StringComparison.OrdinalIgnoreCase) ||
4447
Modes is null)
4548
return;
4649

47-
var newMode = Modes.Where(x => x.Name?.Equals(newValue) ?? false).FirstOrDefault();
50+
var newMode = Modes.Where(x => x.Name?.Equals(newValue, StringComparison.OrdinalIgnoreCase) ?? false).FirstOrDefault();
4851
if (newMode is null)
4952
return;
5053

5154
CurrentSelectedMode = newMode;
5255
}
5356

54-
partial void OnIsFocusedChanged(bool newValue)
57+
partial void OnIsFocusedPropertyChanged(DependencyPropertyChangedEventArgs e)
5558
{
56-
if (CurrentSelectedMode is null || _textBox is null)
59+
if (CurrentSelectedMode is null || _textBox is null || e.OldValue is not bool oldValue || e.NewValue is not bool newValue || oldValue == newValue)
5760
return;
5861

5962
GlobalHelper.WriteDebugStringForOmnibar($"{nameof(IsFocused)} has been changed to {IsFocused}");

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,14 @@ public void ChooseSuggestionItem(object obj, bool isOriginatedFromArrowKey = fal
249249

250250
internal protected void ChangeTextBoxText(string text)
251251
{
252+
if (text.Equals(_textBox.Text, StringComparison.OrdinalIgnoreCase) || CurrentSelectedMode is null)
253+
return;
254+
252255
_textBox.Text = text;
256+
CurrentSelectedMode.Text = text;
253257

254258
// Move the cursor to the end of the TextBox
255-
if (_textChangeReason == OmnibarTextChangeReason.SuggestionChosen)
259+
if (_textChangeReason is OmnibarTextChangeReason.SuggestionChosen)
256260
_textBox?.Select(_textBox.Text.Length, 0);
257261
}
258262

src/Files.App/ViewModels/UserControls/NavigationToolbarViewModel.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,6 @@ private void UserSettingsService_OnSettingChangedEvent(object? sender, SettingCh
338338
}
339339
}
340340

341-
[Obsolete("Superseded by Omnibar.")]
342341
public void PathBoxItem_DragLeave(object sender, DragEventArgs e)
343342
{
344343
if (((FrameworkElement)sender).DataContext is not PathBoxItem pathBoxItem ||
@@ -354,7 +353,6 @@ public void PathBoxItem_DragLeave(object sender, DragEventArgs e)
354353
_dragOverPath = null;
355354
}
356355

357-
[Obsolete("Superseded by Omnibar.")]
358356
public async Task PathBoxItem_Drop(object sender, DragEventArgs e)
359357
{
360358
if (_lockFlag)
@@ -393,7 +391,6 @@ public async Task PathBoxItem_Drop(object sender, DragEventArgs e)
393391
_lockFlag = false;
394392
}
395393

396-
[Obsolete("Superseded by Omnibar.")]
397394
public async Task PathBoxItem_DragOver(object sender, DragEventArgs e)
398395
{
399396
if (IsSingleItemOverride ||

0 commit comments

Comments
 (0)