Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions src/Files.App/Actions/Open/OpenStorageSenseAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright (c) 2024 Files Community
// Licensed under the MIT License. See the LICENSE.

namespace Files.App.Actions
{
internal class OpenStorageSenseAction : ObservableObject, IAction
{
private readonly IContentPageContext context = Ioc.Default.GetRequiredService<IContentPageContext>();
private readonly DrivesViewModel drivesViewModel = Ioc.Default.GetRequiredService<DrivesViewModel>();

public virtual string Label
=> Strings.Cleanup.GetLocalizedResource();

public virtual string Description
=> Strings.OpenStorageSenseDescription.GetLocalizedResource();

public virtual bool IsExecutable =>
context.HasItem &&
!context.HasSelection &&
drivesViewModel.Drives
.Cast<DriveItem>()
.FirstOrDefault(x => string.Equals(x.Path, context.Folder?.ItemPath)) is DriveItem driveItem &&
driveItem.Type != DriveType.Network;

public virtual bool IsAccessibleGlobally
=> true;

public OpenStorageSenseAction()
{
context.PropertyChanged += Context_PropertyChanged;
}

public virtual Task ExecuteAsync(object? parameter = null)
{
return StorageSenseHelper.OpenStorageSenseAsync(context.Folder?.ItemPath ?? string.Empty);
}

public void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName is nameof(IContentPageContext.HasItem))
OnPropertyChanged(nameof(IsExecutable));
}
}
}
28 changes: 28 additions & 0 deletions src/Files.App/Actions/Open/OpenStorageSenseFromHomeAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) 2024 Files Community
// Licensed under the MIT License. See the LICENSE.

namespace Files.App.Actions
{
internal sealed class OpenStorageSenseFromHomeAction : OpenStorageSenseAction
{
private IHomePageContext HomePageContext { get; } = Ioc.Default.GetRequiredService<IHomePageContext>();
private readonly DrivesViewModel drivesViewModel = Ioc.Default.GetRequiredService<DrivesViewModel>();

public override bool IsExecutable =>
HomePageContext.IsAnyItemRightClicked &&
HomePageContext.RightClickedItem is not null &&
HomePageContext.RightClickedItem.Path is not null &&
drivesViewModel.Drives
.Cast<DriveItem>()
.FirstOrDefault(x => string.Equals(x.Path, HomePageContext.RightClickedItem.Path)) is DriveItem driveItem &&
driveItem.Type != DriveType.Network;

public override bool IsAccessibleGlobally
=> false;

public override Task ExecuteAsync(object? parameter = null)
{
return StorageSenseHelper.OpenStorageSenseAsync(HomePageContext?.RightClickedItem?.Path ?? string.Empty);
}
}
}
28 changes: 28 additions & 0 deletions src/Files.App/Actions/Open/OpenStorageSenseFromSidebarAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) 2024 Files Community
// Licensed under the MIT License. See the LICENSE.

namespace Files.App.Actions
{
internal sealed class OpenStorageSenseFromSidebarAction : OpenStorageSenseAction
{
private ISidebarContext SidebarContext { get; } = Ioc.Default.GetRequiredService<ISidebarContext>();
private readonly DrivesViewModel drivesViewModel = Ioc.Default.GetRequiredService<DrivesViewModel>();

public override bool IsExecutable =>
SidebarContext.IsItemRightClicked &&
SidebarContext.RightClickedItem is not null &&
SidebarContext.RightClickedItem.Path is not null &&
drivesViewModel.Drives
.Cast<DriveItem>()
.FirstOrDefault(x => string.Equals(x.Path, SidebarContext.RightClickedItem.Path)) is DriveItem driveItem &&
driveItem.Type != DriveType.Network;

public override bool IsAccessibleGlobally
=> false;

public override Task ExecuteAsync(object? parameter = null)
{
return StorageSenseHelper.OpenStorageSenseAsync(SidebarContext?.RightClickedItem?.Path ?? string.Empty);
}
}
}
3 changes: 3 additions & 0 deletions src/Files.App/Data/Commands/Manager/CommandCodes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ public enum CommandCodes
OpenProperties,
OpenClassicProperties,
OpenSettings,
OpenStorageSense,
OpenStorageSenseFromHome,
OpenStorageSenseFromSidebar,
OpenTerminal,
OpenTerminalAsAdmin,
OpenTerminalFromSidebar,
Expand Down
6 changes: 6 additions & 0 deletions src/Files.App/Data/Commands/Manager/CommandManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ public IRichCommand this[HotKey hotKey]
public IRichCommand OpenRepoInVSCode => commands[CommandCodes.OpenRepoInVSCode];
public IRichCommand OpenProperties => commands[CommandCodes.OpenProperties];
public IRichCommand OpenClassicProperties => commands[CommandCodes.OpenClassicProperties];
public IRichCommand OpenStorageSense => commands[CommandCodes.OpenStorageSense];
public IRichCommand OpenStorageSenseFromHome => commands[CommandCodes.OpenStorageSenseFromHome];
public IRichCommand OpenStorageSenseFromSidebar => commands[CommandCodes.OpenStorageSenseFromSidebar];
public IRichCommand OpenSettings => commands[CommandCodes.OpenSettings];
public IRichCommand OpenTerminal => commands[CommandCodes.OpenTerminal];
public IRichCommand OpenTerminalAsAdmin => commands[CommandCodes.OpenTerminalAsAdmin];
Expand Down Expand Up @@ -313,6 +316,9 @@ public IEnumerator<IRichCommand> GetEnumerator() =>
[CommandCodes.OpenRepoInVSCode] = new OpenRepoInVSCodeAction(),
[CommandCodes.OpenProperties] = new OpenPropertiesAction(),
[CommandCodes.OpenClassicProperties] = new OpenClassicPropertiesAction(),
[CommandCodes.OpenStorageSense] = new OpenStorageSenseAction(),
[CommandCodes.OpenStorageSenseFromHome] = new OpenStorageSenseFromHomeAction(),
[CommandCodes.OpenStorageSenseFromSidebar] = new OpenStorageSenseFromSidebarAction(),
[CommandCodes.OpenSettings] = new OpenSettingsAction(),
[CommandCodes.OpenTerminal] = new OpenTerminalAction(),
[CommandCodes.OpenTerminalAsAdmin] = new OpenTerminalAsAdminAction(),
Expand Down
3 changes: 3 additions & 0 deletions src/Files.App/Data/Commands/Manager/ICommandManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ public interface ICommandManager : IEnumerable<IRichCommand>
IRichCommand OpenRepoInVSCode { get; }
IRichCommand OpenProperties { get; }
IRichCommand OpenClassicProperties { get; }
IRichCommand OpenStorageSense { get; }
IRichCommand OpenStorageSenseFromHome { get; }
IRichCommand OpenStorageSenseFromSidebar { get; }
IRichCommand OpenSettings { get; }
IRichCommand OpenTerminal { get; }
IRichCommand OpenTerminalAsAdmin { get; }
Expand Down
10 changes: 7 additions & 3 deletions src/Files.App/Data/Factories/ContentPageContextFlyoutFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,6 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(
ShowItem = !itemsSelected,
ShowInFtpPage = true
},
new ContextMenuFlyoutItemViewModelBuilder(Commands.FormatDrive).Build(),
new ContextMenuFlyoutItemViewModelBuilder(Commands.EmptyRecycleBin)
{
IsVisible = currentInstanceViewModel.IsPageTypeRecycleBin && !itemsSelected,
Expand Down Expand Up @@ -598,12 +597,17 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(
new ContextMenuFlyoutItemViewModel()
{
ItemType = ContextMenuFlyoutItemType.Separator,
ShowItem = !itemsSelected && Commands.OpenTerminal.IsExecutable || areAllItemsFolders && Commands.OpenTerminal.IsExecutable
ShowItem = (!itemsSelected && Commands.OpenTerminal.IsExecutable) ||
(areAllItemsFolders && Commands.OpenTerminal.IsExecutable) ||
Commands.OpenStorageSense.IsExecutable ||
Commands.FormatDrive.IsExecutable
},
new ContextMenuFlyoutItemViewModelBuilder(Commands.OpenTerminal)
{
IsVisible = !itemsSelected && Commands.OpenTerminal.IsExecutable || areAllItemsFolders && Commands.OpenTerminal.IsExecutable
IsVisible = (!itemsSelected && Commands.OpenTerminal.IsExecutable) || (areAllItemsFolders && Commands.OpenTerminal.IsExecutable)
}.Build(),
new ContextMenuFlyoutItemViewModelBuilder(Commands.OpenStorageSense).Build(),
new ContextMenuFlyoutItemViewModelBuilder(Commands.FormatDrive).Build(),
// Shell extensions are not available on the FTP server or in the archive,
// but following items are intentionally added because icons in the context menu will not appear
// unless there is at least one menu item with an icon that is not an ThemedIconModel. (#12943)
Expand Down
8 changes: 7 additions & 1 deletion src/Files.App/Strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -1244,6 +1244,12 @@
<data name="OpenStorageSense" xml:space="preserve">
<value>Open Storage Sense</value>
</data>
<data name="OpenStorageSenseDescription" xml:space="preserve">
<value>Open the Storage Sense page in Windows Settings</value>
</data>
<data name="Cleanup" xml:space="preserve">
<value>Cleanup</value>
</data>
<data name="Copy" xml:space="preserve">
<value>Copy</value>
</data>
Expand Down Expand Up @@ -2274,7 +2280,7 @@
<value>Show hidden items</value>
</data>
<data name="FormatDriveText" xml:space="preserve">
<value>Format...</value>
<value>Format</value>
</data>
<data name="Help" xml:space="preserve">
<value>Help</value>
Expand Down
24 changes: 12 additions & 12 deletions src/Files.App/ViewModels/UserControls/SidebarViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using Files.App.Helpers.ContextFlyouts;
using Files.App.UserControls.Sidebar;
using Files.App.ViewModels.Dialogs;
using Microsoft.UI.Input;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
Expand All @@ -12,13 +11,11 @@
using System.Collections.Specialized;
using System.IO;
using System.Windows.Input;
using Windows.ApplicationModel.DataTransfer.DragDrop;
using Windows.ApplicationModel.DataTransfer;
using Windows.ApplicationModel.DataTransfer.DragDrop;
using Windows.Storage;
using Windows.System;
using Windows.UI.Core;
using Files.Core.Storage;
using Files.Core.Storage.Extensions;

namespace Files.App.ViewModels.UserControls
{
Expand Down Expand Up @@ -1046,13 +1043,6 @@ private List<ContextMenuFlyoutItemViewModel> GetLocationItemMenuItems(INavigatio
ShowItem = options.ShowEjectDevice
},
new ContextMenuFlyoutItemViewModel()
{
Text = "FormatDriveText".GetLocalizedResource(),
Command = FormatDriveCommand,
CommandParameter = item,
ShowItem = options.ShowFormatDrive
},
new ContextMenuFlyoutItemViewModel()
{
Text = "Properties".GetLocalizedResource(),
ThemedIconModel = new ThemedIconModel()
Expand All @@ -1066,9 +1056,19 @@ private List<ContextMenuFlyoutItemViewModel> GetLocationItemMenuItems(INavigatio
new ContextMenuFlyoutItemViewModel()
{
ItemType = ContextMenuFlyoutItemType.Separator,
ShowItem = Commands.OpenTerminalFromSidebar.IsExecutable
ShowItem = Commands.OpenTerminalFromSidebar.IsExecutable ||
Commands.OpenStorageSenseFromSidebar.IsExecutable ||
options.ShowFormatDrive
},
new ContextMenuFlyoutItemViewModelBuilder(Commands.OpenTerminalFromSidebar).Build(),
new ContextMenuFlyoutItemViewModelBuilder(Commands.OpenStorageSenseFromSidebar).Build(),
new ContextMenuFlyoutItemViewModel()
{
Text = Strings.FormatDriveText.GetLocalizedResource(),
Command = FormatDriveCommand,
CommandParameter = item,
ShowItem = options.ShowFormatDrive
},
new ContextMenuFlyoutItemViewModel()
{
ItemType = ContextMenuFlyoutItemType.Separator,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,6 @@ public override List<ContextMenuFlyoutItemViewModel> GetItemMenuItems(WidgetCard
ShowItem = options?.ShowEjectDevice ?? false
},
new()
{
Text = "FormatDriveText".GetLocalizedResource(),
Command = FormatDriveCommand,
CommandParameter = item,
ShowItem = options?.ShowFormatDrive ?? false
},
new()
{
Text = "Properties".GetLocalizedResource(),
ThemedIconModel = new ThemedIconModel() { ThemedIconStyle = "App.ThemedIcons.Properties" },
Expand All @@ -149,9 +142,19 @@ public override List<ContextMenuFlyoutItemViewModel> GetItemMenuItems(WidgetCard
new ContextMenuFlyoutItemViewModel()
{
ItemType = ContextMenuFlyoutItemType.Separator,
ShowItem = CommandManager.OpenTerminalFromHome.IsExecutable
ShowItem = CommandManager.OpenTerminalFromHome.IsExecutable ||
CommandManager.OpenStorageSenseFromHome.IsExecutable ||
(options?.ShowFormatDrive ?? false)
},
new ContextMenuFlyoutItemViewModelBuilder(CommandManager.OpenTerminalFromHome).Build(),
new ContextMenuFlyoutItemViewModelBuilder(CommandManager.OpenStorageSenseFromHome).Build(),
new()
{
Text = "FormatDriveText".GetLocalizedResource(),
Command = FormatDriveCommand,
CommandParameter = item,
ShowItem = options?.ShowFormatDrive ?? false
},
new()
{
ItemType = ContextMenuFlyoutItemType.Separator,
Expand Down
Loading