/
githubmirror
/
Files
Обзор
Документация
Войти
/
githubmirror
/
Files
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/Files.App/Actions/Sidebar/UnpinFolderToSidebarAction.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 { [GeneratedRichCommand] internal sealed partial class UnpinFolderFromSidebarAction : ObservableObject, IAction { private readonly IContentPageContext context; private readonly IQuickAccessService service; public string Label => Strings.UnpinFolderFromSidebar.GetLocalizedResource(); public string Description => Strings.UnpinFolderFromSidebarDescription.GetLocalizedFormatResource(context.HasSelection ? context.SelectedItems.Count : 1); public ActionCategory Category => ActionCategory.FileSystem; public RichGlyph Glyph => new(themedIconStyle: "App.ThemedIcons.FavoritePinRemove"); public bool IsExecutable => GetIsExecutable(); public UnpinFolderFromSidebarAction() { context = Ioc.Default.GetRequiredService<IContentPageContext>(); service = Ioc.Default.GetRequiredService<IQuickAccessService>(); context.PropertyChanged += Context_PropertyChanged; App.QuickAccessManager.UpdateQuickAccessWidget += QuickAccessManager_DataChanged; } public async Task ExecuteAsync(object? parameter = null) { if (context.HasSelection) { var items = context.SelectedItems.Select(x => x.ItemPath).ToArray(); await service.UnpinFromSidebarAsync(items); } else if (context.Folder is not null) { await service.UnpinFromSidebarAsync(context.Folder.ItemPath); } } private bool GetIsExecutable() { string[] pinnedFolders = [.. App.QuickAccessManager.Model.PinnedFolders]; return context.HasSelection ? context.SelectedItems.All(IsPinned) : context.Folder is not null && IsPinned(context.Folder); bool IsPinned(ListedItem item) { return pinnedFolders.Contains(item.ItemPath); } } private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e) { switch (e.PropertyName) { case nameof(IContentPageContext.Folder): case nameof(IContentPageContext.SelectedItems): OnPropertyChanged(nameof(IsExecutable)); break; } } private void QuickAccessManager_DataChanged(object? sender, ModifyQuickAccessEventArgs e) { OnPropertyChanged(nameof(IsExecutable)); } } }