Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 415c6ba

Browse files
authoredNov 19, 2024··
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

Lines changed: 1 addition & 2 deletions
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 1 addition & 2 deletions
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 1 addition & 2 deletions
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 12 additions & 3 deletions
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

Lines changed: 14 additions & 37 deletions
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

Lines changed: 0 additions & 12 deletions
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

Lines changed: 12 additions & 15 deletions
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

Lines changed: 12 additions & 15 deletions
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;

‎src/Files.App/ViewModels/UserControls/Widgets/NetworkLocationsWidgetViewModel.cs

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ public bool IsNoNetworkLocations
4141
// Commands
4242

4343
private ICommand EjectDeviceCommand { get; } = null!;
44-
private ICommand OpenInNewPaneCommand { get; } = null!;
4544
private ICommand MapNetworkDriveCommand { get; } = null!;
4645
private ICommand DisconnectNetworkDriveCommand { get; } = null!;
4746

@@ -55,12 +54,9 @@ public NetworkLocationsWidgetViewModel()
5554
DrivesViewModel.Drives.CollectionChanged += Drives_CollectionChanged;
5655
NetworkService.Shortcuts.CollectionChanged += Shortcuts_CollectionChanged;
5756

58-
OpenInNewTabCommand = new AsyncRelayCommand<WidgetCardItem>(ExecuteOpenInNewTabCommand);
59-
OpenInNewWindowCommand = new AsyncRelayCommand<WidgetCardItem>(ExecuteOpenInNewWindowCommand);
6057
PinToSidebarCommand = new AsyncRelayCommand<WidgetCardItem>(ExecutePinToSidebarCommand);
6158
UnpinFromSidebarCommand = new AsyncRelayCommand<WidgetCardItem>(ExecuteUnpinFromSidebarCommand);
6259
EjectDeviceCommand = new RelayCommand<WidgetDriveCardItem>(ExecuteEjectDeviceCommand);
63-
OpenInNewPaneCommand = new AsyncRelayCommand<WidgetDriveCardItem>(ExecuteOpenInNewPaneCommand);
6460
OpenPropertiesCommand = new RelayCommand<WidgetDriveCardItem>(ExecuteOpenPropertiesCommand);
6561
DisconnectNetworkDriveCommand = new RelayCommand<WidgetDriveCardItem>(ExecuteDisconnectNetworkDriveCommand);
6662
MapNetworkDriveCommand = new AsyncRelayCommand(ExecuteMapNetworkDriveCommand);
@@ -105,29 +101,18 @@ public override List<ContextMenuFlyoutItemViewModel> GetItemMenuItems(WidgetCard
105101

106102
return new List<ContextMenuFlyoutItemViewModel>()
107103
{
108-
new()
104+
new ContextMenuFlyoutItemViewModelBuilder(CommandManager.OpenInNewTabFromHomeAction)
109105
{
110-
Text = Strings.OpenInNewTab.GetLocalizedResource(),
111-
ThemedIconModel = new ThemedIconModel() { ThemedIconStyle = "App.ThemedIcons.OpenInTab" },
112-
Command = OpenInNewTabCommand,
113-
CommandParameter = item,
114-
ShowItem = UserSettingsService.GeneralSettingsService.ShowOpenInNewTab
115-
},
116-
new()
106+
IsVisible = UserSettingsService.GeneralSettingsService.ShowOpenInNewTab
107+
}.Build(),
108+
new ContextMenuFlyoutItemViewModelBuilder(CommandManager.OpenInNewWindowFromHomeAction)
117109
{
118-
Text = Strings.OpenInNewWindow.GetLocalizedResource(),
119-
ThemedIconModel = new ThemedIconModel() { ThemedIconStyle = "App.ThemedIcons.OpenInWindow" },
120-
Command = OpenInNewWindowCommand,
121-
CommandParameter = item,
122-
ShowItem = UserSettingsService.GeneralSettingsService.ShowOpenInNewWindow
123-
},
124-
new()
110+
IsVisible = UserSettingsService.GeneralSettingsService.ShowOpenInNewWindow
111+
}.Build(),
112+
new ContextMenuFlyoutItemViewModelBuilder(CommandManager.OpenInNewPaneFromHomeAction)
125113
{
126-
Text = Strings.OpenInNewPane.GetLocalizedResource(),
127-
Command = OpenInNewPaneCommand,
128-
CommandParameter = item,
129-
ShowItem = UserSettingsService.GeneralSettingsService.ShowOpenInNewPane
130-
},
114+
IsVisible = UserSettingsService.GeneralSettingsService.ShowOpenInNewPane
115+
}.Build(),
131116
new()
132117
{
133118
Text = Strings.PinFolderToSidebar.GetLocalizedResource(),
@@ -203,14 +188,6 @@ private void ExecuteEjectDeviceCommand(WidgetDriveCardItem? item)
203188
DriveHelpers.EjectDeviceAsync(item.Item.Path);
204189
}
205190

206-
private async Task ExecuteOpenInNewPaneCommand(WidgetDriveCardItem? item)
207-
{
208-
if (item is null || await DriveHelpers.CheckEmptyDrive(item.Item.Path))
209-
return;
210-
211-
ContentPageContext.ShellPage!.PaneHolder?.OpenSecondaryPane(item.Item.Path);
212-
}
213-
214191
private Task ExecuteMapNetworkDriveCommand()
215192
{
216193
return NetworkService.OpenMapNetworkDriveDialogAsync();

‎src/Files.App/ViewModels/UserControls/Widgets/QuickAccessWidgetViewModel.cs

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ public sealed class QuickAccessWidgetViewModel : BaseWidgetViewModel, IWidgetVie
2828
public bool ShowMenuFlyout => false;
2929
public MenuFlyoutItem? MenuFlyoutItem => null;
3030

31-
// Commands
32-
33-
public ICommand OpenInNewPaneCommand { get; set; } = null!;
34-
3531
// Constructor
3632

3733
public QuickAccessWidgetViewModel()
@@ -40,9 +36,6 @@ public QuickAccessWidgetViewModel()
4036

4137
Items.CollectionChanged += Items_CollectionChanged;
4238

43-
OpenInNewTabCommand = new AsyncRelayCommand<WidgetFolderCardItem>(ExecuteOpenInNewTabCommand);
44-
OpenInNewWindowCommand = new AsyncRelayCommand<WidgetFolderCardItem>(ExecuteOpenInNewWindowCommand);
45-
OpenInNewPaneCommand = new RelayCommand<WidgetFolderCardItem>(ExecuteOpenInNewPaneCommand);
4639
OpenPropertiesCommand = new RelayCommand<WidgetFolderCardItem>(ExecuteOpenPropertiesCommand);
4740
PinToSidebarCommand = new AsyncRelayCommand<WidgetFolderCardItem>(ExecutePinToSidebarCommand);
4841
UnpinFromSidebarCommand = new AsyncRelayCommand<WidgetFolderCardItem>(ExecuteUnpinFromSidebarCommand);
@@ -67,9 +60,18 @@ public override List<ContextMenuFlyoutItemViewModel> GetItemMenuItems(WidgetCard
6760
{
6861
return new List<ContextMenuFlyoutItemViewModel>()
6962
{
70-
new ContextMenuFlyoutItemViewModelBuilder(CommandManager.OpenInNewTabFromHomeAction).Build(),
71-
new ContextMenuFlyoutItemViewModelBuilder(CommandManager.OpenInNewWindowFromHomeAction).Build(),
72-
new ContextMenuFlyoutItemViewModelBuilder(CommandManager.OpenInNewPaneFromHomeAction).Build(),
63+
new ContextMenuFlyoutItemViewModelBuilder(CommandManager.OpenInNewTabFromHomeAction)
64+
{
65+
IsVisible = UserSettingsService.GeneralSettingsService.ShowOpenInNewTab
66+
}.Build(),
67+
new ContextMenuFlyoutItemViewModelBuilder(CommandManager.OpenInNewWindowFromHomeAction)
68+
{
69+
IsVisible = UserSettingsService.GeneralSettingsService.ShowOpenInNewWindow
70+
}.Build(),
71+
new ContextMenuFlyoutItemViewModelBuilder(CommandManager.OpenInNewPaneFromHomeAction)
72+
{
73+
IsVisible = UserSettingsService.GeneralSettingsService.ShowOpenInNewPane
74+
}.Build(),
7375
new()
7476
{
7577
Text = "PinFolderToSidebar".GetLocalizedResource(),
@@ -258,14 +260,6 @@ public override async Task ExecuteUnpinFromSidebarCommand(WidgetCardItem? item)
258260
ModifyItemAsync(this, new(new[] { item.Path }, false));
259261
}
260262

261-
private void ExecuteOpenInNewPaneCommand(WidgetFolderCardItem? item)
262-
{
263-
if (item is null || item.Path is null)
264-
return;
265-
266-
ContentPageContext.ShellPage!.PaneHolder?.OpenSecondaryPane(item.Path);
267-
}
268-
269263
private void ExecuteOpenPropertiesCommand(WidgetFolderCardItem? item)
270264
{
271265
if (!HomePageContext.IsAnyItemRightClicked || item is null || item.Item is null)

0 commit comments

Comments
 (0)
Please sign in to comment.