Skip to content

Commit b1ee7a5

Browse files
yaira20x5bfa
authored andcommitted
Connected actions to Omnibar modes
1 parent 7a77bbd commit b1ee7a5

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;
@@ -155,7 +154,7 @@ public sealed partial class NavigationToolbarViewModel : ObservableObject, IAddr
155154

156155
private bool _IsDynamicOverflowEnabled;
157156
public bool IsDynamicOverflowEnabled { get => _IsDynamicOverflowEnabled; set => SetProperty(ref _IsDynamicOverflowEnabled, value); }
158-
157+
159158
private bool _IsUpdating;
160159
public bool IsUpdating { get => _IsUpdating; set => SetProperty(ref _IsUpdating, value); }
161160

@@ -228,7 +227,7 @@ public string? PathText
228227
public string? OmnibarCommandPaletteModeText { get => _OmnibarCommandPaletteModeText; set => SetProperty(ref _OmnibarCommandPaletteModeText, value); }
229228

230229
private bool _IsOmnibarFocused;
231-
public bool IsOmnibarFocused
230+
public bool IsOmnibarFocused
232231
{
233232
get => _IsOmnibarFocused;
234233
set
@@ -237,7 +236,7 @@ public bool IsOmnibarFocused
237236
{
238237
if (value)
239238
{
240-
switch(OmnibarCurrentSelectedMode.Name)
239+
switch (OmnibarCurrentSelectedMode.Name)
241240
{
242241
case OmnibarPathModeName:
243242
PathText =
@@ -741,59 +740,79 @@ public void PathBoxItem_PreviewKeyDown(object sender, KeyRoutedEventArgs e)
741740
switch (e.Key)
742741
{
743742
case Windows.System.VirtualKey.Down:
744-
{
745-
var item = e.OriginalSource as ListViewItem;
746-
var button = item?.FindDescendant<Button>();
747-
button?.Flyout.ShowAt(button);
748-
e.Handled = true;
749-
break;
750-
}
751-
case Windows.System.VirtualKey.Space:
743+
{
744+
var item = e.OriginalSource as ListViewItem;
745+
var button = item?.FindDescendant<Button>();
746+
button?.Flyout.ShowAt(button);
747+
e.Handled = true;
748+
break;
749+
}
750+
case Windows.System.VirtualKey.Space:
752751
case Windows.System.VirtualKey.Enter:
753-
{
754-
var item = e.OriginalSource as ListViewItem;
755-
var path = (item?.Content as PathBoxItem)?.Path;
756-
if (path == PathControlDisplayText)
757-
return;
758-
ToolbarPathItemInvoked?.Invoke(this, new PathNavigationEventArgs()
759752
{
760-
ItemPath = path
761-
});
762-
e.Handled = true;
763-
break;
764-
}
753+
var item = e.OriginalSource as ListViewItem;
754+
var path = (item?.Content as PathBoxItem)?.Path;
755+
if (path == PathControlDisplayText)
756+
return;
757+
ToolbarPathItemInvoked?.Invoke(this, new PathNavigationEventArgs()
758+
{
759+
ItemPath = path
760+
});
761+
e.Handled = true;
762+
break;
763+
}
765764
}
766765
}
767766

768-
public void OpenCommandPalette()
767+
public void SwitchToCommandPaletteMode()
769768
{
770-
PathText = ">";
771-
IsCommandPaletteOpen = true;
772-
ManualEntryBoxLoaded = true;
773-
ClickablePathLoaded = false;
769+
if (EnableOmnibar)
770+
{
771+
OmnibarCurrentSelectedMode.Name = OmnibarPaletteModeName;
772+
IsOmnibarFocused = true;
773+
}
774+
else
775+
{
776+
PathText = ">";
777+
IsCommandPaletteOpen = true;
778+
ManualEntryBoxLoaded = true;
779+
ClickablePathLoaded = false;
774780

775-
var visiblePath = AddressToolbar?.FindDescendant<AutoSuggestBox>(x => x.Name == "VisiblePath");
776-
AddressBarTextEntered?.Invoke(this, new AddressBarTextEnteredEventArgs() { AddressBarTextField = visiblePath });
781+
var visiblePath = AddressToolbar?.FindDescendant<AutoSuggestBox>(x => x.Name == "VisiblePath");
782+
AddressBarTextEntered?.Invoke(this, new AddressBarTextEnteredEventArgs() { AddressBarTextField = visiblePath });
783+
}
777784
}
778785

779-
public void SwitchSearchBoxVisibility()
786+
public void SwitchToSearchMode()
780787
{
781-
if (IsSearchBoxVisible)
788+
if (EnableOmnibar)
782789
{
783-
CloseSearchBox(true);
790+
OmnibarCurrentSelectedMode.Name = OmnibarSearchModeName;
791+
IsOmnibarFocused = true;
784792
}
785793
else
786794
{
787-
IsSearchBoxVisible = true;
795+
if (IsSearchBoxVisible)
796+
CloseSearchBox(true);
797+
else
798+
{
799+
IsSearchBoxVisible = true;
788800

789-
// Given that binding and layouting might take a few cycles, when calling UpdateLayout
790-
// we can guarantee that the focus call will be able to find an open ASB
791-
var searchbox = AddressToolbar?.FindDescendant("SearchRegion") as SearchBox;
792-
searchbox?.UpdateLayout();
793-
searchbox?.Focus(FocusState.Programmatic);
801+
// Given that binding and layouting might take a few cycles, when calling UpdateLayout
802+
// we can guarantee that the focus call will be able to find an open ASB
803+
var searchbox = AddressToolbar?.FindDescendant("SearchRegion") as SearchBox;
804+
searchbox?.UpdateLayout();
805+
searchbox?.Focus(FocusState.Programmatic);
806+
}
794807
}
795808
}
796809

810+
public void SwitchToPathhMode()
811+
{
812+
OmnibarCurrentSelectedMode.Name = OmnibarPathModeName;
813+
IsOmnibarFocused = true;
814+
}
815+
797816
public void UpdateAdditionalActions()
798817
{
799818
OnPropertyChanged(nameof(HasAdditionalAction));

0 commit comments

Comments
 (0)