Skip to content

Commit b4deafc

Browse files
authored
Feature: Display Restore All Items when right clicking recycle bin on the sidebar (#12178)
1 parent d7ea877 commit b4deafc

File tree

3 files changed

+8
-33
lines changed

3 files changed

+8
-33
lines changed
Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,25 @@
11
// Copyright (c) 2023 Files Community
22
// Licensed under the MIT License. See the LICENSE.
33

4-
using CommunityToolkit.Mvvm.DependencyInjection;
54
using Files.App.Commands;
6-
using Files.App.Contexts;
7-
using Files.App.Extensions;
8-
using Files.App.Helpers;
9-
using System.ComponentModel;
10-
using System.Threading.Tasks;
115

126
namespace Files.App.Actions
137
{
148
internal class RestoreAllRecycleBinAction : BaseUIAction, IAction
159
{
16-
private readonly IContentPageContext context = Ioc.Default.GetRequiredService<IContentPageContext>();
17-
1810
public string Label { get; } = "RestoreAllItems".GetLocalizedResource();
1911

2012
public string Description => "RestoreAllRecycleBinDescription".GetLocalizedResource();
2113

2214
public RichGlyph Glyph { get; } = new RichGlyph(opacityStyle: "ColorIconRestoreItem");
2315

2416
public override bool IsExecutable =>
25-
context.ShellPage is not null &&
2617
UIHelpers.CanShowDialog &&
27-
((context.PageType is ContentPageTypes.RecycleBin && context.HasItem) ||
28-
RecycleBinHelpers.RecycleBinHasItems());
29-
30-
public RestoreAllRecycleBinAction()
31-
{
32-
context.PropertyChanged += Context_PropertyChanged;
33-
}
18+
RecycleBinHelpers.RecycleBinHasItems();
3419

3520
public async Task ExecuteAsync()
3621
{
37-
if (context.ShellPage is not null)
38-
await RecycleBinHelpers.RestoreRecycleBin(context.ShellPage);
39-
}
40-
41-
private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
42-
{
43-
switch (e.PropertyName)
44-
{
45-
case nameof(IContentPageContext.PageType):
46-
case nameof(IContentPageContext.HasItem):
47-
if (context.PageType is ContentPageTypes.RecycleBin)
48-
OnPropertyChanged(nameof(IsExecutable));
49-
break;
50-
}
22+
await RecycleBinHelpers.RestoreRecycleBin();
5123
}
5224
}
5325
}

src/Files.App/Helpers/RecycleBinHelpers.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public static async Task EmptyRecycleBin()
100100
}
101101
}
102102

103-
public static async Task RestoreRecycleBin(IShellPage associatedInstance)
103+
public static async Task RestoreRecycleBin()
104104
{
105105
var ConfirmEmptyBinDialog = new ContentDialog()
106106
{
@@ -115,8 +115,7 @@ public static async Task RestoreRecycleBin(IShellPage associatedInstance)
115115

116116
if (result == ContentDialogResult.Primary)
117117
{
118-
associatedInstance.SlimContentPage.ItemManipulationModel.SelectAllItems();
119-
await RestoreItem(associatedInstance);
118+
Vanara.Windows.Shell.RecycleBin.RestoreAll();
120119
}
121120
}
122121

src/Files.App/UserControls/SidebarControl.xaml.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,10 @@ private List<ContextMenuFlyoutItemViewModel> GetLocationItemMenuItems(INavigatio
214214
{
215215
IsVisible = options.ShowEmptyRecycleBin,
216216
}.Build(),
217+
new ContextMenuFlyoutItemViewModelBuilder(commands.RestoreAllRecycleBin)
218+
{
219+
IsVisible = options.ShowEmptyRecycleBin,
220+
}.Build(),
217221
new ContextMenuFlyoutItemViewModel()
218222
{
219223
Text = "OpenInNewTab".GetLocalizedResource(),

0 commit comments

Comments
 (0)