Skip to content

Feature: Add Copy, Cut and Delete RichCommands #11504

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 28, 2023
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
26 changes: 26 additions & 0 deletions src/Files.App/Actions/FileSystem/CopyItemAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using CommunityToolkit.Mvvm.DependencyInjection;
using Files.App.Commands;
using Files.App.Contexts;
using Files.App.Extensions;
using Files.App.Helpers;
using System.Threading.Tasks;
using Windows.System;

namespace Files.App.Actions
{
internal class CopyItemAction : IAction
{
public IContentPageContext context = Ioc.Default.GetRequiredService<IContentPageContext>();

public string Label { get; } = "Copy".GetLocalizedResource();

public HotKey HotKey = new(VirtualKey.C, VirtualKeyModifiers.Control);

public RichGlyph Glyph { get; } = new RichGlyph(opacityStyle: "ColorIconCopy");

public async Task ExecuteAsync()
{
await UIFilesystemHelpers.CopyItem(context.ShellPage);
}
}
}
26 changes: 26 additions & 0 deletions src/Files.App/Actions/FileSystem/CutItemAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using CommunityToolkit.Mvvm.DependencyInjection;
using Files.App.Commands;
using Files.App.Contexts;
using Files.App.Extensions;
using Files.App.Helpers;
using System.Threading.Tasks;
using Windows.System;

namespace Files.App.Actions
{
internal class CutItemAction : IAction
{
public IContentPageContext context = Ioc.Default.GetRequiredService<IContentPageContext>();

public string Label { get; } = "BaseLayoutItemContextFlyoutCut/Text".GetLocalizedResource();

public HotKey HotKey = new(VirtualKey.X, VirtualKeyModifiers.Control);

public RichGlyph Glyph { get; } = new RichGlyph(opacityStyle: "ColorIconCut");

public async Task ExecuteAsync()
{
UIFilesystemHelpers.CutItem(context.ShellPage);
}
}
}
30 changes: 30 additions & 0 deletions src/Files.App/Actions/FileSystem/DeleteItemAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using CommunityToolkit.Mvvm.DependencyInjection;
using Files.App.Commands;
using Files.App.Contexts;
using Files.App.Extensions;
using Files.App.Helpers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.System;

namespace Files.App.Actions
{
internal class DeleteItemAction : IAction
{
public IContentPageContext context = Ioc.Default.GetRequiredService<IContentPageContext>();

public string Label { get; } = "Delete".GetLocalizedResource();

public RichGlyph Glyph { get; } = new RichGlyph(opacityStyle: "ColorIconDelete");

public HotKey HotKey = new(VirtualKey.Delete);

public async Task ExecuteAsync()
{
await RecycleBinHelpers.DeleteItem(context.ShellPage);
}
}
}
3 changes: 3 additions & 0 deletions src/Files.App/Commands/CommandCodes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ public enum CommandCodes
ToggleShowFileExtensions,

// File System
CopyItem,
CutItem,
DeleteItem,
CreateFolder,
CreateShortcut,
CreateShortcutFromDialog,
Expand Down
6 changes: 6 additions & 0 deletions src/Files.App/Commands/Manager/CommandManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ internal class CommandManager : ICommandManager
public IRichCommand UnpinFromStart => commands[CommandCodes.UnpinFromStart];
public IRichCommand PinItemToFavorites => commands[CommandCodes.PinItemToFavorites];
public IRichCommand UnpinItemFromFavorites => commands[CommandCodes.UnpinItemFromFavorites];
public IRichCommand CopyItem => commands[CommandCodes.CopyItem];
public IRichCommand CutItem => commands[CommandCodes.CutItem];
public IRichCommand DeleteItem => commands[CommandCodes.DeleteItem];

public CommandManager()
{
Expand Down Expand Up @@ -83,6 +86,9 @@ public CommandManager()
[CommandCodes.UnpinFromStart] = new UnpinFromStartAction(),
[CommandCodes.PinItemToFavorites] = new PinItemAction(),
[CommandCodes.UnpinItemFromFavorites] = new UnpinItemAction(),
[CommandCodes.CopyItem] = new CopyItemAction(),
[CommandCodes.CutItem] = new CutItemAction(),
[CommandCodes.DeleteItem] = new DeleteItemAction(),
};

[DebuggerDisplay("Command None")]
Expand Down
4 changes: 3 additions & 1 deletion src/Files.App/Commands/Manager/ICommandManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ public interface ICommandManager : IEnumerable<IRichCommand>
IRichCommand ToggleShowHiddenItems { get; }
IRichCommand ToggleShowFileExtensions { get; }

IRichCommand CopyItem { get; }
IRichCommand CutItem { get; }
IRichCommand DeleteItem { get; }
IRichCommand MultiSelect { get; }
IRichCommand SelectAll { get; }
IRichCommand InvertSelection { get; }
IRichCommand ClearSelection { get; }

IRichCommand CreateFolder { get; }
IRichCommand CreateShortcut { get; }
IRichCommand CreateShortcutFromDialog { get; }
Expand Down
67 changes: 9 additions & 58 deletions src/Files.App/Helpers/ContextFlyoutItemHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -749,47 +749,14 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(
ShowInZipPage = true,
ShowItem = itemsSelected
},
new ContextMenuFlyoutItemViewModel()
new ContextMenuFlyoutItemViewModelBuilder(commands.CutItem)
{
Text = "BaseLayoutItemContextFlyoutCut/Text".GetLocalizedResource(),
OpacityIcon = new OpacityIconModel()
{
OpacityIconStyle = "ColorIconCut",
},
Command = commandsViewModel.CutItemCommand,
IsPrimary = true,
KeyboardAccelerator = new KeyboardAccelerator
{
Key = VirtualKey.X,
Modifiers = VirtualKeyModifiers.Control,
IsEnabled = false,
},
ShowInSearchPage = true,
ShowInFtpPage = true,
ShowInZipPage = true,
ShowItem = itemsSelected
},
new ContextMenuFlyoutItemViewModel()
IsVisible = itemsSelected,
}.Build(),
new ContextMenuFlyoutItemViewModelBuilder(commands.CopyItem)
{
Text = "Copy".GetLocalizedResource(),
OpacityIcon = new OpacityIconModel()
{
OpacityIconStyle = "ColorIconCopy",
},
Command = commandsViewModel.CopyItemCommand,
ShowInRecycleBin = true,
ShowInSearchPage = true,
ShowInFtpPage = true,
ShowInZipPage = true,
IsPrimary = true,
KeyboardAccelerator = new KeyboardAccelerator
{
Key = VirtualKey.C,
Modifiers = VirtualKeyModifiers.Control,
IsEnabled = false,
},
ShowItem = itemsSelected
},
IsVisible = itemsSelected,
}.Build(),
new ContextMenuFlyoutItemViewModel()
{
Text = "CopyLocation".GetLocalizedResource(),
Expand Down Expand Up @@ -871,26 +838,10 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(
Command = commandsViewModel.ShareItemCommand,
ShowItem = itemsSelected && DataTransferManager.IsSupported() && !selectedItems.Any(i => i.IsHiddenItem || (i.IsShortcut && !i.IsLinkItem) || (i.PrimaryItemAttribute == StorageItemTypes.Folder && !i.IsArchive)),
},
new ContextMenuFlyoutItemViewModel()
new ContextMenuFlyoutItemViewModelBuilder(commands.DeleteItem)
{
Text = "Delete".GetLocalizedResource(),
IsPrimary = true,
OpacityIcon = new OpacityIconModel()
{
OpacityIconStyle = "ColorIconDelete",
},
Command = commandsViewModel.DeleteItemCommand,
ShowInRecycleBin = true,
ShowInSearchPage = true,
ShowInFtpPage = true,
ShowInZipPage = true,
KeyboardAccelerator = new KeyboardAccelerator
{
Key = VirtualKey.Delete,
IsEnabled = false,
},
ShowItem = itemsSelected
},
IsVisible = itemsSelected,
}.Build(),
new ContextMenuFlyoutItemViewModel()
{
Text = "Properties".GetLocalizedResource(),
Expand Down
15 changes: 0 additions & 15 deletions src/Files.App/Interacts/BaseLayoutCommandImplementationModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,26 +142,11 @@ public virtual async void QuickLook(RoutedEventArgs e)
await QuickLookHelpers.ToggleQuickLook(associatedInstance);
}

public virtual async void CopyItem(RoutedEventArgs e)
{
await UIFilesystemHelpers.CopyItem(associatedInstance);
}

public virtual void CutItem(RoutedEventArgs e)
{
UIFilesystemHelpers.CutItem(associatedInstance);
}

public virtual async void RestoreItem(RoutedEventArgs e)
{
await RecycleBinHelpers.RestoreItem(associatedInstance);
}

public virtual async void DeleteItem(RoutedEventArgs e)
{
await RecycleBinHelpers.DeleteItem(associatedInstance);
}

public virtual void ShowFolderProperties(RoutedEventArgs e)
=> ShowProperties(e);

Expand Down
13 changes: 0 additions & 13 deletions src/Files.App/Interacts/BaseLayoutCommandsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ private void InitializeCommands()
RestoreRecycleBinCommand = new RelayCommand<RoutedEventArgs>(CommandsModel.RestoreRecycleBin);
RestoreSelectionRecycleBinCommand = new RelayCommand<RoutedEventArgs>(CommandsModel.RestoreSelectionRecycleBin);
QuickLookCommand = new RelayCommand<RoutedEventArgs>(CommandsModel.QuickLook);
CopyItemCommand = new RelayCommand<RoutedEventArgs>(CommandsModel.CopyItem);
CutItemCommand = new RelayCommand<RoutedEventArgs>(CommandsModel.CutItem);
RestoreItemCommand = new RelayCommand<RoutedEventArgs>(CommandsModel.RestoreItem);
DeleteItemCommand = new RelayCommand<RoutedEventArgs>(CommandsModel.DeleteItem);
ShowFolderPropertiesCommand = new RelayCommand<RoutedEventArgs>(CommandsModel.ShowFolderProperties);
ShowPropertiesCommand = new RelayCommand<RoutedEventArgs>(CommandsModel.ShowProperties);
OpenFileLocationCommand = new RelayCommand<RoutedEventArgs>(CommandsModel.OpenFileLocation);
Expand Down Expand Up @@ -92,10 +89,6 @@ private void InitializeCommands()

public ICommand RunAsAnotherUserCommand { get; private set; }

public ICommand SidebarPinItemCommand { get; private set; }

public ICommand SidebarUnpinItemCommand { get; private set; }

public ICommand OpenItemCommand { get; private set; }

public ICommand RestoreRecycleBinCommand { get; private set; }
Expand All @@ -104,14 +97,8 @@ private void InitializeCommands()

public ICommand QuickLookCommand { get; private set; }

public ICommand CopyItemCommand { get; private set; }

public ICommand CutItemCommand { get; private set; }

public ICommand RestoreItemCommand { get; private set; }

public ICommand DeleteItemCommand { get; private set; }

public ICommand ShowFolderPropertiesCommand { get; private set; }

public ICommand ShowPropertiesCommand { get; private set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,8 @@ public interface IBaseLayoutCommandImplementationModel : IDisposable

void QuickLook(RoutedEventArgs e);

void CopyItem(RoutedEventArgs e);

void CutItem(RoutedEventArgs e);

void RestoreItem(RoutedEventArgs e);

void DeleteItem(RoutedEventArgs e);

void ShowFolderProperties(RoutedEventArgs e);

void ShowProperties(RoutedEventArgs e);
Expand Down
9 changes: 6 additions & 3 deletions src/Files.App/Views/BaseShellPage.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using CommunityToolkit.Mvvm.DependencyInjection;
using CommunityToolkit.Mvvm.Input;
using CommunityToolkit.WinUI;
using Files.App.Commands;
using Files.App.DataModels;
using Files.App.EventArguments;
using Files.App.Extensions;
Expand Down Expand Up @@ -30,6 +31,7 @@
using System.Diagnostics;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Security.Policy;
using System.Threading;
using System.Threading.Tasks;
using Windows.Storage;
Expand Down Expand Up @@ -60,6 +62,7 @@ public abstract class BaseShellPage : Page, IShellPage, INotifyPropertyChanged

public IBaseLayout SlimContentPage => ContentPage;

public ICommandManager commands = Ioc.Default.GetRequiredService<ICommandManager>();
public IFilesystemHelpers FilesystemHelpers { get; protected set; }

public Type CurrentPageType => ItemDisplay.SourcePageType;
Expand Down Expand Up @@ -630,11 +633,11 @@ protected void InitToolbarCommands()
ToolbarViewModel.CreateNewFileCommand = new RelayCommand<ShellNewEntry>(x => UIFilesystemHelpers.CreateFileFromDialogResultType(AddItemDialogItemType.File, x, this));
ToolbarViewModel.CreateNewFolderCommand = new RelayCommand(() => UIFilesystemHelpers.CreateFileFromDialogResultType(AddItemDialogItemType.Folder, null, this));
ToolbarViewModel.CreateNewShortcutCommand = new RelayCommand(() => CreateNewShortcutFromDialog());
ToolbarViewModel.CopyCommand = new RelayCommand(async () => await UIFilesystemHelpers.CopyItem(this));
ToolbarViewModel.CopyCommand = new RelayCommand(async () => commands.CopyItem.Execute(null));
ToolbarViewModel.Rename = new RelayCommand(() => SlimContentPage?.CommandsViewModel.RenameItemCommand.Execute(null));
ToolbarViewModel.Share = new RelayCommand(() => SlimContentPage?.CommandsViewModel.ShareItemCommand.Execute(null));
ToolbarViewModel.DeleteCommand = new RelayCommand(() => SlimContentPage?.CommandsViewModel.DeleteItemCommand.Execute(null));
ToolbarViewModel.CutCommand = new RelayCommand(() => SlimContentPage?.CommandsViewModel.CutItemCommand.Execute(null));
ToolbarViewModel.DeleteCommand = new RelayCommand(() => commands.DeleteItem.Execute(null));
ToolbarViewModel.CutCommand = new RelayCommand(() => commands.CutItem.Execute(null));
ToolbarViewModel.RestoreRecycleBinCommand = new RelayCommand(() => SlimContentPage?.CommandsViewModel.RestoreRecycleBinCommand.Execute(null));
ToolbarViewModel.RestoreSelectionRecycleBinCommand = new RelayCommand(() => SlimContentPage?.CommandsViewModel.RestoreSelectionRecycleBinCommand.Execute(null));
ToolbarViewModel.RunWithPowerShellCommand = new RelayCommand(async () => await Win32Helpers.InvokeWin32ComponentAsync("powershell", this, PathNormalization.NormalizePath(SlimContentPage?.SelectedItem.ItemPath)));
Expand Down