Skip to content

Commit 3e169ba

Browse files
committed
Fixed "On a fresh start, focusing on the Path Mode textbox doesn't open the suggestion flyout"
1 parent 2df25f2 commit 3e169ba

File tree

8 files changed

+66
-27
lines changed

8 files changed

+66
-27
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/IOmnibarTextMemberPathProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
namespace Files.App.Controls
55
{
66
/// <summary>
7-
/// An interface that provides a way to get the text member path of <see cref="OmnibarMode.SuggestionItemsSource"/>.
7+
/// An interface that provides a way to get the text member path of <see cref="OmnibarMode.ItemsSource"/>.
88
/// </summary>
99
/// <remarks>
1010
/// An alternative to this interface is to use an <see cref="Microsoft.UI.Xaml.Data.IBindableCustomPropertyImplementation"/> powered by CsWinRT.

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

Lines changed: 15 additions & 7 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,9 +156,11 @@ 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;
159-
_textBoxSuggestionsListView.ItemTemplate = newMode.SuggestionItemTemplate;
160-
_textBoxSuggestionsListView.ItemsSource = newMode.SuggestionItemsSource;
162+
_textBoxSuggestionsListView.ItemTemplate = newMode.ItemTemplate;
163+
_textBoxSuggestionsListView.ItemsSource = newMode.ItemsSource;
161164

162165
if (newMode.IsAutoFocusEnabled)
163166
{
@@ -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
{
@@ -196,12 +199,17 @@ internal protected void FocusTextBox()
196199
_textBox.Focus(FocusState.Keyboard);
197200
}
198201

199-
public bool TryToggleIsSuggestionsPopupOpen(bool wantToOpen)
202+
internal protected bool TryToggleIsSuggestionsPopupOpen(bool wantToOpen)
200203
{
201-
if (wantToOpen && (!IsFocused || CurrentSelectedMode?.SuggestionItemsSource is null || (CurrentSelectedMode?.SuggestionItemsSource 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.Controls/Omnibar/OmnibarMode.Properties.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,9 @@ public partial class OmnibarMode
2828
[GeneratedDependencyProperty]
2929
public partial FrameworkElement? IconOnInactive { get; set; }
3030

31-
[GeneratedDependencyProperty]
32-
public partial object? SuggestionItemsSource { get; set; }
33-
34-
[GeneratedDependencyProperty]
35-
public partial DataTemplate? SuggestionItemTemplate { get; set; }
36-
3731
[GeneratedDependencyProperty]
3832
/// <remark>
39-
/// Implement <see cref="IOmnibarTextMemberPathProvider"/> in <see cref="SuggestionItemsSource"/> to get the text member path from the suggestion item correctly.
33+
/// Implement <see cref="IOmnibarTextMemberPathProvider"/> in <see cref="ItemsSource"/> to get the text member path from the suggestion item correctly.
4034
/// </remark>
4135
public partial string? TextMemberPath { get; set; }
4236

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
namespace Files.App.Controls
77
{
88
[DebuggerDisplay("{" + nameof(ToString) + "(),nq}")]
9-
public partial class OmnibarMode : Control
9+
public partial class OmnibarMode : ItemsControl
1010
{
1111
// Constants
1212

@@ -66,6 +66,14 @@ protected override void OnKeyUp(KeyRoutedEventArgs args)
6666
}
6767
}
6868

69+
protected override void OnItemsChanged(object e)
70+
{
71+
base.OnItemsChanged(e);
72+
73+
if (_ownerRef is not null && _ownerRef.TryGetTarget(out var owner))
74+
owner.TryToggleIsSuggestionsPopupOpen(true);
75+
}
76+
6977
private void OmnibarMode_Loaded(object sender, RoutedEventArgs e)
7078
{
7179
// Set this mode as the current mode if it is the default mode

src/Files.App/UserControls/NavigationToolbar.xaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -333,9 +333,9 @@
333333
IconOnActive="{controls:ThemedIconMarkup Style={StaticResource App.ThemedIcons.Omnibar.Path}, IsFilled=True}"
334334
IconOnInactive="{controls:ThemedIconMarkup Style={StaticResource App.ThemedIcons.Omnibar.Path}, IconType=Outline}"
335335
IsDefault="True"
336+
ItemsSource="{x:Bind ViewModel.PathModeSuggestionItems, Mode=OneWay}"
336337
ModeName="{x:Bind Commands.EditPath.LabelWithHotKey, Mode=OneWay}"
337338
PlaceholderText="{helpers:ResourceString Name=OmnibarPathModeTextPlaceholder}"
338-
SuggestionItemsSource="{x:Bind ViewModel.PathModeSuggestionItems, Mode=OneWay}"
339339
Text="{x:Bind ViewModel.PathText, Mode=TwoWay}"
340340
TextMemberPath="Path">
341341
<controls:OmnibarMode.ContentOnInactive>
@@ -364,25 +364,25 @@
364364
</controls:BreadcrumbBar.ItemTemplate>
365365
</controls:BreadcrumbBar>
366366
</controls:OmnibarMode.ContentOnInactive>
367-
<controls:OmnibarMode.SuggestionItemTemplate>
367+
<controls:OmnibarMode.ItemTemplate>
368368
<DataTemplate x:DataType="datamodels:OmnibarPathModeSuggestionModel">
369369
<TextBlock Text="{x:Bind DisplayName, Mode=OneWay}" />
370370
</DataTemplate>
371-
</controls:OmnibarMode.SuggestionItemTemplate>
371+
</controls:OmnibarMode.ItemTemplate>
372372
</controls:OmnibarMode>
373373

374374
<controls:OmnibarMode
375375
x:Name="OmnibarCommandPaletteMode"
376376
IconOnActive="{controls:ThemedIconMarkup Style={StaticResource App.ThemedIcons.Omnibar.Commands}, IsFilled=True}"
377377
IconOnInactive="{controls:ThemedIconMarkup Style={StaticResource App.ThemedIcons.Omnibar.Commands}, IconType=Outline}"
378378
IsAutoFocusEnabled="True"
379+
ItemsSource="{x:Bind ViewModel.OmnibarCommandPaletteModeSuggestionItems, Mode=OneWay}"
379380
ModeName="{x:Bind Commands.OpenCommandPalette.LabelWithHotKey, Mode=OneWay}"
380381
PlaceholderText="{helpers:ResourceString Name=OmnibarCommandPaletteModeTextPlaceholder}"
381-
SuggestionItemsSource="{x:Bind ViewModel.OmnibarCommandPaletteModeSuggestionItems, Mode=OneWay}"
382382
Text="{x:Bind ViewModel.OmnibarCommandPaletteModeText, Mode=TwoWay}"
383383
TextMemberPath="Text"
384384
UpdateTextOnSelect="False">
385-
<controls:OmnibarMode.SuggestionItemTemplate>
385+
<controls:OmnibarMode.ItemTemplate>
386386
<DataTemplate x:DataType="dataitems:NavigationBarSuggestionItem">
387387
<Grid ColumnSpacing="12">
388388
<Grid.ColumnDefinitions>
@@ -421,7 +421,7 @@
421421
HotKeys="{x:Bind HotKeys}" />
422422
</Grid>
423423
</DataTemplate>
424-
</controls:OmnibarMode.SuggestionItemTemplate>
424+
</controls:OmnibarMode.ItemTemplate>
425425
</controls:OmnibarMode>
426426

427427
<controls:OmnibarMode

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public sealed partial class NavigationToolbar : UserControl
2323
private readonly MainPageViewModel MainPageViewModel = Ioc.Default.GetRequiredService<MainPageViewModel>();
2424
private readonly ICommandManager Commands = Ioc.Default.GetRequiredService<ICommandManager>();
2525
private readonly StatusCenterViewModel OngoingTasksViewModel = Ioc.Default.GetRequiredService<StatusCenterViewModel>();
26+
private readonly IContentPageContext ContentPageContext = Ioc.Default.GetRequiredService<IContentPageContext>();
2627

2728
// Properties
2829

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

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using CommunityToolkit.WinUI;
55
using Files.App.Controls;
66
using Files.Shared.Helpers;
7+
using Microsoft.Extensions.Logging;
78
using Microsoft.UI.Dispatching;
89
using Microsoft.UI.Xaml;
910
using Microsoft.UI.Xaml.Controls;
@@ -264,7 +265,33 @@ public bool IsOmnibarFocused
264265
}
265266

266267
private string _OmnibarCurrentSelectedModeName = OmnibarPathModeName;
267-
public string OmnibarCurrentSelectedModeName { get => _OmnibarCurrentSelectedModeName; set => SetProperty(ref _OmnibarCurrentSelectedModeName, value); }
268+
public string OmnibarCurrentSelectedModeName
269+
{
270+
get => _OmnibarCurrentSelectedModeName;
271+
set
272+
{
273+
if (SetProperty(ref _OmnibarCurrentSelectedModeName, value) && IsOmnibarFocused)
274+
{
275+
switch (value)
276+
{
277+
case OmnibarPathModeName:
278+
PathText =
279+
string.IsNullOrEmpty(ContentPageContext.ShellPage?.ShellViewModel?.WorkingDirectory)
280+
? Constants.UserEnvironmentPaths.HomePath
281+
: ContentPageContext.ShellPage.ShellViewModel.WorkingDirectory;
282+
_ = PopulateOmnibarSuggestionsForPathMode();
283+
break;
284+
case OmnibarPaletteModeName:
285+
PopulateOmnibarSuggestionsForCommandPaletteMode();
286+
break;
287+
case OmnibarSearchModeName:
288+
break;
289+
default:
290+
break;
291+
}
292+
}
293+
}
294+
}
268295

269296
private CurrentInstanceViewModel _InstanceViewModel;
270297
public CurrentInstanceViewModel InstanceViewModel
@@ -735,7 +762,6 @@ await DialogDisplayHelper.ShowDialogAsync(Strings.InvalidItemDialogTitle.GetLoca
735762
}
736763

737764
PathControlDisplayText = ContentPageContext.ShellPage.ShellViewModel.WorkingDirectory;
738-
IsOmnibarFocused = false;
739765
}
740766

741767
public void PathBoxItem_PreviewKeyDown(object sender, KeyRoutedEventArgs e)
@@ -1074,6 +1100,8 @@ private static async Task<bool> LaunchApplicationFromPath(string currentInput, s
10741100

10751101
public async Task PopulateOmnibarSuggestionsForPathMode()
10761102
{
1103+
PathModeSuggestionItems.Clear();
1104+
10771105
var result = await SafetyExtensions.IgnoreExceptions((Func<Task<bool>>)(async () =>
10781106
{
10791107
List<OmnibarPathModeSuggestionModel>? newSuggestions = [];
@@ -1114,9 +1142,7 @@ public async Task PopulateOmnibarSuggestionsForPathMode()
11141142

11151143
// If there are no suggestions, show "No suggestions"
11161144
if (newSuggestions.Count is 0)
1117-
{
1118-
AddNoResultsItem();
1119-
}
1145+
return false;
11201146

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

0 commit comments

Comments
 (0)