From 9777b9a5ee12f45cf99d4ae4f3f37717393b9c9b Mon Sep 17 00:00:00 2001 From: Takoooooo Date: Thu, 23 Sep 2021 15:01:31 +0300 Subject: [PATCH 1/4] fix --- .../Platform/DefaultMenuInteractionHandler.cs | 158 +++++++++--------- 1 file changed, 79 insertions(+), 79 deletions(-) diff --git a/src/Avalonia.Controls/Platform/DefaultMenuInteractionHandler.cs b/src/Avalonia.Controls/Platform/DefaultMenuInteractionHandler.cs index 726d2c596c..dd3388b30e 100644 --- a/src/Avalonia.Controls/Platform/DefaultMenuInteractionHandler.cs +++ b/src/Avalonia.Controls/Platform/DefaultMenuInteractionHandler.cs @@ -99,7 +99,7 @@ namespace Avalonia.Controls.Platform { root.Deactivated -= WindowDeactivated; } - + if (_root is TopLevel tl) tl.PlatformImpl.LostFocus -= TopLevelLostPlatformFocus; @@ -148,116 +148,116 @@ namespace Avalonia.Controls.Platform { case Key.Up: case Key.Down: - { - if (item?.IsTopLevel == true) { - if (item.HasSubMenu && !item.IsSubMenuOpen) + if (item?.IsTopLevel == true) { - Open(item, true); - e.Handled = true; + if (item.HasSubMenu && !item.IsSubMenuOpen) + { + Open(item, true); + e.Handled = true; + } } + else + { + goto default; + } + break; } - else - { - goto default; - } - break; - } case Key.Left: - { - if (item?.Parent is IMenuItem parent && !parent.IsTopLevel && parent.IsSubMenuOpen) { - parent.Close(); - parent.Focus(); - e.Handled = true; - } - else - { - goto default; + if (item?.Parent is IMenuItem parent && !parent.IsTopLevel && parent.IsSubMenuOpen) + { + parent.Close(); + parent.Focus(); + e.Handled = true; + } + else + { + goto default; + } + break; } - break; - } case Key.Right: - { - if (item != null && !item.IsTopLevel && item.HasSubMenu) { - Open(item, true); - e.Handled = true; + if (item != null && !item.IsTopLevel && item.HasSubMenu) + { + Open(item, true); + e.Handled = true; + } + else + { + goto default; + } + break; } - else + + case Key.Enter: { - goto default; + if (item != null) + { + if (!item.HasSubMenu) + { + Click(item); + } + else + { + Open(item, true); + } + + e.Handled = true; + } + break; } - break; - } - case Key.Enter: - { - if (item != null) + case Key.Escape: { - if (!item.HasSubMenu) + if (item?.Parent is IMenuElement parent) { - Click(item); + parent.Close(); + parent.Focus(); } else { - Open(item, true); + Menu!.Close(); } e.Handled = true; + break; } - break; - } - - case Key.Escape: - { - if (item?.Parent is IMenuElement parent) - { - parent.Close(); - parent.Focus(); - } - else - { - Menu!.Close(); - } - - e.Handled = true; - break; - } default: - { - var direction = e.Key.ToNavigationDirection(); - - if (direction?.IsDirectional() == true) { - if (item == null && _isContextMenu) + var direction = e.Key.ToNavigationDirection(); + + if (direction?.IsDirectional() == true) { - if (Menu!.MoveSelection(direction.Value, true) == true) + if (item == null && _isContextMenu) { - e.Handled = true; + if (Menu!.MoveSelection(direction.Value, true) == true) + { + e.Handled = true; + } } - } - else if (item?.Parent?.MoveSelection(direction.Value, true) == true) - { - // If the the parent is an IMenu which successfully moved its selection, - // and the current menu is open then close the current menu and open the - // new menu. - if (item.IsSubMenuOpen && - item.Parent is IMenu && - item.Parent.SelectedItem is object) + else if (item?.Parent?.MoveSelection(direction.Value, true) == true) { - item.Close(); - Open(item.Parent.SelectedItem, true); + // If the the parent is an IMenu which successfully moved its selection, + // and the current menu is open then close the current menu and open the + // new menu. + if (item.IsSubMenuOpen && + item.Parent is IMenu && + item.Parent.SelectedItem is object) + { + item.Close(); + Open(item.Parent.SelectedItem, true); + } + e.Handled = true; } - e.Handled = true; } - } - break; - } + break; + } } if (!e.Handled && item?.Parent is IMenuItem parentItem) @@ -275,7 +275,7 @@ namespace Avalonia.Controls.Platform return; } - if (item.HasSubMenu) + if (item.HasSubMenu && item.IsEnabled) { Open(item, true); } @@ -441,7 +441,7 @@ namespace Avalonia.Controls.Platform { Menu?.Close(); } - + private void TopLevelLostPlatformFocus() { Menu?.Close(); From 63716e19d7988fc732b1c82c6edcea22ab1abbe8 Mon Sep 17 00:00:00 2001 From: Takoooooo Date: Thu, 23 Sep 2021 15:14:06 +0300 Subject: [PATCH 2/4] Revert "fix" This reverts commit 9777b9a5ee12f45cf99d4ae4f3f37717393b9c9b. --- .../Platform/DefaultMenuInteractionHandler.cs | 158 +++++++++--------- 1 file changed, 79 insertions(+), 79 deletions(-) diff --git a/src/Avalonia.Controls/Platform/DefaultMenuInteractionHandler.cs b/src/Avalonia.Controls/Platform/DefaultMenuInteractionHandler.cs index dd3388b30e..726d2c596c 100644 --- a/src/Avalonia.Controls/Platform/DefaultMenuInteractionHandler.cs +++ b/src/Avalonia.Controls/Platform/DefaultMenuInteractionHandler.cs @@ -99,7 +99,7 @@ namespace Avalonia.Controls.Platform { root.Deactivated -= WindowDeactivated; } - + if (_root is TopLevel tl) tl.PlatformImpl.LostFocus -= TopLevelLostPlatformFocus; @@ -148,116 +148,116 @@ namespace Avalonia.Controls.Platform { case Key.Up: case Key.Down: + { + if (item?.IsTopLevel == true) { - if (item?.IsTopLevel == true) + if (item.HasSubMenu && !item.IsSubMenuOpen) { - if (item.HasSubMenu && !item.IsSubMenuOpen) - { - Open(item, true); - e.Handled = true; - } - } - else - { - goto default; + Open(item, true); + e.Handled = true; } - break; } + else + { + goto default; + } + break; + } case Key.Left: + { + if (item?.Parent is IMenuItem parent && !parent.IsTopLevel && parent.IsSubMenuOpen) { - if (item?.Parent is IMenuItem parent && !parent.IsTopLevel && parent.IsSubMenuOpen) - { - parent.Close(); - parent.Focus(); - e.Handled = true; - } - else - { - goto default; - } - break; + parent.Close(); + parent.Focus(); + e.Handled = true; + } + else + { + goto default; } + break; + } case Key.Right: + { + if (item != null && !item.IsTopLevel && item.HasSubMenu) { - if (item != null && !item.IsTopLevel && item.HasSubMenu) - { - Open(item, true); - e.Handled = true; - } - else - { - goto default; - } - break; + Open(item, true); + e.Handled = true; } - - case Key.Enter: + else { - if (item != null) - { - if (!item.HasSubMenu) - { - Click(item); - } - else - { - Open(item, true); - } - - e.Handled = true; - } - break; + goto default; } + break; + } - case Key.Escape: + case Key.Enter: + { + if (item != null) { - if (item?.Parent is IMenuElement parent) + if (!item.HasSubMenu) { - parent.Close(); - parent.Focus(); + Click(item); } else { - Menu!.Close(); + Open(item, true); } e.Handled = true; - break; } + break; + } - default: + case Key.Escape: + { + if (item?.Parent is IMenuElement parent) { - var direction = e.Key.ToNavigationDirection(); + parent.Close(); + parent.Focus(); + } + else + { + Menu!.Close(); + } - if (direction?.IsDirectional() == true) + e.Handled = true; + break; + } + + default: + { + var direction = e.Key.ToNavigationDirection(); + + if (direction?.IsDirectional() == true) + { + if (item == null && _isContextMenu) { - if (item == null && _isContextMenu) + if (Menu!.MoveSelection(direction.Value, true) == true) { - if (Menu!.MoveSelection(direction.Value, true) == true) - { - e.Handled = true; - } + e.Handled = true; } - else if (item?.Parent?.MoveSelection(direction.Value, true) == true) + } + else if (item?.Parent?.MoveSelection(direction.Value, true) == true) + { + // If the the parent is an IMenu which successfully moved its selection, + // and the current menu is open then close the current menu and open the + // new menu. + if (item.IsSubMenuOpen && + item.Parent is IMenu && + item.Parent.SelectedItem is object) { - // If the the parent is an IMenu which successfully moved its selection, - // and the current menu is open then close the current menu and open the - // new menu. - if (item.IsSubMenuOpen && - item.Parent is IMenu && - item.Parent.SelectedItem is object) - { - item.Close(); - Open(item.Parent.SelectedItem, true); - } - e.Handled = true; + item.Close(); + Open(item.Parent.SelectedItem, true); } + e.Handled = true; } - - break; } + + break; + } } if (!e.Handled && item?.Parent is IMenuItem parentItem) @@ -275,7 +275,7 @@ namespace Avalonia.Controls.Platform return; } - if (item.HasSubMenu && item.IsEnabled) + if (item.HasSubMenu) { Open(item, true); } @@ -441,7 +441,7 @@ namespace Avalonia.Controls.Platform { Menu?.Close(); } - + private void TopLevelLostPlatformFocus() { Menu?.Close(); From a13e9c1c1c932a124513a478ae8493203fdf4782 Mon Sep 17 00:00:00 2001 From: Takoooooo Date: Thu, 23 Sep 2021 15:14:29 +0300 Subject: [PATCH 3/4] fix --- src/Avalonia.Controls/Platform/DefaultMenuInteractionHandler.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Avalonia.Controls/Platform/DefaultMenuInteractionHandler.cs b/src/Avalonia.Controls/Platform/DefaultMenuInteractionHandler.cs index 726d2c596c..cde78ae839 100644 --- a/src/Avalonia.Controls/Platform/DefaultMenuInteractionHandler.cs +++ b/src/Avalonia.Controls/Platform/DefaultMenuInteractionHandler.cs @@ -275,7 +275,7 @@ namespace Avalonia.Controls.Platform return; } - if (item.HasSubMenu) + if (item.HasSubMenu && item.IsEnabled) { Open(item, true); } From cfc50e45f54b5ea7727ec07cb17413011771c76f Mon Sep 17 00:00:00 2001 From: Takoooooo Date: Thu, 23 Sep 2021 16:37:18 +0300 Subject: [PATCH 4/4] upd --- src/Avalonia.Controls/Platform/DefaultMenuInteractionHandler.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Avalonia.Controls/Platform/DefaultMenuInteractionHandler.cs b/src/Avalonia.Controls/Platform/DefaultMenuInteractionHandler.cs index cde78ae839..e361e7b736 100644 --- a/src/Avalonia.Controls/Platform/DefaultMenuInteractionHandler.cs +++ b/src/Avalonia.Controls/Platform/DefaultMenuInteractionHandler.cs @@ -275,7 +275,7 @@ namespace Avalonia.Controls.Platform return; } - if (item.HasSubMenu && item.IsEnabled) + if (item.HasSubMenu && item.IsEffectivelyEnabled) { Open(item, true); }