/
githubmirror
/
Files
Обзор
Документация
Войти
/
githubmirror
/
Files
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/Files.App/Actions/Content/Archives/Compress/BaseCompressArchiveAction.cs
79 строк
2 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. namespace Files.App.Actions { internal abstract class BaseCompressArchiveAction : BaseUIAction, IAction { protected readonly IContentPageContext context; protected IStorageArchiveService StorageArchiveService { get; } = Ioc.Default.GetRequiredService<IStorageArchiveService>(); public abstract string Label { get; } public abstract string Description { get; } public virtual string ExtendedLabel => Label; public virtual ActionCategory Category => ActionCategory.Archive; public RichGlyph Glyph => new(themedIconStyle: "App.ThemedIcons.Zip"); public override bool IsExecutable => IsContextPageTypeAdaptedToCommand() && StorageArchiveService.CanCompress(context.SelectedItems) && UIHelpers.CanShowDialog; public BaseCompressArchiveAction() { context = Ioc.Default.GetRequiredService<IContentPageContext>(); context.PropertyChanged += Context_PropertyChanged; } public abstract Task ExecuteAsync(object? parameter = null); protected void GetDestination(out string[] sources, out string directory, out string fileName) { sources = context.SelectedItems.Select(item => item.ItemPath).ToArray(); directory = string.Empty; fileName = string.Empty; if (sources.Length is not 0) { // Get the current directory path directory = context.ShellPage.ShellViewModel.WorkingDirectory.Normalize(); // Get the library save folder if the folder is library item if (App.LibraryManager.TryGetLibrary(directory, out var library) && !library.IsEmpty) directory = library.DefaultSaveFolder; // Gets the file name from the directory path fileName = SystemIO.Path.GetFileName(sources.Length is 1 ? sources[0] : directory); } } private bool IsContextPageTypeAdaptedToCommand() { return context.PageType != ContentPageTypes.RecycleBin && context.PageType != ContentPageTypes.ZipFolder && context.PageType != ContentPageTypes.ReleaseNotes && context.PageType != ContentPageTypes.Settings && context.PageType != ContentPageTypes.None; } private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e) { switch (e.PropertyName) { case nameof(IContentPageContext.SelectedItems): if (IsContextPageTypeAdaptedToCommand()) OnPropertyChanged(nameof(IsExecutable)); break; } } } }