Skip to content

Commit 14af283

Browse files
committed
Connected actions to Omnibar modes
1 parent 99bb2ff commit 14af283

File tree

5 files changed

+70
-45
lines changed

5 files changed

+70
-45
lines changed

src/Files.App/Actions/Global/EditPathAction.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ namespace Files.App.Actions
55
{
66
internal sealed class EditPathAction : IAction
77
{
8-
private readonly IContentPageContext context;
8+
private readonly IContentPageContext context = Ioc.Default.GetRequiredService<IContentPageContext>();
9+
private readonly IGeneralSettingsService GeneralSettingsService = Ioc.Default.GetRequiredService<IGeneralSettingsService>();
910

1011
public string Label
1112
=> Strings.EditPath.GetLocalizedResource();
@@ -21,13 +22,18 @@ public HotKey SecondHotKey
2122

2223
public EditPathAction()
2324
{
24-
context = Ioc.Default.GetRequiredService<IContentPageContext>();
25+
2526
}
2627

2728
public Task ExecuteAsync(object? parameter = null)
2829
{
2930
if (context.ShellPage is not null)
30-
context.ShellPage.ToolbarViewModel.IsEditModeEnabled = true;
31+
{
32+
if (GeneralSettingsService.EnableOmnibar)
33+
context.ShellPage!.ToolbarViewModel.SwitchToPathhMode();
34+
else
35+
context.ShellPage.ToolbarViewModel.IsEditModeEnabled = true;
36+
}
3137

3238
return Task.CompletedTask;
3339
}

src/Files.App/Actions/Global/SearchAction.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public SearchAction()
3434

3535
public Task ExecuteAsync(object? parameter = null)
3636
{
37-
context.ShellPage!.ToolbarViewModel.SwitchSearchBoxVisibility();
37+
context.ShellPage!.ToolbarViewModel.SwitchToSearchMode();
3838

3939
return Task.CompletedTask;
4040
}

src/Files.App/Actions/Open/OpenCommandPaletteAction.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public OpenCommandPaletteAction()
2323

2424
public Task ExecuteAsync(object? parameter = null)
2525
{
26-
_context.ShellPage?.ToolbarViewModel.OpenCommandPalette();
26+
_context.ShellPage?.ToolbarViewModel.SwitchToCommandPaletteMode();
2727

2828
return Task.CompletedTask;
2929
}

src/Files.App/Data/Contracts/IAddressToolbarViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public interface IAddressToolbarViewModel
4242

4343
public event EventHandler RefreshWidgetsRequested;
4444

45-
public void SwitchSearchBoxVisibility();
45+
public void SwitchToSearchMode();
4646

4747
public ISearchBoxViewModel SearchBox { get; }
4848
}

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

Lines changed: 58 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Licensed under the MIT License.
33

44
using CommunityToolkit.WinUI;
5-
using Files.App.Actions;
65
using Files.App.Controls;
76
using Files.Shared.Helpers;
87
using Microsoft.UI.Dispatching;
@@ -151,7 +150,7 @@ public sealed partial class NavigationToolbarViewModel : ObservableObject, IAddr
151150

152151
private bool _IsDynamicOverflowEnabled;
153152
public bool IsDynamicOverflowEnabled { get => _IsDynamicOverflowEnabled; set => SetProperty(ref _IsDynamicOverflowEnabled, value); }
154-
153+
155154
private bool _IsUpdating;
156155
public bool IsUpdating { get => _IsUpdating; set => SetProperty(ref _IsUpdating, value); }
157156

@@ -224,7 +223,7 @@ public string? PathText
224223
public string? OmnibarCommandPaletteModeText { get => _OmnibarCommandPaletteModeText; set => SetProperty(ref _OmnibarCommandPaletteModeText, value); }
225224

226225
private bool _IsOmnibarFocused;
227-
public bool IsOmnibarFocused
226+
public bool IsOmnibarFocused
228227
{
229228
get => _IsOmnibarFocused;
230229
set
@@ -233,7 +232,7 @@ public bool IsOmnibarFocused
233232
{
234233
if (value)
235234
{
236-
switch(OmnibarCurrentSelectedMode.Name)
235+
switch (OmnibarCurrentSelectedMode.Name)
237236
{
238237
case OmnibarPathModeName:
239238
PathText =
@@ -725,59 +724,79 @@ public void PathBoxItem_PreviewKeyDown(object sender, KeyRoutedEventArgs e)
725724
switch (e.Key)
726725
{
727726
case Windows.System.VirtualKey.Down:
728-
{
729-
var item = e.OriginalSource as ListViewItem;
730-
var button = item?.FindDescendant<Button>();
731-
button?.Flyout.ShowAt(button);
732-
e.Handled = true;
733-
break;
734-
}
735-
case Windows.System.VirtualKey.Space:
727+
{
728+
var item = e.OriginalSource as ListViewItem;
729+
var button = item?.FindDescendant<Button>();
730+
button?.Flyout.ShowAt(button);
731+
e.Handled = true;
732+
break;
733+
}
734+
case Windows.System.VirtualKey.Space:
736735
case Windows.System.VirtualKey.Enter:
737-
{
738-
var item = e.OriginalSource as ListViewItem;
739-
var path = (item?.Content as PathBoxItem)?.Path;
740-
if (path == PathControlDisplayText)
741-
return;
742-
ToolbarPathItemInvoked?.Invoke(this, new PathNavigationEventArgs()
743736
{
744-
ItemPath = path
745-
});
746-
e.Handled = true;
747-
break;
748-
}
737+
var item = e.OriginalSource as ListViewItem;
738+
var path = (item?.Content as PathBoxItem)?.Path;
739+
if (path == PathControlDisplayText)
740+
return;
741+
ToolbarPathItemInvoked?.Invoke(this, new PathNavigationEventArgs()
742+
{
743+
ItemPath = path
744+
});
745+
e.Handled = true;
746+
break;
747+
}
749748
}
750749
}
751750

752-
public void OpenCommandPalette()
751+
public void SwitchToCommandPaletteMode()
753752
{
754-
PathText = ">";
755-
IsCommandPaletteOpen = true;
756-
ManualEntryBoxLoaded = true;
757-
ClickablePathLoaded = false;
753+
if (EnableOmnibar)
754+
{
755+
OmnibarCurrentSelectedMode.Name = OmnibarPaletteModeName;
756+
IsOmnibarFocused = true;
757+
}
758+
else
759+
{
760+
PathText = ">";
761+
IsCommandPaletteOpen = true;
762+
ManualEntryBoxLoaded = true;
763+
ClickablePathLoaded = false;
758764

759-
var visiblePath = AddressToolbar?.FindDescendant<AutoSuggestBox>(x => x.Name == "VisiblePath");
760-
AddressBarTextEntered?.Invoke(this, new AddressBarTextEnteredEventArgs() { AddressBarTextField = visiblePath });
765+
var visiblePath = AddressToolbar?.FindDescendant<AutoSuggestBox>(x => x.Name == "VisiblePath");
766+
AddressBarTextEntered?.Invoke(this, new AddressBarTextEnteredEventArgs() { AddressBarTextField = visiblePath });
767+
}
761768
}
762769

763-
public void SwitchSearchBoxVisibility()
770+
public void SwitchToSearchMode()
764771
{
765-
if (IsSearchBoxVisible)
772+
if (EnableOmnibar)
766773
{
767-
CloseSearchBox(true);
774+
OmnibarCurrentSelectedMode.Name = OmnibarSearchModeName;
775+
IsOmnibarFocused = true;
768776
}
769777
else
770778
{
771-
IsSearchBoxVisible = true;
779+
if (IsSearchBoxVisible)
780+
CloseSearchBox(true);
781+
else
782+
{
783+
IsSearchBoxVisible = true;
772784

773-
// Given that binding and layouting might take a few cycles, when calling UpdateLayout
774-
// we can guarantee that the focus call will be able to find an open ASB
775-
var searchbox = AddressToolbar?.FindDescendant("SearchRegion") as SearchBox;
776-
searchbox?.UpdateLayout();
777-
searchbox?.Focus(FocusState.Programmatic);
785+
// Given that binding and layouting might take a few cycles, when calling UpdateLayout
786+
// we can guarantee that the focus call will be able to find an open ASB
787+
var searchbox = AddressToolbar?.FindDescendant("SearchRegion") as SearchBox;
788+
searchbox?.UpdateLayout();
789+
searchbox?.Focus(FocusState.Programmatic);
790+
}
778791
}
779792
}
780793

794+
public void SwitchToPathhMode()
795+
{
796+
OmnibarCurrentSelectedMode.Name = OmnibarPathModeName;
797+
IsOmnibarFocused = true;
798+
}
799+
781800
public void UpdateAdditionalActions()
782801
{
783802
OnPropertyChanged(nameof(HasAdditionalAction));

0 commit comments

Comments
 (0)