Skip to content

Commit edd6336

Browse files
RichCommand: PermanentlyDelete (#12103)
1 parent 4dcd5e1 commit edd6336

File tree

12 files changed

+84
-113
lines changed

12 files changed

+84
-113
lines changed

specs/RichCommand/CommandList.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ This is the list of all commands defined in `CommandCodes` enum except `None`.
1010
| | ExitCompactOverlay | Exit compact overlay | Exit compact overlay | Ctrl+Alt+Down |
1111
| | ToggleCompactOverlay | Toggle compact overlay | Toggle compact overlay | F12 |
1212
| | Search | Search | Go to search box | Ctrl+F, F3 |
13+
| | Redo | Redo | Redo the last file operation | Ctrl+Y |
14+
| | Undo | Undo | Undo the last file operation | Ctrl+Z |
1315
| Show | ToggleShowHiddenItems | Show hidden items | Toggle whether to show hidden items | Ctrl+H |
1416
| | ToggleShowFileExtensions | Show file extensions | Toggle whether to show file extensions | |
1517
| | TogglePreviewPane | Toggle the preview pane | Toggle whether to show preview pane | Ctrl+P |
@@ -19,7 +21,8 @@ This is the list of all commands defined in `CommandCodes` enum except `None`.
1921
| | CutItem | Cut | Cut item(s) to clipboard | Ctrl+X |
2022
| | PasteItem | Paste | Paste item(s) from clipboard to current folder | Ctrl+V |
2123
| | PasteItemToSelection | Paste | Paste item(s) from clipboard to selected folder | Ctrl+Shift+V |
22-
| | DeleteItem | Delete | Delete item(s) | Delete |
24+
| | DeleteItem | Delete | Delete item(s) | Delete, Ctrl+D |
25+
| | DeletemeItemPermanently | Delete permanently | Delete item(s) permanently | Shift+Delete |
2326
| | CreateFolder | Folder | Create new folder | |
2427
| | CreateShortcut | Create shortcut | Create new shortcut(s) to selected item(s) | |
2528
| | CreateShortcutFromDialog | Shortcut | Create new shortcut to any item | |
@@ -49,6 +52,7 @@ This is the list of all commands defined in `CommandCodes` enum except `None`.
4952
| Run | RunAsAdmin | Run as administrator | Run selected application as administrator | |
5053
| | RunAsAnotherUser | Run as another user | Run selected application as another user | |
5154
| | RunWithPowershell | Run with PowerShell | Run selected PowerShell script | |
55+
| Play | PlayAll | Play all | Play the selected media files | |
5256
| QuickLook | LaunchQuickLook | Launch QuickLook | Launch QuickLook with selected item | Space |
5357
| Archives | CompressIntoArchive | Create archive | Create archive with selected item(s) | |
5458
| | CompressIntoSevenZip | Create _ArchiveName_.7z | Create 7z archive instantly with selected item(s) | |
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using CommunityToolkit.Mvvm.DependencyInjection;
2+
using Files.App.Contexts;
3+
using Files.App.Filesystem;
4+
using Files.App.Helpers;
5+
using Files.Backend.Services.Settings;
6+
using System.ComponentModel;
7+
using System.Linq;
8+
using System.Threading.Tasks;
9+
using Windows.Storage;
10+
11+
namespace Files.App.Actions
12+
{
13+
internal abstract class BaseDeleteAction : BaseUIAction
14+
{
15+
private readonly IFoldersSettingsService settings = Ioc.Default.GetRequiredService<IFoldersSettingsService>();
16+
17+
protected readonly IContentPageContext context = Ioc.Default.GetRequiredService<IContentPageContext>();
18+
19+
public override bool IsExecutable =>
20+
context.HasSelection &&
21+
(!context.ShellPage?.SlimContentPage?.IsRenamingItem ?? false) &&
22+
UIHelpers.CanShowDialog;
23+
24+
public BaseDeleteAction()
25+
{
26+
context.PropertyChanged += Context_PropertyChanged;
27+
}
28+
29+
protected async Task DeleteItems(bool permanently)
30+
{
31+
var items = context.SelectedItems.Select(item => StorageHelpers.FromPathAndType(item.ItemPath,
32+
item.PrimaryItemAttribute is StorageItemTypes.File ? FilesystemItemType.File : FilesystemItemType.Directory));
33+
34+
await context.ShellPage!.FilesystemHelpers.DeleteItemsAsync(items, settings.DeleteConfirmationPolicy, permanently, true);
35+
await context.ShellPage.FilesystemViewModel.ApplyFilesAndFoldersChangesAsync();
36+
}
37+
38+
private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
39+
{
40+
if (e.PropertyName is nameof(IContentPageContext.HasSelection))
41+
OnPropertyChanged(nameof(IsExecutable));
42+
}
43+
}
44+
}
Lines changed: 5 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,11 @@
1-
using CommunityToolkit.Mvvm.DependencyInjection;
2-
using Files.App.Commands;
3-
using Files.App.Contexts;
1+
using Files.App.Commands;
42
using Files.App.Extensions;
5-
using Files.App.Filesystem;
6-
using Files.App.Helpers;
7-
using Files.Backend.Services.Settings;
8-
using System.ComponentModel;
9-
using System.Linq;
103
using System.Threading.Tasks;
11-
using Windows.Storage;
124

135
namespace Files.App.Actions
146
{
15-
internal class DeleteItemAction : BaseUIAction, IAction
7+
internal class DeleteItemAction : BaseDeleteAction, IAction
168
{
17-
private readonly IContentPageContext context = Ioc.Default.GetRequiredService<IContentPageContext>();
18-
19-
private readonly IFoldersSettingsService settings = Ioc.Default.GetRequiredService<IFoldersSettingsService>();
20-
219
public string Label { get; } = "Delete".GetLocalizedResource();
2210

2311
public string Description => "DeleteItemDescription".GetLocalizedResource();
@@ -26,32 +14,11 @@ internal class DeleteItemAction : BaseUIAction, IAction
2614

2715
public HotKey HotKey { get; } = new(Keys.Delete);
2816

29-
public override bool IsExecutable =>
30-
context.HasSelection &&
31-
(!context.ShellPage?.SlimContentPage?.IsRenamingItem ?? false) &&
32-
UIHelpers.CanShowDialog;
33-
34-
public DeleteItemAction()
35-
{
36-
context.PropertyChanged += Context_PropertyChanged;
37-
}
38-
39-
public async Task ExecuteAsync()
40-
{
41-
if (context.ShellPage is null || !IsExecutable)
42-
return;
43-
44-
var items = context.SelectedItems.Select(item => StorageHelpers.FromPathAndType(item.ItemPath,
45-
item.PrimaryItemAttribute is StorageItemTypes.File ? FilesystemItemType.File : FilesystemItemType.Directory));
46-
47-
await context.ShellPage.FilesystemHelpers.DeleteItemsAsync(items, settings.DeleteConfirmationPolicy, false, true);
48-
await context.ShellPage.FilesystemViewModel.ApplyFilesAndFoldersChangesAsync();
49-
}
17+
public HotKey SecondHotKey { get; } = new(Keys.D, KeyModifiers.Ctrl);
5018

51-
private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
19+
public Task ExecuteAsync()
5220
{
53-
if (e.PropertyName is nameof(IContentPageContext.HasSelection))
54-
OnPropertyChanged(nameof(IsExecutable));
21+
return DeleteItems(false);
5522
}
5623
}
5724
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Files.App.Commands;
2+
using Files.App.Extensions;
3+
using System.Threading.Tasks;
4+
5+
namespace Files.App.Actions
6+
{
7+
internal class DeleteItemPermanentlyAction : BaseDeleteAction, IAction
8+
{
9+
public string Label { get; } = "DeletePermanently".GetLocalizedResource();
10+
11+
public string Description { get; } = "DeleteItemPermanentlyDescription".GetLocalizedResource();
12+
13+
public HotKey HotKey { get; } = new(Keys.Delete, KeyModifiers.Shift);
14+
15+
public Task ExecuteAsync()
16+
{
17+
return DeleteItems(true);
18+
}
19+
}
20+
}

src/Files.App/Commands/CommandCodes.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public enum CommandCodes
2727
PasteItem,
2828
PasteItemToSelection,
2929
DeleteItem,
30+
DeleteItemPermanently,
3031
CreateFolder,
3132
CreateShortcut,
3233
CreateShortcutFromDialog,

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ internal class CommandManager : ICommandManager
6161
public IRichCommand PasteItem => commands[CommandCodes.PasteItem];
6262
public IRichCommand PasteItemToSelection => commands[CommandCodes.PasteItemToSelection];
6363
public IRichCommand DeleteItem => commands[CommandCodes.DeleteItem];
64+
public IRichCommand DeleteItemPermanently => commands[CommandCodes.DeleteItemPermanently];
6465
public IRichCommand InstallFont => commands[CommandCodes.InstallFont];
6566
public IRichCommand InstallInfDriver => commands[CommandCodes.InstallInfDriver];
6667
public IRichCommand RunAsAdmin => commands[CommandCodes.RunAsAdmin];
@@ -204,6 +205,7 @@ public CommandManager()
204205
[CommandCodes.PasteItem] = new PasteItemAction(),
205206
[CommandCodes.PasteItemToSelection] = new PasteItemToSelectionAction(),
206207
[CommandCodes.DeleteItem] = new DeleteItemAction(),
208+
[CommandCodes.DeleteItemPermanently] = new DeleteItemPermanentlyAction(),
207209
[CommandCodes.InstallFont] = new InstallFontAction(),
208210
[CommandCodes.InstallInfDriver] = new InstallInfDriverAction(),
209211
[CommandCodes.RunAsAdmin] = new RunAsAdminAction(),

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public interface ICommandManager : IEnumerable<IRichCommand>
2929
IRichCommand PasteItem { get; }
3030
IRichCommand PasteItemToSelection { get; }
3131
IRichCommand DeleteItem { get; }
32+
IRichCommand DeleteItemPermanently { get; }
3233
IRichCommand SelectAll { get; }
3334
IRichCommand InvertSelection { get; }
3435
IRichCommand ClearSelection { get; }

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3178,6 +3178,12 @@
31783178
<data name="ShowCheckboxesWhenSelectingItems" xml:space="preserve">
31793179
<value>Show checkboxes when selecting items</value>
31803180
</data>
3181+
<data name="DeletePermanently" xml:space="preserve">
3182+
<value>Delete permanently</value>
3183+
</data>
3184+
<data name="DeleteItemPermanentlyDescription" xml:space="preserve">
3185+
<value>Delete item(s) permanently</value>
3186+
</data>
31813187
<data name="PlayAllDescription" xml:space="preserve">
31823188
<value>Play the selected media files</value>
31833189
</data>

src/Files.App/Views/ColumnShellPage.xaml

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,26 +35,11 @@
3535
Invoked="KeyboardAccelerator_Invoked"
3636
IsEnabled="{x:Bind IsCurrentInstance, Mode=OneWay}"
3737
Modifiers="Control,Shift" />
38-
<KeyboardAccelerator
39-
Key="Delete"
40-
Invoked="KeyboardAccelerator_Invoked"
41-
IsEnabled="{x:Bind IsCurrentInstance, Mode=OneWay}"
42-
Modifiers="Shift" />
4338
<KeyboardAccelerator
4439
Key="V"
4540
Invoked="KeyboardAccelerator_Invoked"
4641
IsEnabled="{x:Bind IsCurrentInstance, Mode=OneWay}"
4742
Modifiers="Control" />
48-
<KeyboardAccelerator
49-
Key="D"
50-
Invoked="KeyboardAccelerator_Invoked"
51-
IsEnabled="{x:Bind IsCurrentInstance, Mode=OneWay}"
52-
Modifiers="Control" />
53-
<KeyboardAccelerator
54-
Key="R"
55-
Invoked="KeyboardAccelerator_Invoked"
56-
IsEnabled="{x:Bind IsCurrentInstance, Mode=OneWay}"
57-
Modifiers="Control" />
5843
<KeyboardAccelerator
5944
Key="L"
6045
Invoked="KeyboardAccelerator_Invoked"

src/Files.App/Views/ColumnShellPage.xaml.cs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -149,33 +149,11 @@ private async void KeyboardAccelerator_Invoked(KeyboardAccelerator sender, Keybo
149149
this);
150150
}
151151
break;
152-
// Shift + Del, Permanent delete
153-
case (false, true, false, true, VirtualKey.Delete):
154-
if (ContentPage.IsItemSelected && !ToolbarViewModel.IsEditModeEnabled && !InstanceViewModel.IsPageTypeSearchResults)
155-
{
156-
var items = SlimContentPage.SelectedItems.ToList().Select((item) => StorageHelpers.FromPathAndType(
157-
item.ItemPath,
158-
item.PrimaryItemAttribute == StorageItemTypes.File ? FilesystemItemType.File : FilesystemItemType.Directory));
159-
160-
await FilesystemHelpers.DeleteItemsAsync(items, userSettingsService.FoldersSettingsService.DeleteConfirmationPolicy, true, true);
161-
}
162-
break;
163152
// Ctrl + V, Paste
164153
case (true, false, false, true, VirtualKey.V):
165154
if (!ToolbarViewModel.IsEditModeEnabled && !ContentPage.IsRenamingItem && !InstanceViewModel.IsPageTypeSearchResults && !ToolbarViewModel.SearchHasFocus)
166155
await UIFilesystemHelpers.PasteItemAsync(FilesystemViewModel.WorkingDirectory, this);
167156
break;
168-
// Ctrl + D, Delete item
169-
case (true, false, false, true, VirtualKey.D):
170-
if (ContentPage.IsItemSelected && !ContentPage.IsRenamingItem && !InstanceViewModel.IsPageTypeSearchResults)
171-
{
172-
var items = SlimContentPage.SelectedItems.ToList().Select((item) => StorageHelpers.FromPathAndType(
173-
item.ItemPath,
174-
item.PrimaryItemAttribute == StorageItemTypes.File ? FilesystemItemType.File : FilesystemItemType.Directory));
175-
176-
await FilesystemHelpers.DeleteItemsAsync(items, userSettingsService.FoldersSettingsService.DeleteConfirmationPolicy, false, true);
177-
}
178-
break;
179157
// Alt + D, Select address bar (English)
180158
case (false, false, true, true, VirtualKey.D):
181159
// Ctrl + L, Select address bar

0 commit comments

Comments
 (0)