From c1649981b5430ebd9841c36d1eaae989cfcfb5b2 Mon Sep 17 00:00:00 2001 From: BDisp Date: Fri, 11 Mar 2022 13:07:43 +0000 Subject: [PATCH] Implementing UseSubMenusSingleFrame in context menu. --- Terminal.Gui/Core/ContextMenu.cs | 8 +++++++- Terminal.Gui/Views/Menu.cs | 4 +++- UICatalog/Scenarios/ContextMenus.cs | 13 ++++++++++++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/Terminal.Gui/Core/ContextMenu.cs b/Terminal.Gui/Core/ContextMenu.cs index 75869b2b4..3c949cf19 100644 --- a/Terminal.Gui/Core/ContextMenu.cs +++ b/Terminal.Gui/Core/ContextMenu.cs @@ -106,7 +106,8 @@ namespace Terminal.Gui { X = position.X, Y = position.Y, Width = 0, - Height = 0 + Height = 0, + UseSubMenusSingleFrame = UseSubMenusSingleFrame }; menuBar.isContextMenuLoading = true; @@ -201,5 +202,10 @@ namespace Terminal.Gui { /// Gets the that is hosting this context menu. /// public MenuBar MenuBar { get => menuBar; } + + /// + /// Gets or sets if the sub-menus must be displayed in a single or multiple frames. + /// + public bool UseSubMenusSingleFrame { get; set; } } } diff --git a/Terminal.Gui/Views/Menu.cs b/Terminal.Gui/Views/Menu.cs index 6faeded35..cb53a7162 100644 --- a/Terminal.Gui/Views/Menu.cs +++ b/Terminal.Gui/Views/Menu.cs @@ -757,8 +757,10 @@ namespace Terminal.Gui { if (item == null || !item.IsEnabled ()) disabled = true; if (item != null && !disabled) current = me.Y - 1; - if (host.UseSubMenusSingleFrame || !CheckSubMenu ()) + if (host.UseSubMenusSingleFrame || !CheckSubMenu ()) { + SetNeedsDisplay (); return true; + } host.OnMenuOpened (); return true; } diff --git a/UICatalog/Scenarios/ContextMenus.cs b/UICatalog/Scenarios/ContextMenus.cs index 15f9d9c2b..d86d049bc 100644 --- a/UICatalog/Scenarios/ContextMenus.cs +++ b/UICatalog/Scenarios/ContextMenus.cs @@ -12,12 +12,19 @@ namespace UICatalog.Scenarios { private MenuItem miForceMinimumPosToZero; private bool forceMinimumPosToZero = true; private TextField tfTopLeft, tfTopRight, tfMiddle, tfBottomLeft, tfBottomRight; + private MenuItem miUseSubMenusSingleFrame; + private bool useSubMenusSingleFrame; public override void Setup () { var text = "Context Menu"; var width = 20; + Win.Add (new Label ("Press 'Ctrl + Space' to open the Window context menu.") { + X = Pos.Center (), + Y = 1 + }); + tfTopLeft = new TextField (text) { Width = width }; @@ -89,10 +96,14 @@ namespace UICatalog.Scenarios { tfBottomLeft.ContextMenu.ForceMinimumPosToZero = forceMinimumPosToZero; tfBottomRight.ContextMenu.ForceMinimumPosToZero = forceMinimumPosToZero; }) { CheckType = MenuItemCheckStyle.Checked, Checked = forceMinimumPosToZero }, + miUseSubMenusSingleFrame = new MenuItem ("Use_SubMenusSingleFrame", "", + () => contextMenu.UseSubMenusSingleFrame = miUseSubMenusSingleFrame.Checked = useSubMenusSingleFrame = !useSubMenusSingleFrame) { + CheckType = MenuItemCheckStyle.Checked, Checked = useSubMenusSingleFrame + }, null, new MenuItem ("_Quit", "", () => Application.RequestStop ()) }) - ) { ForceMinimumPosToZero = forceMinimumPosToZero }; + ) { ForceMinimumPosToZero = forceMinimumPosToZero, UseSubMenusSingleFrame = useSubMenusSingleFrame }; tfTopLeft.ContextMenu.ForceMinimumPosToZero = forceMinimumPosToZero; tfTopRight.ContextMenu.ForceMinimumPosToZero = forceMinimumPosToZero;