mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-29 01:07:58 +01:00
Prevents open menu bar if it's invisible and close all opened menus.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user