Skip to content

Commit 415c6ba

Browse files
authored
Code Quality: Replaced Home and Sidebar commands with actions (#16484)
1 parent 88a991e commit 415c6ba

16 files changed

+74
-144
lines changed

src/Files.App/Actions/Navigation/OpenInNewPane/BaseOpenInNewPaneAction.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ public string Description
1818

1919
public virtual bool IsExecutable =>
2020
ContentPageContext.SelectedItem is not null &&
21-
ContentPageContext.SelectedItem.IsFolder &&
22-
UserSettingsService.GeneralSettingsService.ShowOpenInNewPane;
21+
ContentPageContext.SelectedItem.IsFolder;
2322

2423
public virtual bool IsAccessibleGlobally
2524
=> true;

src/Files.App/Actions/Navigation/OpenInNewPane/OpenInNewPaneFromHomeAction.cs

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ namespace Files.App.Actions
66
internal sealed class OpenInNewPaneFromHomeAction : BaseOpenInNewPaneAction
77
{
88
public override bool IsExecutable =>
9-
UserSettingsService.GeneralSettingsService.ShowOpenInNewPane &&
109
HomePageContext.IsAnyItemRightClicked &&
1110
HomePageContext.RightClickedItem is not null &&
1211
(HomePageContext.RightClickedItem is WidgetFileTagCardItem fileTagItem

src/Files.App/Actions/Navigation/OpenInNewPane/OpenInNewPaneFromSidebarAction.cs

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ namespace Files.App.Actions
66
internal sealed class OpenInNewPaneFromSidebarAction : BaseOpenInNewPaneAction
77
{
88
public override bool IsExecutable =>
9-
UserSettingsService.GeneralSettingsService.ShowOpenInNewPane &&
109
SidebarContext.IsItemRightClicked &&
1110
SidebarContext.RightClickedItem is not null &&
1211
SidebarContext.RightClickedItem.MenuOptions.IsLocationItem;

src/Files.App/Actions/Navigation/OpenInNewTab/BaseOpenInNewTabAction.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ ContentPageContext.ShellPage is not null &&
2727
ContentPageContext.ShellPage.SlimContentPage is not null &&
2828
ContentPageContext.SelectedItems.Count is not 0 &&
2929
ContentPageContext.SelectedItems.Count <= 5 &&
30-
ContentPageContext.SelectedItems.Count(x => x.IsFolder) == ContentPageContext.SelectedItems.Count &&
31-
UserSettingsService.GeneralSettingsService.ShowOpenInNewTab;
30+
ContentPageContext.SelectedItems.Count(x => x.IsFolder) == ContentPageContext.SelectedItems.Count;
3231

3332
public BaseOpenInNewTabAction()
3433
{

src/Files.App/Actions/Navigation/OpenInNewTab/OpenInNewTabFromHomeAction.cs

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ namespace Files.App.Actions
66
internal sealed class OpenInNewTabFromHomeAction : BaseOpenInNewTabAction
77
{
88
public override bool IsExecutable =>
9-
UserSettingsService.GeneralSettingsService.ShowOpenInNewTab &&
109
HomePageContext.IsAnyItemRightClicked &&
1110
HomePageContext.RightClickedItem is not null &&
1211
(HomePageContext.RightClickedItem is WidgetFileTagCardItem fileTagItem

src/Files.App/Actions/Navigation/OpenInNewTab/OpenInNewTabFromSidebarAction.cs

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ namespace Files.App.Actions
66
internal sealed class OpenInNewTabFromSidebarAction : BaseOpenInNewTabAction
77
{
88
public override bool IsExecutable =>
9-
UserSettingsService.GeneralSettingsService.ShowOpenInNewTab &&
109
SidebarContext.IsItemRightClicked &&
1110
SidebarContext.RightClickedItem is not null &&
1211
SidebarContext.RightClickedItem.MenuOptions.IsLocationItem;

src/Files.App/Actions/Navigation/OpenInNewWindow/BaseOpenInNewWindowAction.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ ContentPageContext.ShellPage is not null &&
3232
ContentPageContext.ShellPage.SlimContentPage is not null &&
3333
ContentPageContext.SelectedItems.Count is not 0 &&
3434
ContentPageContext.SelectedItems.Count <= 5 &&
35-
ContentPageContext.SelectedItems.Count(x => x.IsFolder) == ContentPageContext.SelectedItems.Count &&
36-
UserSettingsService.GeneralSettingsService.ShowOpenInNewWindow;
35+
ContentPageContext.SelectedItems.Count(x => x.IsFolder) == ContentPageContext.SelectedItems.Count;
3736

3837
public BaseOpenInNewWindowAction()
3938
{

src/Files.App/Actions/Navigation/OpenInNewWindow/OpenInNewWindowFromHomeAction.cs

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ public override HotKey HotKey
99
=> HotKey.None;
1010

1111
public override bool IsExecutable =>
12-
UserSettingsService.GeneralSettingsService.ShowOpenInNewWindow &&
1312
HomePageContext.IsAnyItemRightClicked &&
1413
HomePageContext.RightClickedItem is not null &&
1514
(HomePageContext.RightClickedItem is WidgetFileTagCardItem fileTagItem

src/Files.App/Actions/Navigation/OpenInNewWindow/OpenInNewWindowFromSidebarAction.cs

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ public override HotKey HotKey
99
=> HotKey.None;
1010

1111
public override bool IsExecutable =>
12-
UserSettingsService.GeneralSettingsService.ShowOpenInNewWindow &&
1312
SidebarContext.IsItemRightClicked &&
1413
SidebarContext.RightClickedItem is not null &&
1514
SidebarContext.RightClickedItem.MenuOptions.IsLocationItem;

src/Files.App/Data/Factories/ContentPageContextFlyoutFactory.cs

+12-3
Original file line numberDiff line numberDiff line change
@@ -407,9 +407,18 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(
407407
ShowItem = itemsSelected && showOpenItemWith
408408
},
409409
new ContextMenuFlyoutItemViewModelBuilder(Commands.OpenFileLocation).Build(),
410-
new ContextMenuFlyoutItemViewModelBuilder(Commands.OpenInNewTabAction).Build(),
411-
new ContextMenuFlyoutItemViewModelBuilder(Commands.OpenInNewWindowAction).Build(),
412-
new ContextMenuFlyoutItemViewModelBuilder(Commands.OpenInNewPaneAction).Build(),
410+
new ContextMenuFlyoutItemViewModelBuilder(Commands.OpenInNewTabAction)
411+
{
412+
IsVisible = UserSettingsService.GeneralSettingsService.ShowOpenInNewTab
413+
}.Build(),
414+
new ContextMenuFlyoutItemViewModelBuilder(Commands.OpenInNewWindowAction)
415+
{
416+
IsVisible = UserSettingsService.GeneralSettingsService.ShowOpenInNewWindow
417+
}.Build(),
418+
new ContextMenuFlyoutItemViewModelBuilder(Commands.OpenInNewPaneAction)
419+
{
420+
IsVisible = UserSettingsService.GeneralSettingsService.ShowOpenInNewPane
421+
}.Build(),
413422
new ContextMenuFlyoutItemViewModel()
414423
{
415424
Text = "BaseLayoutItemContextFlyoutSetAs/Text".GetLocalizedResource(),

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

+14-37
Original file line numberDiff line numberDiff line change
@@ -254,9 +254,6 @@ public SidebarViewModel()
254254
HideSectionCommand = new RelayCommand(HideSection);
255255
UnpinItemCommand = new RelayCommand(UnpinItem);
256256
PinItemCommand = new RelayCommand(PinItem);
257-
OpenInNewTabCommand = new AsyncRelayCommand(OpenInNewTabAsync);
258-
OpenInNewWindowCommand = new AsyncRelayCommand(OpenInNewWindowAsync);
259-
OpenInNewPaneCommand = new AsyncRelayCommand(OpenInNewPaneAsync);
260257
EjectDeviceCommand = new RelayCommand(EjectDevice);
261258
OpenPropertiesCommand = new RelayCommand<CommandBarFlyout>(OpenProperties);
262259
ReorderItemsCommand = new AsyncRelayCommand(ReorderItemsAsync);
@@ -830,41 +827,12 @@ public async void HandleItemInvokedAsync(object item, PointerUpdateKind pointerU
830827

831828
private ICommand UnpinItemCommand { get; }
832829

833-
private ICommand OpenInNewTabCommand { get; }
834-
835-
private ICommand OpenInNewWindowCommand { get; }
836-
837-
private ICommand OpenInNewPaneCommand { get; }
838-
839830
private ICommand EjectDeviceCommand { get; }
840831

841832
private ICommand OpenPropertiesCommand { get; }
842833

843834
private ICommand ReorderItemsCommand { get; }
844835

845-
private async Task OpenInNewPaneAsync()
846-
{
847-
if (await DriveHelpers.CheckEmptyDrive(rightClickedItem.Path))
848-
return;
849-
PaneHolder.OpenSecondaryPane(rightClickedItem.Path);
850-
}
851-
852-
private async Task OpenInNewTabAsync()
853-
{
854-
if (await DriveHelpers.CheckEmptyDrive(rightClickedItem.Path))
855-
return;
856-
857-
await NavigationHelpers.OpenPathInNewTab(rightClickedItem.Path, false);
858-
}
859-
860-
private async Task OpenInNewWindowAsync()
861-
{
862-
if (await DriveHelpers.CheckEmptyDrive(rightClickedItem.Path))
863-
return;
864-
865-
await NavigationHelpers.OpenPathInNewWindowAsync(rightClickedItem.Path);
866-
}
867-
868836
private void PinItem()
869837
{
870838
if (rightClickedItem is DriveItem)
@@ -971,14 +939,14 @@ private List<ContextMenuFlyoutItemViewModel> GetLocationItemMenuItems(INavigatio
971939
{
972940
new ContextMenuFlyoutItemViewModel()
973941
{
974-
Text = "SideBarCreateNewLibrary/Text".GetLocalizedResource(),
942+
Text = Strings.SideBarCreateNewLibrary_Text.GetLocalizedResource(),
975943
Glyph = "\uE710",
976944
Command = CreateLibraryCommand,
977945
ShowItem = options.IsLibrariesHeader
978946
},
979947
new ContextMenuFlyoutItemViewModel()
980948
{
981-
Text = "SideBarRestoreLibraries/Text".GetLocalizedResource(),
949+
Text = Strings.SideBarRestoreLibraries_Text.GetLocalizedResource(),
982950
Glyph = "\uE10E",
983951
Command = RestoreLibrariesCommand,
984952
ShowItem = options.IsLibrariesHeader
@@ -991,9 +959,18 @@ private List<ContextMenuFlyoutItemViewModel> GetLocationItemMenuItems(INavigatio
991959
{
992960
IsVisible = options.ShowEmptyRecycleBin,
993961
}.Build(),
994-
new ContextMenuFlyoutItemViewModelBuilder(Commands.OpenInNewTabFromSidebarAction).Build(),
995-
new ContextMenuFlyoutItemViewModelBuilder(Commands.OpenInNewWindowFromSidebarAction).Build(),
996-
new ContextMenuFlyoutItemViewModelBuilder(Commands.OpenInNewPaneFromSidebarAction).Build(),
962+
new ContextMenuFlyoutItemViewModelBuilder(Commands.OpenInNewTabFromSidebarAction)
963+
{
964+
IsVisible = UserSettingsService.GeneralSettingsService.ShowOpenInNewTab
965+
}.Build(),
966+
new ContextMenuFlyoutItemViewModelBuilder(Commands.OpenInNewWindowFromSidebarAction)
967+
{
968+
IsVisible = UserSettingsService.GeneralSettingsService.ShowOpenInNewWindow
969+
}.Build(),
970+
new ContextMenuFlyoutItemViewModelBuilder(Commands.OpenInNewPaneFromSidebarAction)
971+
{
972+
IsVisible = UserSettingsService.GeneralSettingsService.ShowOpenInNewPane
973+
}.Build(),
997974
new ContextMenuFlyoutItemViewModel()
998975
{
999976
Text = "PinFolderToSidebar".GetLocalizedResource(),

src/Files.App/ViewModels/UserControls/Widgets/BaseWidgetViewModel.cs

-12
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ public abstract class BaseWidgetViewModel : ObservableObject
3737
protected ICommand RemoveRecentItemCommand { get; set; } = null!;
3838
protected ICommand ClearAllItemsCommand { get; set; } = null!;
3939
protected ICommand OpenFileLocationCommand { get; set; } = null!;
40-
protected ICommand OpenInNewTabCommand { get; set; } = null!;
41-
protected ICommand OpenInNewWindowCommand { get; set; } = null!;
4240
protected ICommand OpenPropertiesCommand { get; set; } = null!;
4341
protected ICommand PinToSidebarCommand { get; set; } = null!;
4442
protected ICommand UnpinFromSidebarCommand { get; set; } = null!;
@@ -100,16 +98,6 @@ widgetCardItem.DataContext is not WidgetCardItem item ||
10098

10199
// Command methods
102100

103-
public async Task ExecuteOpenInNewTabCommand(WidgetCardItem? item)
104-
{
105-
await NavigationHelpers.OpenPathInNewTab(item?.Path ?? string.Empty, false);
106-
}
107-
108-
public async Task ExecuteOpenInNewWindowCommand(WidgetCardItem? item)
109-
{
110-
await NavigationHelpers.OpenPathInNewWindowAsync(item?.Path ?? string.Empty);
111-
}
112-
113101
public virtual async Task ExecutePinToSidebarCommand(WidgetCardItem? item)
114102
{
115103
await QuickAccessService.PinToSidebarAsync(item?.Path ?? string.Empty);

src/Files.App/ViewModels/UserControls/Widgets/DrivesWidgetViewModel.cs

+12-15
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ public sealed class DrivesWidgetViewModel : BaseWidgetViewModel, IWidgetViewMode
2929
// Commands
3030

3131
private ICommand EjectDeviceCommand { get; } = null!;
32-
private ICommand OpenInNewPaneCommand { get; } = null!;
3332
private ICommand DisconnectNetworkDriveCommand { get; } = null!;
3433

3534
// Constructor
@@ -40,12 +39,9 @@ public DrivesWidgetViewModel()
4039

4140
DrivesViewModel.Drives.CollectionChanged += Drives_CollectionChanged;
4241

43-
OpenInNewTabCommand = new AsyncRelayCommand<WidgetCardItem>(ExecuteOpenInNewTabCommand);
44-
OpenInNewWindowCommand = new AsyncRelayCommand<WidgetCardItem>(ExecuteOpenInNewWindowCommand);
4542
PinToSidebarCommand = new AsyncRelayCommand<WidgetCardItem>(ExecutePinToSidebarCommand);
4643
UnpinFromSidebarCommand = new AsyncRelayCommand<WidgetCardItem>(ExecuteUnpinFromSidebarCommand);
4744
EjectDeviceCommand = new RelayCommand<WidgetDriveCardItem>(ExecuteEjectDeviceCommand);
48-
OpenInNewPaneCommand = new AsyncRelayCommand<WidgetDriveCardItem>(ExecuteOpenInNewPaneCommand);
4945
OpenPropertiesCommand = new RelayCommand<WidgetDriveCardItem>(ExecuteOpenPropertiesCommand);
5046
DisconnectNetworkDriveCommand = new RelayCommand<WidgetDriveCardItem>(ExecuteDisconnectNetworkDriveCommand);
5147
}
@@ -92,9 +88,18 @@ public override List<ContextMenuFlyoutItemViewModel> GetItemMenuItems(WidgetCard
9288

9389
return new List<ContextMenuFlyoutItemViewModel>()
9490
{
95-
new ContextMenuFlyoutItemViewModelBuilder(CommandManager.OpenInNewTabFromHomeAction).Build(),
96-
new ContextMenuFlyoutItemViewModelBuilder(CommandManager.OpenInNewWindowFromHomeAction).Build(),
97-
new ContextMenuFlyoutItemViewModelBuilder(CommandManager.OpenInNewPaneFromHomeAction).Build(),
91+
new ContextMenuFlyoutItemViewModelBuilder(CommandManager.OpenInNewTabFromHomeAction)
92+
{
93+
IsVisible = UserSettingsService.GeneralSettingsService.ShowOpenInNewTab
94+
}.Build(),
95+
new ContextMenuFlyoutItemViewModelBuilder(CommandManager.OpenInNewWindowFromHomeAction)
96+
{
97+
IsVisible = UserSettingsService.GeneralSettingsService.ShowOpenInNewWindow
98+
}.Build(),
99+
new ContextMenuFlyoutItemViewModelBuilder(CommandManager.OpenInNewPaneFromHomeAction)
100+
{
101+
IsVisible = UserSettingsService.GeneralSettingsService.ShowOpenInNewPane
102+
}.Build(),
98103
new()
99104
{
100105
Text = Strings.PinFolderToSidebar.GetLocalizedResource(),
@@ -174,14 +179,6 @@ private void ExecuteEjectDeviceCommand(WidgetDriveCardItem? item)
174179
DriveHelpers.EjectDeviceAsync(item.Item.Path);
175180
}
176181

177-
private async Task ExecuteOpenInNewPaneCommand(WidgetDriveCardItem? item)
178-
{
179-
if (item is null || await DriveHelpers.CheckEmptyDrive(item.Item.Path))
180-
return;
181-
182-
ContentPageContext.ShellPage!.PaneHolder?.OpenSecondaryPane(item.Item.Path);
183-
}
184-
185182
private void ExecuteOpenPropertiesCommand(WidgetDriveCardItem? item)
186183
{
187184
if (!HomePageContext.IsAnyItemRightClicked || item is null)

src/Files.App/ViewModels/UserControls/Widgets/FileTagsWidgetViewModel.cs

+12-15
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
using Microsoft.UI.Xaml.Controls;
55
using System.IO;
6-
using System.Windows.Input;
76
using Windows.Storage;
87

98
namespace Files.App.ViewModels.UserControls.Widgets
@@ -28,22 +27,16 @@ public sealed partial class FileTagsWidgetViewModel : BaseWidgetViewModel, IWidg
2827

2928
public static event EventHandler<IEnumerable<WidgetFileTagCardItem>>? SelectedTaggedItemsChanged;
3029

31-
// Commands
32-
33-
private ICommand OpenInNewPaneCommand { get; set; } = null!;
3430

3531
// Constructor
3632

3733
public FileTagsWidgetViewModel()
3834
{
3935
_ = InitializeWidget();
4036

41-
OpenInNewTabCommand = new AsyncRelayCommand<WidgetCardItem>(ExecuteOpenInNewTabCommand);
42-
OpenInNewWindowCommand = new AsyncRelayCommand<WidgetCardItem>(ExecuteOpenInNewWindowCommand);
4337
PinToSidebarCommand = new AsyncRelayCommand<WidgetCardItem>(ExecutePinToSidebarCommand);
4438
UnpinFromSidebarCommand = new AsyncRelayCommand<WidgetCardItem>(ExecuteUnpinFromSidebarCommand);
4539
OpenFileLocationCommand = new RelayCommand<WidgetCardItem>(ExecuteOpenFileLocationCommand);
46-
OpenInNewPaneCommand = new RelayCommand<WidgetCardItem>(ExecuteOpenInNewPaneCommand);
4740
OpenPropertiesCommand = new RelayCommand<WidgetCardItem>(ExecuteOpenPropertiesCommand);
4841
}
4942

@@ -73,9 +66,18 @@ public override List<ContextMenuFlyoutItemViewModel> GetItemMenuItems(WidgetCard
7366
{
7467
return new List<ContextMenuFlyoutItemViewModel>()
7568
{
76-
new ContextMenuFlyoutItemViewModelBuilder(CommandManager.OpenInNewTabFromHomeAction).Build(),
77-
new ContextMenuFlyoutItemViewModelBuilder(CommandManager.OpenInNewWindowFromHomeAction).Build(),
78-
new ContextMenuFlyoutItemViewModelBuilder(CommandManager.OpenInNewPaneFromHomeAction).Build(),
69+
new ContextMenuFlyoutItemViewModelBuilder(CommandManager.OpenInNewTabFromHomeAction)
70+
{
71+
IsVisible = UserSettingsService.GeneralSettingsService.ShowOpenInNewTab
72+
}.Build(),
73+
new ContextMenuFlyoutItemViewModelBuilder(CommandManager.OpenInNewWindowFromHomeAction)
74+
{
75+
IsVisible = UserSettingsService.GeneralSettingsService.ShowOpenInNewWindow
76+
}.Build(),
77+
new ContextMenuFlyoutItemViewModelBuilder(CommandManager.OpenInNewPaneFromHomeAction)
78+
{
79+
IsVisible = UserSettingsService.GeneralSettingsService.ShowOpenInNewPane
80+
}.Build(),
7981
new()
8082
{
8183
Text = "OpenWith".GetLocalizedResource(),
@@ -172,11 +174,6 @@ private void ExecuteOpenPropertiesCommand(WidgetCardItem? item)
172174
flyout!.Closed += flyoutClosed;
173175
}
174176

175-
private void ExecuteOpenInNewPaneCommand(WidgetCardItem? item)
176-
{
177-
ContentPageContext.ShellPage!.PaneHolder?.OpenSecondaryPane(item?.Path ?? string.Empty);
178-
}
179-
180177
private void ExecuteOpenFileLocationCommand(WidgetCardItem? item)
181178
{
182179
var itemPath = Directory.GetParent(item?.Path ?? string.Empty)?.FullName ?? string.Empty;

0 commit comments

Comments
 (0)