Prevents open menu bar if it's invisible and close all opened menus.

This commit is contained in:
BDisp
2023-08-10 19:13:50 +01:00
committed by Tig
parent b9c9079629
commit 42fcc35154
2 changed files with 36 additions and 2 deletions

View File

@@ -943,6 +943,17 @@ namespace Terminal.Gui {
/// </summary>
public Key Key { get; set; } = Key.F9;
///<inheritdoc/>
public override bool Visible {
get => base.Visible;
set {
base.Visible = value;
if (!value) {
CloseAllMenus ();
}
}
}
/// <summary>
/// Initializes a new instance of the <see cref="MenuBar"/>.
/// </summary>
@@ -1745,10 +1756,11 @@ namespace Terminal.Gui {
public override bool ProcessHotKey (KeyEvent kb)
{
if (kb.Key == Key) {
if (!IsMenuOpen)
if (Visible && !IsMenuOpen) {
OpenMenu ();
else
} else {
CloseAllMenus ();
}
return true;
}

View File

@@ -1787,5 +1787,27 @@ Edit
Assert.False (CanExecuteNew ());
Assert.True (CanExecuteClose ());
}
[Fact, AutoInitShutdown]
public void Visible_False_Key_Does_Not_Open_And_Close_All_Opened_Menus ()
{
var menu = new MenuBar (new MenuBarItem [] {
new MenuBarItem ("File", new MenuItem [] {
new MenuItem ("New", "", null)
})
});
Application.Top.Add (menu);
Application.Begin (Application.Top);
Assert.True (menu.Visible);
Assert.True (menu.ProcessHotKey (new KeyEvent (menu.Key, new KeyModifiers ())));
Assert.True (menu.IsMenuOpen);
menu.Visible = false;
Assert.False (menu.IsMenuOpen);
Assert.True (menu.ProcessHotKey (new KeyEvent (menu.Key, new KeyModifiers ())));
Assert.False (menu.IsMenuOpen);
}
}
}