/
githubmirror
/
Files
Обзор
Документация
Войти
/
githubmirror
/
Files
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/Files.App/Actions/FileSystem/AddItemAction.cs
74 строки
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 AddItemAction : ObservableObject, IAction { private readonly IContentPageContext context; private readonly IDialogService dialogService; private readonly AddItemDialogViewModel viewModel = new(); public string Label => Strings.BaseLayoutContextFlyoutNew_Label.GetLocalizedResource(); public string ExtendedLabel => Description; public string Description => Strings.AddItemDescription.GetLocalizedResource(); public ActionCategory Category => ActionCategory.Create; public RichGlyph Glyph => new(themedIconStyle: "App.ThemedIcons.New.Item"); public HotKey HotKey => new(Keys.I, KeyModifiers.CtrlShift); public bool IsExecutable => context.CanCreateItem; public AddItemAction() { context = Ioc.Default.GetRequiredService<IContentPageContext>(); dialogService = Ioc.Default.GetRequiredService<IDialogService>(); context.PropertyChanged += Context_PropertyChanged; } public async Task ExecuteAsync(object? parameter = null) { await dialogService.ShowDialogAsync(viewModel); if (viewModel.ResultType.ItemType == AddItemDialogItemType.Shortcut) { await Ioc.Default.GetRequiredService<ICommandManager>().CreateShortcutFromDialog.ExecuteAsync(); } else if (viewModel.ResultType.ItemType != AddItemDialogItemType.Cancel) { await UIFilesystemHelpers.CreateFileFromDialogResultTypeAsync( viewModel.ResultType.ItemType, viewModel.ResultType.ItemInfo, context.ShellPage!); } viewModel.ResultType.ItemType = AddItemDialogItemType.Cancel; } private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e) { switch (e.PropertyName) { case nameof(IContentPageContext.CanCreateItem): case nameof(IContentPageContext.HasSelection): OnPropertyChanged(nameof(IsExecutable)); break; } } } }