Skip to content

Commit 567a252

Browse files
committed
Revert
1 parent 6485531 commit 567a252

File tree

5 files changed

+51
-29
lines changed

5 files changed

+51
-29
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@ public record class OmnibarQuerySubmittedEventArgs(OmnibarMode Mode, object? Ite
88
public record class OmnibarSuggestionChosenEventArgs(OmnibarMode Mode, object SelectedItem);
99

1010
public record class OmnibarTextChangedEventArgs(OmnibarMode Mode, OmnibarTextChangeReason Reason);
11+
12+
public record class OmnibarModeChangedEventArgs(OmnibarMode? OldMode, OmnibarMode NewMode);
1113
}

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public partial class Omnibar : Control
4141
public event TypedEventHandler<Omnibar, OmnibarQuerySubmittedEventArgs>? QuerySubmitted;
4242
public event TypedEventHandler<Omnibar, OmnibarSuggestionChosenEventArgs>? SuggestionChosen;
4343
public event TypedEventHandler<Omnibar, OmnibarTextChangedEventArgs>? TextChanged;
44+
public event TypedEventHandler<Omnibar, OmnibarModeChangedEventArgs>? ModeChanged;
4445

4546
// Constructor
4647

@@ -155,6 +156,8 @@ protected void ChangeMode(OmnibarMode? oldMode, OmnibarMode newMode)
155156
VisualStateManager.GoToState(newMode, "Focused", true);
156157
newMode.IsTabStop = false;
157158

159+
ModeChanged?.Invoke(this, new(oldMode, newMode!));
160+
158161
_textBox.PlaceholderText = newMode.PlaceholderText ?? string.Empty;
159162
_textBoxSuggestionsListView.ItemTemplate = newMode.ItemTemplate;
160163
_textBoxSuggestionsListView.ItemsSource = newMode.ItemsSource;
@@ -179,10 +182,10 @@ protected void ChangeMode(OmnibarMode? oldMode, OmnibarMode newMode)
179182
{
180183
VisualStateManager.GoToState(_textBox, "InputAreaVisible", true);
181184
}
182-
183-
TryToggleIsSuggestionsPopupOpen(true);
184185
}
185186

187+
TryToggleIsSuggestionsPopupOpen(true);
188+
186189
// Remove the reposition transition from the all modes
187190
foreach (var mode in Modes)
188191
{
@@ -198,10 +201,15 @@ internal protected void FocusTextBox()
198201

199202
internal protected bool TryToggleIsSuggestionsPopupOpen(bool wantToOpen)
200203
{
201-
if (wantToOpen && (!IsFocused || CurrentSelectedMode?.ItemsSource is null || (CurrentSelectedMode?.ItemsSource is IList collection && collection.Count is 0)) ||
202-
_textBoxSuggestionsPopup is null)
204+
if (_textBoxSuggestionsPopup is null)
203205
return false;
204206

207+
if (wantToOpen && (!IsFocused || CurrentSelectedMode?.ItemsSource is null || (CurrentSelectedMode?.ItemsSource is IList collection && collection.Count is 0)))
208+
{
209+
_textBoxSuggestionsPopup.IsOpen = false;
210+
return false;
211+
}
212+
205213
_textBoxSuggestionsPopup.IsOpen = wantToOpen;
206214

207215
return false;

src/Files.App/UserControls/NavigationToolbar.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@
322322
Grid.Column="1"
323323
x:Load="{x:Bind ViewModel.EnableOmnibar, Mode=OneWay}"
324324
CurrentSelectedModeName="{x:Bind ViewModel.OmnibarCurrentSelectedModeName, Mode=TwoWay}"
325-
GotFocus="Omnibar_GotFocus"
325+
IsFocused="{x:Bind ViewModel.IsOmnibarFocused, Mode=TwoWay}"
326326
LostFocus="Omnibar_LostFocus"
327327
PreviewKeyDown="Omnibar_PreviewKeyDown"
328328
QuerySubmitted="Omnibar_QuerySubmitted"

src/Files.App/UserControls/NavigationToolbar.xaml.cs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -412,27 +412,6 @@ private void BreadcrumbBar_ItemDropDownFlyoutClosed(object sender, BreadcrumbBar
412412
e.Flyout.Items.Clear();
413413
}
414414

415-
private async void Omnibar_GotFocus(object sender, RoutedEventArgs e)
416-
{
417-
switch (ViewModel.OmnibarCurrentSelectedModeName)
418-
{
419-
case NavigationToolbarViewModel.OmnibarPathModeName:
420-
ViewModel.PathText =
421-
string.IsNullOrEmpty(ContentPageContext.ShellPage?.ShellViewModel?.WorkingDirectory)
422-
? Constants.UserEnvironmentPaths.HomePath
423-
: ContentPageContext.ShellPage.ShellViewModel.WorkingDirectory;
424-
await ViewModel.PopulateOmnibarSuggestionsForPathMode();
425-
break;
426-
case NavigationToolbarViewModel.OmnibarPaletteModeName:
427-
ViewModel.PopulateOmnibarSuggestionsForCommandPaletteMode();
428-
break;
429-
case NavigationToolbarViewModel.OmnibarSearchModeName:
430-
break;
431-
default:
432-
break;
433-
}
434-
}
435-
436415
private void Omnibar_LostFocus(object sender, RoutedEventArgs e)
437416
{
438417
if (Omnibar.CurrentSelectedMode == OmnibarCommandPaletteMode)

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

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,39 @@ public string? PathText
231231
private string? _OmnibarCommandPaletteModeText;
232232
public string? OmnibarCommandPaletteModeText { get => _OmnibarCommandPaletteModeText; set => SetProperty(ref _OmnibarCommandPaletteModeText, value); }
233233

234+
private bool _IsOmnibarFocused;
235+
public bool IsOmnibarFocused
236+
{
237+
get => _IsOmnibarFocused;
238+
set
239+
{
240+
// NOTE: Don't call ObservableObject.SetProperty() here since we don't want to change focus logic outside of the control.
241+
242+
_IsOmnibarFocused = value;
243+
244+
if (value)
245+
{
246+
switch (OmnibarCurrentSelectedModeName)
247+
{
248+
case OmnibarPathModeName:
249+
PathText =
250+
string.IsNullOrEmpty(ContentPageContext.ShellPage?.ShellViewModel?.WorkingDirectory)
251+
? Constants.UserEnvironmentPaths.HomePath
252+
: ContentPageContext.ShellPage.ShellViewModel.WorkingDirectory;
253+
_ = PopulateOmnibarSuggestionsForPathMode();
254+
break;
255+
case OmnibarPaletteModeName:
256+
PopulateOmnibarSuggestionsForCommandPaletteMode();
257+
break;
258+
case OmnibarSearchModeName:
259+
break;
260+
default:
261+
break;
262+
}
263+
}
264+
}
265+
}
266+
234267
private string _OmnibarCurrentSelectedModeName = OmnibarPathModeName;
235268
public string OmnibarCurrentSelectedModeName { get => _OmnibarCurrentSelectedModeName; set => SetProperty(ref _OmnibarCurrentSelectedModeName, value); }
236269

@@ -1041,6 +1074,8 @@ private static async Task<bool> LaunchApplicationFromPath(string currentInput, s
10411074

10421075
public async Task PopulateOmnibarSuggestionsForPathMode()
10431076
{
1077+
PathModeSuggestionItems.Clear();
1078+
10441079
var result = await SafetyExtensions.IgnoreExceptions((Func<Task<bool>>)(async () =>
10451080
{
10461081
List<OmnibarPathModeSuggestionModel>? newSuggestions = [];
@@ -1081,9 +1116,7 @@ public async Task PopulateOmnibarSuggestionsForPathMode()
10811116

10821117
// If there are no suggestions, show "No suggestions"
10831118
if (newSuggestions.Count is 0)
1084-
{
1085-
AddNoResultsItem();
1086-
}
1119+
return false;
10871120

10881121
// Check whether at least one item is in common between the old and the new suggestions
10891122
// since the suggestions popup becoming empty causes flickering

0 commit comments

Comments
 (0)