Browse Source
Merge pull request #4795 from MarchingCube/gw-changes
Menu interaction handler fixes
pull/4815/head
Max Katz
6 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
17 additions and
5 deletions
-
src/Avalonia.Controls/MenuItem.cs
-
src/Avalonia.Controls/Platform/DefaultMenuInteractionHandler.cs
|
|
|
@ -101,7 +101,7 @@ namespace Avalonia.Controls |
|
|
|
|
|
|
|
private ICommand? _command; |
|
|
|
private bool _commandCanExecute = true; |
|
|
|
private Popup _popup; |
|
|
|
private Popup? _popup; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Initializes static members of the <see cref="MenuItem"/> class.
|
|
|
|
@ -145,7 +145,7 @@ namespace Avalonia.Controls |
|
|
|
{ |
|
|
|
var parent = x as Control; |
|
|
|
return parent?.GetObservable(DefinitionBase.PrivateSharedSizeScopeProperty) ?? |
|
|
|
Observable.Return<DefinitionBase.SharedSizeScope>(null); |
|
|
|
Observable.Return<DefinitionBase.SharedSizeScope?>(null); |
|
|
|
}); |
|
|
|
|
|
|
|
this.Bind(DefinitionBase.PrivateSharedSizeScopeProperty, parentSharedSizeScope); |
|
|
|
|
|
|
|
@ -148,6 +148,7 @@ namespace Avalonia.Controls.Platform |
|
|
|
{ |
|
|
|
case Key.Up: |
|
|
|
case Key.Down: |
|
|
|
{ |
|
|
|
if (item?.IsTopLevel == true) |
|
|
|
{ |
|
|
|
if (item.HasSubMenu && !item.IsSubMenuOpen) |
|
|
|
@ -161,8 +162,10 @@ namespace Avalonia.Controls.Platform |
|
|
|
goto default; |
|
|
|
} |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
case Key.Left: |
|
|
|
{ |
|
|
|
if (item?.Parent is IMenuItem parent && !parent.IsTopLevel && parent.IsSubMenuOpen) |
|
|
|
{ |
|
|
|
parent.Close(); |
|
|
|
@ -174,8 +177,10 @@ namespace Avalonia.Controls.Platform |
|
|
|
goto default; |
|
|
|
} |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
case Key.Right: |
|
|
|
{ |
|
|
|
if (item != null && !item.IsTopLevel && item.HasSubMenu) |
|
|
|
{ |
|
|
|
Open(item, true); |
|
|
|
@ -186,8 +191,10 @@ namespace Avalonia.Controls.Platform |
|
|
|
goto default; |
|
|
|
} |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
case Key.Enter: |
|
|
|
{ |
|
|
|
if (item != null) |
|
|
|
{ |
|
|
|
if (!item.HasSubMenu) |
|
|
|
@ -202,12 +209,14 @@ namespace Avalonia.Controls.Platform |
|
|
|
e.Handled = true; |
|
|
|
} |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
case Key.Escape: |
|
|
|
if (item?.Parent != null) |
|
|
|
{ |
|
|
|
if (item?.Parent is IMenuElement parent) |
|
|
|
{ |
|
|
|
item.Parent.Close(); |
|
|
|
item.Parent.Focus(); |
|
|
|
parent.Close(); |
|
|
|
parent.Focus(); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
@ -216,8 +225,10 @@ namespace Avalonia.Controls.Platform |
|
|
|
|
|
|
|
e.Handled = true; |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
default: |
|
|
|
{ |
|
|
|
var direction = e.Key.ToNavigationDirection(); |
|
|
|
|
|
|
|
if (direction.HasValue) |
|
|
|
@ -246,6 +257,7 @@ namespace Avalonia.Controls.Platform |
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (!e.Handled && item?.Parent is IMenuItem parentItem) |
|
|
|
|