Skip to content

Commit 6485531

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

File tree

7 files changed

+45
-54
lines changed

7 files changed

+45
-54
lines changed

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: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@ protected void ChangeMode(OmnibarMode? oldMode, OmnibarMode newMode)
156156
newMode.IsTabStop = false;
157157

158158
_textBox.PlaceholderText = newMode.PlaceholderText ?? string.Empty;
159-
_textBoxSuggestionsListView.ItemTemplate = newMode.SuggestionItemTemplate;
160-
_textBoxSuggestionsListView.ItemsSource = newMode.SuggestionItemsSource;
159+
_textBoxSuggestionsListView.ItemTemplate = newMode.ItemTemplate;
160+
_textBoxSuggestionsListView.ItemsSource = newMode.ItemsSource;
161161

162162
if (newMode.IsAutoFocusEnabled)
163163
{
@@ -196,9 +196,9 @@ internal protected void FocusTextBox()
196196
_textBox.Focus(FocusState.Keyboard);
197197
}
198198

199-
public bool TryToggleIsSuggestionsPopupOpen(bool wantToOpen)
199+
internal protected bool TryToggleIsSuggestionsPopupOpen(bool wantToOpen)
200200
{
201-
if (wantToOpen && (!IsFocused || CurrentSelectedMode?.SuggestionItemsSource is null || (CurrentSelectedMode?.SuggestionItemsSource is IList collection && collection.Count is 0)) ||
201+
if (wantToOpen && (!IsFocused || CurrentSelectedMode?.ItemsSource is null || (CurrentSelectedMode?.ItemsSource is IList collection && collection.Count is 0)) ||
202202
_textBoxSuggestionsPopup is null)
203203
return false;
204204

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: 7 additions & 7 deletions
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-
IsFocused="{x:Bind ViewModel.IsOmnibarFocused, Mode=TwoWay}"
325+
GotFocus="Omnibar_GotFocus"
326326
LostFocus="Omnibar_LostFocus"
327327
PreviewKeyDown="Omnibar_PreviewKeyDown"
328328
QuerySubmitted="Omnibar_QuerySubmitted"
@@ -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: 22 additions & 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

@@ -411,6 +412,27 @@ private void BreadcrumbBar_ItemDropDownFlyoutClosed(object sender, BreadcrumbBar
411412
e.Flyout.Items.Clear();
412413
}
413414

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+
414436
private void Omnibar_LostFocus(object sender, RoutedEventArgs e)
415437
{
416438
if (Omnibar.CurrentSelectedMode == OmnibarCommandPaletteMode)

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

Lines changed: 1 addition & 34 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;
@@ -230,39 +231,6 @@ public string? PathText
230231
private string? _OmnibarCommandPaletteModeText;
231232
public string? OmnibarCommandPaletteModeText { get => _OmnibarCommandPaletteModeText; set => SetProperty(ref _OmnibarCommandPaletteModeText, value); }
232233

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

@@ -735,7 +703,6 @@ await DialogDisplayHelper.ShowDialogAsync(Strings.InvalidItemDialogTitle.GetLoca
735703
}
736704

737705
PathControlDisplayText = ContentPageContext.ShellPage.ShellViewModel.WorkingDirectory;
738-
IsOmnibarFocused = false;
739706
}
740707

741708
public void PathBoxItem_PreviewKeyDown(object sender, KeyRoutedEventArgs e)

0 commit comments

Comments
 (0)