Skip to content

Feature: Display Restore All Items when right clicking recycle bin on the sidebar #12178

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
Apr 25, 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
32 changes: 2 additions & 30 deletions src/Files.App/Actions/FileSystem/RestoreAllRecycleBinAction.cs
Original file line number Diff line number Diff line change
@@ -1,53 +1,25 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using CommunityToolkit.Mvvm.DependencyInjection;
using Files.App.Commands;
using Files.App.Contexts;
using Files.App.Extensions;
using Files.App.Helpers;
using System.ComponentModel;
using System.Threading.Tasks;

namespace Files.App.Actions
{
internal class RestoreAllRecycleBinAction : BaseUIAction, IAction
{
private readonly IContentPageContext context = Ioc.Default.GetRequiredService<IContentPageContext>();

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

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

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

public override bool IsExecutable =>
context.ShellPage is not null &&
UIHelpers.CanShowDialog &&
((context.PageType is ContentPageTypes.RecycleBin && context.HasItem) ||
RecycleBinHelpers.RecycleBinHasItems());

public RestoreAllRecycleBinAction()
{
context.PropertyChanged += Context_PropertyChanged;
}
RecycleBinHelpers.RecycleBinHasItems();

public async Task ExecuteAsync()
{
if (context.ShellPage is not null)
await RecycleBinHelpers.RestoreRecycleBin(context.ShellPage);
}

private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
switch (e.PropertyName)
{
case nameof(IContentPageContext.PageType):
case nameof(IContentPageContext.HasItem):
if (context.PageType is ContentPageTypes.RecycleBin)
OnPropertyChanged(nameof(IsExecutable));
break;
}
await RecycleBinHelpers.RestoreRecycleBin();
}
}
}
5 changes: 2 additions & 3 deletions src/Files.App/Helpers/RecycleBinHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public static async Task EmptyRecycleBin()
}
}

public static async Task RestoreRecycleBin(IShellPage associatedInstance)
public static async Task RestoreRecycleBin()
{
var ConfirmEmptyBinDialog = new ContentDialog()
{
Expand All @@ -115,8 +115,7 @@ public static async Task RestoreRecycleBin(IShellPage associatedInstance)

if (result == ContentDialogResult.Primary)
{
associatedInstance.SlimContentPage.ItemManipulationModel.SelectAllItems();
await RestoreItem(associatedInstance);
Vanara.Windows.Shell.RecycleBin.RestoreAll();
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/Files.App/UserControls/SidebarControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,10 @@ private List<ContextMenuFlyoutItemViewModel> GetLocationItemMenuItems(INavigatio
{
IsVisible = options.ShowEmptyRecycleBin,
}.Build(),
new ContextMenuFlyoutItemViewModelBuilder(commands.RestoreAllRecycleBin)
{
IsVisible = options.ShowEmptyRecycleBin,
}.Build(),
new ContextMenuFlyoutItemViewModel()
{
Text = "OpenInNewTab".GetLocalizedResource(),
Expand Down