/
githubmirror
/
Files
Обзор
Документация
Войти
/
githubmirror
/
Files
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/Files.App/Actions/FileSystem/RestoreRecycleBinAction.cs
81 строка
3 KB
yair100
Code Quality: Add Category, ExtendedLabel, AutomationId and AccessKey to actions (#18308)
27 мар 2026, 00:40
Не верифицирован
27 мар 2026, 00:40
6ef1f17
Код
Авторство
О чём код?
// Copyright (c) Files Community // Licensed under the MIT License. using Microsoft.UI.Xaml.Controls; using Windows.Foundation.Metadata; using Windows.Storage; namespace Files.App.Actions { [GeneratedRichCommand] internal sealed partial class RestoreRecycleBinAction : BaseUIAction, IAction { private readonly IContentPageContext context; public string Label => Strings.Restore.GetLocalizedResource(); public string Description => Strings.RestoreRecycleBinDescription.GetLocalizedFormatResource(context.SelectedItems.Count); public ActionCategory Category => ActionCategory.FileSystem; public RichGlyph Glyph => new(themedIconStyle: "App.ThemedIcons.RestoreDeleted"); public override bool IsExecutable => context.PageType is ContentPageTypes.RecycleBin && context.SelectedItems.Any() && UIHelpers.CanShowDialog; public RestoreRecycleBinAction() { context = Ioc.Default.GetRequiredService<IContentPageContext>(); context.PropertyChanged += Context_PropertyChanged; } public async Task ExecuteAsync(object? parameter = null) { var confirmationDialog = new ContentDialog() { Title = Strings.ConfirmRestoreSelectionBinDialogTitle.GetLocalizedResource(), Content = string.Format(Strings.ConfirmRestoreSelectionBinDialogContent.GetLocalizedFormatResource(context.SelectedItems.Count), context.SelectedItems.Count), PrimaryButtonText = Strings.Yes.GetLocalizedResource(), SecondaryButtonText = Strings.Cancel.GetLocalizedResource(), DefaultButton = ContentDialogButton.Primary }; if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 8)) confirmationDialog.XamlRoot = MainWindow.Instance.Content.XamlRoot; ContentDialogResult result = await confirmationDialog.TryShowAsync(); if (result is not ContentDialogResult.Primary) return; var items = context.SelectedItems.ToList().Where(x => x is RecycleBinItem).Select((item) => new { Source = StorageHelpers.FromPathAndType( item.ItemPath, item.PrimaryItemAttribute == StorageItemTypes.File ? FilesystemItemType.File : FilesystemItemType.Directory), Dest = ((RecycleBinItem)item).ItemOriginalPath }); await context.ShellPage!.FilesystemHelpers.RestoreItemsFromTrashAsync(items.Select(x => x.Source), items.Select(x => x.Dest), true); } private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e) { switch (e.PropertyName) { case nameof(IContentPageContext.PageType): case nameof(IContentPageContext.SelectedItems): if (context.PageType is ContentPageTypes.RecycleBin) OnPropertyChanged(nameof(IsExecutable)); break; } } } }