Browse Source

Merge branch 'master' into fixes/711-stream-binding-expression-operator

pull/764/head
Steven Kirk 10 years ago
committed by GitHub
parent
commit
a027291aa0
  1. 25
      src/Avalonia.Input/AccessKeyHandler.cs

25
src/Avalonia.Input/AccessKeyHandler.cs

@ -43,6 +43,16 @@ namespace Avalonia.Input
/// </summary> /// </summary>
private bool _ignoreAltUp; private bool _ignoreAltUp;
/// <summary>
/// Whether the AltKey is down.
/// </summary>
private bool _altIsDown;
/// <summary>
/// Element to restore folowing AltKey taking focus.
/// </summary>
private IInputElement _restoreFocusElement;
/// <summary> /// <summary>
/// Gets or sets the window's main menu. /// Gets or sets the window's main menu.
/// </summary> /// </summary>
@ -110,8 +120,14 @@ namespace Avalonia.Input
{ {
if (e.Key == Key.LeftAlt) if (e.Key == Key.LeftAlt)
{ {
_altIsDown = true;
if (MainMenu == null || !MainMenu.IsOpen) if (MainMenu == null || !MainMenu.IsOpen)
{ {
// 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;
// When Alt is pressed without a main menu, or with a closed main menu, show // When Alt is pressed without a main menu, or with a closed main menu, show
// access key markers in the window (i.e. "_File"). // access key markers in the window (i.e. "_File").
_owner.ShowAccessKeys = _showingAccessKeys = true; _owner.ShowAccessKeys = _showingAccessKeys = true;
@ -121,11 +137,18 @@ namespace Avalonia.Input
// If the Alt key is pressed and the main menu is open, close the main menu. // If the Alt key is pressed and the main menu is open, close the main menu.
CloseMenu(); CloseMenu();
_ignoreAltUp = true; _ignoreAltUp = true;
_restoreFocusElement?.Focus();
_restoreFocusElement = null;
} }
// We always handle the Alt key. // We always handle the Alt key.
e.Handled = true; e.Handled = true;
} }
else if (_altIsDown)
{
_ignoreAltUp = true;
}
} }
/// <summary> /// <summary>
@ -179,6 +202,8 @@ namespace Avalonia.Input
switch (e.Key) switch (e.Key)
{ {
case Key.LeftAlt: case Key.LeftAlt:
_altIsDown = false;
if (_ignoreAltUp) if (_ignoreAltUp)
{ {
_ignoreAltUp = false; _ignoreAltUp = false;

Loading…
Cancel
Save