Skip to content

Commit d6fd89c

Browse files
authored
Feature: Added an action to open Storage Sense (#16467)
1 parent 9e7b3f5 commit d6fd89c

File tree

10 files changed

+149
-24
lines changed

10 files changed

+149
-24
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright (c) 2024 Files Community
2+
// Licensed under the MIT License. See the LICENSE.
3+
4+
namespace Files.App.Actions
5+
{
6+
internal class OpenStorageSenseAction : ObservableObject, IAction
7+
{
8+
private readonly IContentPageContext context = Ioc.Default.GetRequiredService<IContentPageContext>();
9+
private readonly DrivesViewModel drivesViewModel = Ioc.Default.GetRequiredService<DrivesViewModel>();
10+
11+
public virtual string Label
12+
=> Strings.Cleanup.GetLocalizedResource();
13+
14+
public virtual string Description
15+
=> Strings.OpenStorageSenseDescription.GetLocalizedResource();
16+
17+
public virtual bool IsExecutable =>
18+
context.HasItem &&
19+
!context.HasSelection &&
20+
drivesViewModel.Drives
21+
.Cast<DriveItem>()
22+
.FirstOrDefault(x => string.Equals(x.Path, context.Folder?.ItemPath)) is DriveItem driveItem &&
23+
driveItem.Type != DriveType.Network;
24+
25+
public virtual bool IsAccessibleGlobally
26+
=> true;
27+
28+
public OpenStorageSenseAction()
29+
{
30+
context.PropertyChanged += Context_PropertyChanged;
31+
}
32+
33+
public virtual Task ExecuteAsync(object? parameter = null)
34+
{
35+
return StorageSenseHelper.OpenStorageSenseAsync(context.Folder?.ItemPath ?? string.Empty);
36+
}
37+
38+
public void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
39+
{
40+
if (e.PropertyName is nameof(IContentPageContext.HasItem))
41+
OnPropertyChanged(nameof(IsExecutable));
42+
}
43+
}
44+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright (c) 2024 Files Community
2+
// Licensed under the MIT License. See the LICENSE.
3+
4+
namespace Files.App.Actions
5+
{
6+
internal sealed class OpenStorageSenseFromHomeAction : OpenStorageSenseAction
7+
{
8+
private IHomePageContext HomePageContext { get; } = Ioc.Default.GetRequiredService<IHomePageContext>();
9+
private readonly DrivesViewModel drivesViewModel = Ioc.Default.GetRequiredService<DrivesViewModel>();
10+
11+
public override bool IsExecutable =>
12+
HomePageContext.IsAnyItemRightClicked &&
13+
HomePageContext.RightClickedItem is not null &&
14+
HomePageContext.RightClickedItem.Path is not null &&
15+
drivesViewModel.Drives
16+
.Cast<DriveItem>()
17+
.FirstOrDefault(x => string.Equals(x.Path, HomePageContext.RightClickedItem.Path)) is DriveItem driveItem &&
18+
driveItem.Type != DriveType.Network;
19+
20+
public override bool IsAccessibleGlobally
21+
=> false;
22+
23+
public override Task ExecuteAsync(object? parameter = null)
24+
{
25+
return StorageSenseHelper.OpenStorageSenseAsync(HomePageContext?.RightClickedItem?.Path ?? string.Empty);
26+
}
27+
}
28+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright (c) 2024 Files Community
2+
// Licensed under the MIT License. See the LICENSE.
3+
4+
namespace Files.App.Actions
5+
{
6+
internal sealed class OpenStorageSenseFromSidebarAction : OpenStorageSenseAction
7+
{
8+
private ISidebarContext SidebarContext { get; } = Ioc.Default.GetRequiredService<ISidebarContext>();
9+
private readonly DrivesViewModel drivesViewModel = Ioc.Default.GetRequiredService<DrivesViewModel>();
10+
11+
public override bool IsExecutable =>
12+
SidebarContext.IsItemRightClicked &&
13+
SidebarContext.RightClickedItem is not null &&
14+
SidebarContext.RightClickedItem.Path is not null &&
15+
drivesViewModel.Drives
16+
.Cast<DriveItem>()
17+
.FirstOrDefault(x => string.Equals(x.Path, SidebarContext.RightClickedItem.Path)) is DriveItem driveItem &&
18+
driveItem.Type != DriveType.Network;
19+
20+
public override bool IsAccessibleGlobally
21+
=> false;
22+
23+
public override Task ExecuteAsync(object? parameter = null)
24+
{
25+
return StorageSenseHelper.OpenStorageSenseAsync(SidebarContext?.RightClickedItem?.Path ?? string.Empty);
26+
}
27+
}
28+
}

src/Files.App/Data/Commands/Manager/CommandCodes.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ public enum CommandCodes
114114
OpenProperties,
115115
OpenClassicProperties,
116116
OpenSettings,
117+
OpenStorageSense,
118+
OpenStorageSenseFromHome,
119+
OpenStorageSenseFromSidebar,
117120
OpenTerminal,
118121
OpenTerminalAsAdmin,
119122
OpenTerminalFromSidebar,

src/Files.App/Data/Commands/Manager/CommandManager.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ public IRichCommand this[HotKey hotKey]
116116
public IRichCommand OpenRepoInVSCode => commands[CommandCodes.OpenRepoInVSCode];
117117
public IRichCommand OpenProperties => commands[CommandCodes.OpenProperties];
118118
public IRichCommand OpenClassicProperties => commands[CommandCodes.OpenClassicProperties];
119+
public IRichCommand OpenStorageSense => commands[CommandCodes.OpenStorageSense];
120+
public IRichCommand OpenStorageSenseFromHome => commands[CommandCodes.OpenStorageSenseFromHome];
121+
public IRichCommand OpenStorageSenseFromSidebar => commands[CommandCodes.OpenStorageSenseFromSidebar];
119122
public IRichCommand OpenSettings => commands[CommandCodes.OpenSettings];
120123
public IRichCommand OpenTerminal => commands[CommandCodes.OpenTerminal];
121124
public IRichCommand OpenTerminalAsAdmin => commands[CommandCodes.OpenTerminalAsAdmin];
@@ -313,6 +316,9 @@ public IEnumerator<IRichCommand> GetEnumerator() =>
313316
[CommandCodes.OpenRepoInVSCode] = new OpenRepoInVSCodeAction(),
314317
[CommandCodes.OpenProperties] = new OpenPropertiesAction(),
315318
[CommandCodes.OpenClassicProperties] = new OpenClassicPropertiesAction(),
319+
[CommandCodes.OpenStorageSense] = new OpenStorageSenseAction(),
320+
[CommandCodes.OpenStorageSenseFromHome] = new OpenStorageSenseFromHomeAction(),
321+
[CommandCodes.OpenStorageSenseFromSidebar] = new OpenStorageSenseFromSidebarAction(),
316322
[CommandCodes.OpenSettings] = new OpenSettingsAction(),
317323
[CommandCodes.OpenTerminal] = new OpenTerminalAction(),
318324
[CommandCodes.OpenTerminalAsAdmin] = new OpenTerminalAsAdminAction(),

src/Files.App/Data/Commands/Manager/ICommandManager.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ public interface ICommandManager : IEnumerable<IRichCommand>
102102
IRichCommand OpenRepoInVSCode { get; }
103103
IRichCommand OpenProperties { get; }
104104
IRichCommand OpenClassicProperties { get; }
105+
IRichCommand OpenStorageSense { get; }
106+
IRichCommand OpenStorageSenseFromHome { get; }
107+
IRichCommand OpenStorageSenseFromSidebar { get; }
105108
IRichCommand OpenSettings { get; }
106109
IRichCommand OpenTerminal { get; }
107110
IRichCommand OpenTerminalAsAdmin { get; }

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,6 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(
368368
ShowItem = !itemsSelected,
369369
ShowInFtpPage = true
370370
},
371-
new ContextMenuFlyoutItemViewModelBuilder(Commands.FormatDrive).Build(),
372371
new ContextMenuFlyoutItemViewModelBuilder(Commands.EmptyRecycleBin)
373372
{
374373
IsVisible = currentInstanceViewModel.IsPageTypeRecycleBin && !itemsSelected,
@@ -598,12 +597,17 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(
598597
new ContextMenuFlyoutItemViewModel()
599598
{
600599
ItemType = ContextMenuFlyoutItemType.Separator,
601-
ShowItem = !itemsSelected && Commands.OpenTerminal.IsExecutable || areAllItemsFolders && Commands.OpenTerminal.IsExecutable
600+
ShowItem = (!itemsSelected && Commands.OpenTerminal.IsExecutable) ||
601+
(areAllItemsFolders && Commands.OpenTerminal.IsExecutable) ||
602+
Commands.OpenStorageSense.IsExecutable ||
603+
Commands.FormatDrive.IsExecutable
602604
},
603605
new ContextMenuFlyoutItemViewModelBuilder(Commands.OpenTerminal)
604606
{
605-
IsVisible = !itemsSelected && Commands.OpenTerminal.IsExecutable || areAllItemsFolders && Commands.OpenTerminal.IsExecutable
607+
IsVisible = (!itemsSelected && Commands.OpenTerminal.IsExecutable) || (areAllItemsFolders && Commands.OpenTerminal.IsExecutable)
606608
}.Build(),
609+
new ContextMenuFlyoutItemViewModelBuilder(Commands.OpenStorageSense).Build(),
610+
new ContextMenuFlyoutItemViewModelBuilder(Commands.FormatDrive).Build(),
607611
// Shell extensions are not available on the FTP server or in the archive,
608612
// but following items are intentionally added because icons in the context menu will not appear
609613
// unless there is at least one menu item with an icon that is not an ThemedIconModel. (#12943)

src/Files.App/Strings/en-US/Resources.resw

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1244,6 +1244,12 @@
12441244
<data name="OpenStorageSense" xml:space="preserve">
12451245
<value>Open Storage Sense</value>
12461246
</data>
1247+
<data name="OpenStorageSenseDescription" xml:space="preserve">
1248+
<value>Open the Storage Sense page in Windows Settings</value>
1249+
</data>
1250+
<data name="Cleanup" xml:space="preserve">
1251+
<value>Cleanup</value>
1252+
</data>
12471253
<data name="Copy" xml:space="preserve">
12481254
<value>Copy</value>
12491255
</data>
@@ -2274,7 +2280,7 @@
22742280
<value>Show hidden items</value>
22752281
</data>
22762282
<data name="FormatDriveText" xml:space="preserve">
2277-
<value>Format...</value>
2283+
<value>Format</value>
22782284
</data>
22792285
<data name="Help" xml:space="preserve">
22802286
<value>Help</value>

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
using Files.App.Helpers.ContextFlyouts;
55
using Files.App.UserControls.Sidebar;
6-
using Files.App.ViewModels.Dialogs;
76
using Microsoft.UI.Input;
87
using Microsoft.UI.Xaml;
98
using Microsoft.UI.Xaml.Controls;
@@ -12,13 +11,11 @@
1211
using System.Collections.Specialized;
1312
using System.IO;
1413
using System.Windows.Input;
15-
using Windows.ApplicationModel.DataTransfer.DragDrop;
1614
using Windows.ApplicationModel.DataTransfer;
15+
using Windows.ApplicationModel.DataTransfer.DragDrop;
1716
using Windows.Storage;
1817
using Windows.System;
1918
using Windows.UI.Core;
20-
using Files.Core.Storage;
21-
using Files.Core.Storage.Extensions;
2219

2320
namespace Files.App.ViewModels.UserControls
2421
{
@@ -1046,13 +1043,6 @@ private List<ContextMenuFlyoutItemViewModel> GetLocationItemMenuItems(INavigatio
10461043
ShowItem = options.ShowEjectDevice
10471044
},
10481045
new ContextMenuFlyoutItemViewModel()
1049-
{
1050-
Text = "FormatDriveText".GetLocalizedResource(),
1051-
Command = FormatDriveCommand,
1052-
CommandParameter = item,
1053-
ShowItem = options.ShowFormatDrive
1054-
},
1055-
new ContextMenuFlyoutItemViewModel()
10561046
{
10571047
Text = "Properties".GetLocalizedResource(),
10581048
ThemedIconModel = new ThemedIconModel()
@@ -1066,9 +1056,19 @@ private List<ContextMenuFlyoutItemViewModel> GetLocationItemMenuItems(INavigatio
10661056
new ContextMenuFlyoutItemViewModel()
10671057
{
10681058
ItemType = ContextMenuFlyoutItemType.Separator,
1069-
ShowItem = Commands.OpenTerminalFromSidebar.IsExecutable
1059+
ShowItem = Commands.OpenTerminalFromSidebar.IsExecutable ||
1060+
Commands.OpenStorageSenseFromSidebar.IsExecutable ||
1061+
options.ShowFormatDrive
10701062
},
10711063
new ContextMenuFlyoutItemViewModelBuilder(Commands.OpenTerminalFromSidebar).Build(),
1064+
new ContextMenuFlyoutItemViewModelBuilder(Commands.OpenStorageSenseFromSidebar).Build(),
1065+
new ContextMenuFlyoutItemViewModel()
1066+
{
1067+
Text = Strings.FormatDriveText.GetLocalizedResource(),
1068+
Command = FormatDriveCommand,
1069+
CommandParameter = item,
1070+
ShowItem = options.ShowFormatDrive
1071+
},
10721072
new ContextMenuFlyoutItemViewModel()
10731073
{
10741074
ItemType = ContextMenuFlyoutItemType.Separator,

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,6 @@ public override List<ContextMenuFlyoutItemViewModel> GetItemMenuItems(WidgetCard
121121
ShowItem = options?.ShowEjectDevice ?? false
122122
},
123123
new()
124-
{
125-
Text = "FormatDriveText".GetLocalizedResource(),
126-
Command = FormatDriveCommand,
127-
CommandParameter = item,
128-
ShowItem = options?.ShowFormatDrive ?? false
129-
},
130-
new()
131124
{
132125
Text = "Properties".GetLocalizedResource(),
133126
ThemedIconModel = new ThemedIconModel() { ThemedIconStyle = "App.ThemedIcons.Properties" },
@@ -149,9 +142,19 @@ public override List<ContextMenuFlyoutItemViewModel> GetItemMenuItems(WidgetCard
149142
new ContextMenuFlyoutItemViewModel()
150143
{
151144
ItemType = ContextMenuFlyoutItemType.Separator,
152-
ShowItem = CommandManager.OpenTerminalFromHome.IsExecutable
145+
ShowItem = CommandManager.OpenTerminalFromHome.IsExecutable ||
146+
CommandManager.OpenStorageSenseFromHome.IsExecutable ||
147+
(options?.ShowFormatDrive ?? false)
153148
},
154149
new ContextMenuFlyoutItemViewModelBuilder(CommandManager.OpenTerminalFromHome).Build(),
150+
new ContextMenuFlyoutItemViewModelBuilder(CommandManager.OpenStorageSenseFromHome).Build(),
151+
new()
152+
{
153+
Text = "FormatDriveText".GetLocalizedResource(),
154+
Command = FormatDriveCommand,
155+
CommandParameter = item,
156+
ShowItem = options?.ShowFormatDrive ?? false
157+
},
155158
new()
156159
{
157160
ItemType = ContextMenuFlyoutItemType.Separator,

0 commit comments

Comments
 (0)