Skip to content

Commit a117ff3

Browse files
RichCommands: Redo/Undo & PlayAll (#12017)
1 parent cc243ef commit a117ff3

18 files changed

+180
-65
lines changed
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: 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: 5 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,
@@ -152,5 +154,8 @@ public enum CommandCodes
152154
CloseSelectedTab,
153155
OpenNewPane,
154156
ClosePane,
157+
158+
// Play
159+
PlayAll,
155160
}
156161
}

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

Lines changed: 6 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];
@@ -134,6 +136,7 @@ internal class CommandManager : ICommandManager
134136
public IRichCommand CloseSelectedTab => commands[CommandCodes.CloseSelectedTab];
135137
public IRichCommand OpenNewPane => commands[CommandCodes.OpenNewPane];
136138
public IRichCommand ClosePane => commands[CommandCodes.ClosePane];
139+
public IRichCommand PlayAll => commands[CommandCodes.PlayAll];
137140

138141
public CommandManager()
139142
{
@@ -169,6 +172,8 @@ public CommandManager()
169172
[CommandCodes.ExitCompactOverlay] = new ExitCompactOverlayAction(),
170173
[CommandCodes.ToggleCompactOverlay] = new ToggleCompactOverlayAction(),
171174
[CommandCodes.Search] = new SearchAction(),
175+
[CommandCodes.Redo] = new RedoAction(),
176+
[CommandCodes.Undo] = new UndoAction(),
172177
[CommandCodes.ToggleShowHiddenItems] = new ToggleShowHiddenItemsAction(),
173178
[CommandCodes.ToggleShowFileExtensions] = new ToggleShowFileExtensionsAction(),
174179
[CommandCodes.TogglePreviewPane] = new TogglePreviewPaneAction(),
@@ -274,6 +279,7 @@ public CommandManager()
274279
[CommandCodes.CloseSelectedTab] = new CloseSelectedTabAction(),
275280
[CommandCodes.OpenNewPane] = new OpenNewPaneAction(),
276281
[CommandCodes.ClosePane] = new ClosePaneAction(),
282+
[CommandCodes.PlayAll] = new PlayAllAction(),
277283
};
278284

279285
[DebuggerDisplay("Command None")]

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

Lines changed: 4 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; }
@@ -135,5 +137,7 @@ public interface ICommandManager : IEnumerable<IRichCommand>
135137
IRichCommand CloseSelectedTab { get; }
136138
IRichCommand OpenNewPane { get; }
137139
IRichCommand ClosePane { get; }
140+
141+
IRichCommand PlayAll { get; }
138142
}
139143
}

src/Files.App/IShellPage.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Files.App.Filesystem;
2+
using Files.App.Filesystem.FilesystemHistory;
23
using Files.App.UserControls.MultitaskingControl;
34
using Files.App.ViewModels;
45
using Files.App.Views;
@@ -13,6 +14,8 @@ public interface IShellPage : ITabItemContent, IMultiPaneInfo, IDisposable, INot
1314

1415
CurrentInstanceViewModel InstanceViewModel { get; }
1516

17+
StorageHistoryHelpers StorageHistoryHelpers { get; }
18+
1619
IBaseLayout SlimContentPage { get; }
1720

1821
Type CurrentPageType { get; }

src/Files.App/Interacts/BaseLayoutCommandImplementationModel.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using Files.App.Filesystem.StorageItems;
88
using Files.App.Helpers;
99
using Files.App.ServicesImplementation;
10-
using Files.App.Shell;
1110
using Files.App.ViewModels;
1211
using Files.App.Views;
1312
using Files.Backend.Enums;
@@ -298,11 +297,6 @@ public async Task CreateFolderWithSelection(RoutedEventArgs e)
298297
await UIFilesystemHelpers.CreateFolderWithSelectionAsync(associatedInstance);
299298
}
300299

301-
public async Task PlayAll()
302-
{
303-
await NavigationHelpers.OpenSelectedItems(associatedInstance);
304-
}
305-
306300
#endregion Command Implementation
307301
}
308302
}

src/Files.App/Interacts/BaseLayoutCommandsViewModel.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using CommunityToolkit.Mvvm.Input;
2-
using Files.App.Filesystem;
32
using Files.Shared;
43
using Microsoft.UI.Xaml;
54
using Microsoft.UI.Xaml.Input;
@@ -39,7 +38,6 @@ private void InitializeCommands()
3938
DropCommand = new AsyncRelayCommand<DragEventArgs>(CommandsModel.Drop);
4039
SearchUnindexedItems = new RelayCommand<RoutedEventArgs>(CommandsModel.SearchUnindexedItems);
4140
CreateFolderWithSelection = new AsyncRelayCommand<RoutedEventArgs>(CommandsModel.CreateFolderWithSelection);
42-
PlayAllCommand = new AsyncRelayCommand(CommandsModel.PlayAll);
4341
}
4442

4543
#endregion Command Initialization
@@ -70,8 +68,6 @@ private void InitializeCommands()
7068

7169
public ICommand CreateFolderWithSelection { get; private set; }
7270

73-
public ICommand PlayAllCommand { get; private set; }
74-
7571
#endregion Commands
7672

7773
#region IDisposable

src/Files.App/Interacts/IBaseLayoutCommandImplementationModel.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using Files.App.Filesystem;
21
using Files.Shared;
32
using Microsoft.UI.Xaml;
43
using Microsoft.UI.Xaml.Input;
@@ -32,7 +31,5 @@ public interface IBaseLayoutCommandImplementationModel : IDisposable
3231
void SearchUnindexedItems(RoutedEventArgs e);
3332

3433
Task CreateFolderWithSelection(RoutedEventArgs e);
35-
36-
Task PlayAll();
3734
}
3835
}

0 commit comments

Comments
 (0)