|
|
|
@ -24,7 +24,7 @@ namespace Avalonia.Input |
|
|
|
/// <summary>
|
|
|
|
/// The registered access keys.
|
|
|
|
/// </summary>
|
|
|
|
private readonly List<Tuple<string, IInputElement>> _registered = new List<Tuple<string, IInputElement>>(); |
|
|
|
private readonly List<(string AccessKey, IInputElement Element)> _registered = new(); |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// The window to which the handler belongs.
|
|
|
|
@ -109,12 +109,12 @@ namespace Avalonia.Input |
|
|
|
{ |
|
|
|
var existing = _registered.FirstOrDefault(x => x.Item2 == element); |
|
|
|
|
|
|
|
if (existing != null) |
|
|
|
if (existing != default) |
|
|
|
{ |
|
|
|
_registered.Remove(existing); |
|
|
|
} |
|
|
|
|
|
|
|
_registered.Add(Tuple.Create(accessKey.ToString(CultureInfo.InvariantCulture).ToUpperInvariant(), element)); |
|
|
|
_registered.Add((accessKey.ToString().ToUpperInvariant(), element)); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -144,7 +144,7 @@ namespace Avalonia.Input |
|
|
|
{ |
|
|
|
// TODO: Use FocusScopes to store the current element and restore it when context menu is closed.
|
|
|
|
// Save currently focused input element.
|
|
|
|
_restoreFocusElement = FocusManager.Instance?.Current; |
|
|
|
_restoreFocusElement = FocusManager.Instance?.Current; |
|
|
|
|
|
|
|
// When Alt is pressed without a main menu, or with a closed main menu, show
|
|
|
|
// access key markers in the window (i.e. "_File").
|
|
|
|
@ -183,8 +183,9 @@ namespace Avalonia.Input |
|
|
|
// find all controls who have registered that access key.
|
|
|
|
var text = e.Key.ToString(); |
|
|
|
var matches = _registered |
|
|
|
.Where(x => string.Equals( x.Item1 , text, StringComparison.OrdinalIgnoreCase) && ((Visual)x.Item2).IsEffectivelyVisible) |
|
|
|
.Select(x => x.Item2); |
|
|
|
.Where(x => x.Element.IsEffectivelyVisible |
|
|
|
&& string.Equals(x.AccessKey , text, StringComparison.OrdinalIgnoreCase) ) |
|
|
|
.Select(x => x.Element); |
|
|
|
|
|
|
|
// If the menu is open, only match controls in the menu's visual tree.
|
|
|
|
if (menuIsOpen) |
|
|
|
@ -195,7 +196,7 @@ namespace Avalonia.Input |
|
|
|
var match = matches.FirstOrDefault(); |
|
|
|
|
|
|
|
// If there was a match, raise the AccessKeyPressed event on it.
|
|
|
|
if (match != null) |
|
|
|
if (match is not null) |
|
|
|
{ |
|
|
|
match.RaiseEvent(new RoutedEventArgs(AccessKeyPressedEvent)); |
|
|
|
e.Handled = true; |
|
|
|
|