/
githubmirror
/
Files
Обзор
Документация
Войти
/
githubmirror
/
Files
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/Files.App/Actions/Content/Selection/ToggleSelectAction.cs
48 строк
1 KB
Yair
Code Quality: Fix COMException in property notifications during UI teardown
19 апр 2026, 17:35
19 апр 2026, 17:35
f796178
Код
Авторство
О чём код?
// Copyright (c) Files Community // Licensed under the MIT License. using Microsoft.UI.Xaml.Controls.Primitives; using Microsoft.UI.Xaml.Input; using System.Runtime.InteropServices; namespace Files.App.Actions { [GeneratedRichCommand] internal sealed class ToggleSelectAction : IAction { public string Label => Strings.ToggleSelect.GetLocalizedResource(); public string Description => Strings.ToggleSelectDescription.GetLocalizedResource(); public ActionCategory Category => ActionCategory.Selection; public HotKey HotKey => new(Keys.Space, KeyModifiers.Ctrl); public bool IsExecutable => GetFocusedElement() is not null; public Task ExecuteAsync(object? parameter = null) { if (GetFocusedElement() is SelectorItem item) item.IsSelected = !item.IsSelected; return Task.CompletedTask; } private static SelectorItem? GetFocusedElement() { try { return FocusManager.GetFocusedElement(MainWindow.Instance.Content.XamlRoot) as SelectorItem; } catch (COMException) // Window may already be closed { return null; } } } }