Skip to content

Commit f533e8e

Browse files
committed
Merge branch '5bfa/integrate-securityadv' of https://github.com/0x5bfa/Files into 5bfa/integrate-securityadv
2 parents 82fe9c4 + a41dfd2 commit f533e8e

37 files changed

+598
-503
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: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using CommunityToolkit.Mvvm.ComponentModel;
2+
using CommunityToolkit.Mvvm.DependencyInjection;
3+
using Files.App.Commands;
4+
using Files.App.Contexts;
5+
using Files.App.Extensions;
6+
using Files.App.Helpers;
7+
using Files.Backend.Helpers;
8+
using System.ComponentModel;
9+
using System.Linq;
10+
using System.Threading.Tasks;
11+
12+
namespace Files.App.Actions
13+
{
14+
internal class PlayAllAction : ObservableObject, IAction
15+
{
16+
private readonly IContentPageContext context = Ioc.Default.GetRequiredService<IContentPageContext>();
17+
18+
public string Label { get; } = "PlayAll".GetLocalizedResource();
19+
20+
public string Description { get; } = "PlayAllDescription".GetLocalizedResource();
21+
22+
public RichGlyph Glyph { get; } = new("\uE768");
23+
24+
public bool IsExecutable => context.PageType is not ContentPageTypes.RecycleBin &&
25+
context.SelectedItems.Count > 1 &&
26+
context.SelectedItems.All(item => FileExtensionHelpers.IsMediaFile(item.FileExtension));
27+
28+
public PlayAllAction()
29+
{
30+
context.PropertyChanged += Context_PropertyChanged;
31+
}
32+
33+
public Task ExecuteAsync()
34+
{
35+
return NavigationHelpers.OpenSelectedItems(context.ShellPage!);
36+
}
37+
38+
private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
39+
{
40+
switch (e.PropertyName)
41+
{
42+
case nameof(IContentPageContext.PageType):
43+
case nameof(IContentPageContext.SelectedItems):
44+
OnPropertyChanged(nameof(IsExecutable));
45+
break;
46+
}
47+
}
48+
}
49+
}
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+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using CommunityToolkit.Mvvm.ComponentModel;
2+
using CommunityToolkit.Mvvm.DependencyInjection;
3+
using Files.App.Commands;
4+
using Files.App.Contexts;
5+
using Files.App.Extensions;
6+
using System.ComponentModel;
7+
using System.Threading.Tasks;
8+
9+
namespace Files.App.Actions
10+
{
11+
internal class RedoAction : ObservableObject, IAction
12+
{
13+
private readonly IContentPageContext context = Ioc.Default.GetRequiredService<IContentPageContext>();
14+
15+
public string Label { get; } = "Redo".GetLocalizedResource();
16+
17+
public string Description { get; } = "RedoDescription".GetLocalizedResource();
18+
19+
public HotKey HotKey { get; } = new(Keys.Y, KeyModifiers.Ctrl);
20+
21+
public bool IsExecutable => context.ShellPage is not null &&
22+
context.PageType is not ContentPageTypes.SearchResults;
23+
24+
public RedoAction()
25+
{
26+
context.PropertyChanged += Context_PropertyChanged;
27+
}
28+
29+
public Task ExecuteAsync()
30+
{
31+
return context.ShellPage!.StorageHistoryHelpers.TryRedo();
32+
}
33+
34+
private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
35+
{
36+
switch (e.PropertyName)
37+
{
38+
case nameof(IContentPageContext.ShellPage):
39+
case nameof(IContentPageContext.PageType):
40+
OnPropertyChanged(nameof(IsExecutable));
41+
break;
42+
}
43+
}
44+
}
45+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using CommunityToolkit.Mvvm.ComponentModel;
2+
using CommunityToolkit.Mvvm.DependencyInjection;
3+
using Files.App.Commands;
4+
using Files.App.Contexts;
5+
using Files.App.Extensions;
6+
using System.ComponentModel;
7+
using System.Threading.Tasks;
8+
9+
namespace Files.App.Actions
10+
{
11+
internal class UndoAction : ObservableObject, IAction
12+
{
13+
private readonly IContentPageContext context = Ioc.Default.GetRequiredService<IContentPageContext>();
14+
15+
public string Label { get; } = "Undo".GetLocalizedResource();
16+
17+
public string Description { get; } = "UndoDescription".GetLocalizedResource();
18+
19+
public HotKey HotKey { get; } = new(Keys.Z, KeyModifiers.Ctrl);
20+
21+
public bool IsExecutable => context.ShellPage is not null &&
22+
context.PageType is not ContentPageTypes.SearchResults;
23+
24+
public UndoAction()
25+
{
26+
context.PropertyChanged += Context_PropertyChanged;
27+
}
28+
29+
public Task ExecuteAsync()
30+
{
31+
return context.ShellPage.StorageHistoryHelpers.TryUndo();
32+
}
33+
34+
private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
35+
{
36+
switch (e.PropertyName)
37+
{
38+
case nameof(IContentPageContext.ShellPage):
39+
case nameof(IContentPageContext.PageType):
40+
OnPropertyChanged(nameof(IsExecutable));
41+
break;
42+
}
43+
}
44+
}
45+
}

src/Files.App/Commands/CommandCodes.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ public enum CommandCodes
1111
ExitCompactOverlay,
1212
ToggleCompactOverlay,
1313
Search,
14+
Redo,
15+
Undo,
1416

1517
// Show
1618
ToggleShowHiddenItems,
@@ -25,6 +27,7 @@ public enum CommandCodes
2527
PasteItem,
2628
PasteItemToSelection,
2729
DeleteItem,
30+
DeleteItemPermanently,
2831
CreateFolder,
2932
CreateShortcut,
3033
CreateShortcutFromDialog,
@@ -152,5 +155,8 @@ public enum CommandCodes
152155
CloseSelectedTab,
153156
OpenNewPane,
154157
ClosePane,
158+
159+
// Play
160+
PlayAll,
155161
}
156162
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ internal class CommandManager : ICommandManager
2929
public IRichCommand ExitCompactOverlay => commands[CommandCodes.ExitCompactOverlay];
3030
public IRichCommand ToggleCompactOverlay => commands[CommandCodes.ToggleCompactOverlay];
3131
public IRichCommand Search => commands[CommandCodes.Search];
32+
public IRichCommand Redo => commands[CommandCodes.Redo];
33+
public IRichCommand Undo => commands[CommandCodes.Undo];
3234
public IRichCommand ToggleShowHiddenItems => commands[CommandCodes.ToggleShowHiddenItems];
3335
public IRichCommand ToggleShowFileExtensions => commands[CommandCodes.ToggleShowFileExtensions];
3436
public IRichCommand TogglePreviewPane => commands[CommandCodes.TogglePreviewPane];
@@ -59,6 +61,7 @@ internal class CommandManager : ICommandManager
5961
public IRichCommand PasteItem => commands[CommandCodes.PasteItem];
6062
public IRichCommand PasteItemToSelection => commands[CommandCodes.PasteItemToSelection];
6163
public IRichCommand DeleteItem => commands[CommandCodes.DeleteItem];
64+
public IRichCommand DeleteItemPermanently => commands[CommandCodes.DeleteItemPermanently];
6265
public IRichCommand InstallFont => commands[CommandCodes.InstallFont];
6366
public IRichCommand InstallInfDriver => commands[CommandCodes.InstallInfDriver];
6467
public IRichCommand RunAsAdmin => commands[CommandCodes.RunAsAdmin];
@@ -134,6 +137,7 @@ internal class CommandManager : ICommandManager
134137
public IRichCommand CloseSelectedTab => commands[CommandCodes.CloseSelectedTab];
135138
public IRichCommand OpenNewPane => commands[CommandCodes.OpenNewPane];
136139
public IRichCommand ClosePane => commands[CommandCodes.ClosePane];
140+
public IRichCommand PlayAll => commands[CommandCodes.PlayAll];
137141

138142
public CommandManager()
139143
{
@@ -169,6 +173,8 @@ public CommandManager()
169173
[CommandCodes.ExitCompactOverlay] = new ExitCompactOverlayAction(),
170174
[CommandCodes.ToggleCompactOverlay] = new ToggleCompactOverlayAction(),
171175
[CommandCodes.Search] = new SearchAction(),
176+
[CommandCodes.Redo] = new RedoAction(),
177+
[CommandCodes.Undo] = new UndoAction(),
172178
[CommandCodes.ToggleShowHiddenItems] = new ToggleShowHiddenItemsAction(),
173179
[CommandCodes.ToggleShowFileExtensions] = new ToggleShowFileExtensionsAction(),
174180
[CommandCodes.TogglePreviewPane] = new TogglePreviewPaneAction(),
@@ -199,6 +205,7 @@ public CommandManager()
199205
[CommandCodes.PasteItem] = new PasteItemAction(),
200206
[CommandCodes.PasteItemToSelection] = new PasteItemToSelectionAction(),
201207
[CommandCodes.DeleteItem] = new DeleteItemAction(),
208+
[CommandCodes.DeleteItemPermanently] = new DeleteItemPermanentlyAction(),
202209
[CommandCodes.InstallFont] = new InstallFontAction(),
203210
[CommandCodes.InstallInfDriver] = new InstallInfDriverAction(),
204211
[CommandCodes.RunAsAdmin] = new RunAsAdminAction(),
@@ -274,6 +281,7 @@ public CommandManager()
274281
[CommandCodes.CloseSelectedTab] = new CloseSelectedTabAction(),
275282
[CommandCodes.OpenNewPane] = new OpenNewPaneAction(),
276283
[CommandCodes.ClosePane] = new ClosePaneAction(),
284+
[CommandCodes.PlayAll] = new PlayAllAction(),
277285
};
278286

279287
[DebuggerDisplay("Command None")]

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ public interface ICommandManager : IEnumerable<IRichCommand>
1515
IRichCommand ExitCompactOverlay { get; }
1616
IRichCommand ToggleCompactOverlay { get; }
1717
IRichCommand Search { get; }
18+
IRichCommand Redo { get; }
19+
IRichCommand Undo { get; }
1820

1921
IRichCommand ToggleShowHiddenItems { get; }
2022
IRichCommand ToggleShowFileExtensions { get; }
@@ -27,6 +29,7 @@ public interface ICommandManager : IEnumerable<IRichCommand>
2729
IRichCommand PasteItem { get; }
2830
IRichCommand PasteItemToSelection { get; }
2931
IRichCommand DeleteItem { get; }
32+
IRichCommand DeleteItemPermanently { get; }
3033
IRichCommand SelectAll { get; }
3134
IRichCommand InvertSelection { get; }
3235
IRichCommand ClearSelection { get; }
@@ -135,5 +138,7 @@ public interface ICommandManager : IEnumerable<IRichCommand>
135138
IRichCommand CloseSelectedTab { get; }
136139
IRichCommand OpenNewPane { get; }
137140
IRichCommand ClosePane { get; }
141+
142+
IRichCommand PlayAll { get; }
138143
}
139144
}

0 commit comments

Comments
 (0)