diff --git a/Terminal.Gui/Views/ColorPicker.cs b/Terminal.Gui/Views/ColorPicker.cs
index dff7d81336..00d6ee3f5d 100644
--- a/Terminal.Gui/Views/ColorPicker.cs
+++ b/Terminal.Gui/Views/ColorPicker.cs
@@ -361,7 +361,7 @@ private void UpdateValueFromTextField ()
}
}
-
+ ///
protected override void Dispose (bool disposing)
{
DisposeOldViews ();
diff --git a/Terminal.Gui/Views/Menu/ContextMenu.cs b/Terminal.Gui/Views/Menu/ContextMenu.cs
index 0ceec6d747..8751ada923 100644
--- a/Terminal.Gui/Views/Menu/ContextMenu.cs
+++ b/Terminal.Gui/Views/Menu/ContextMenu.cs
@@ -58,7 +58,7 @@ public ContextMenu ()
public static bool IsShow { get; private set; }
/// Specifies the key that will activate the context menu.
- public new Key Key
+ public Key Key
{
get => _key;
set
@@ -133,7 +133,7 @@ private void RemoveKeyBindings (MenuBarItem? menuBarItem)
return;
}
- foreach (var menuItem in menuBarItem.Children!)
+ foreach (MenuItem? menuItem in menuBarItem.Children!)
{
// ReSharper disable once ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract
if (menuItem is null)
@@ -150,7 +150,7 @@ private void RemoveKeyBindings (MenuBarItem? menuBarItem)
if (menuItem.ShortcutKey != Key.Empty)
{
// Remove an existent ShortcutKey
- _menuBar?.KeyBindings.Remove (menuItem.ShortcutKey);
+ _menuBar?.KeyBindings.Remove (menuItem.ShortcutKey!);
}
}
}
@@ -171,7 +171,7 @@ public void Show (MenuBarItem? menuItems)
Dispose ();
}
- if (menuItems is null || menuItems.Children.Length == 0)
+ if (menuItems is null || menuItems.Children!.Length == 0)
{
return;
}
diff --git a/Terminal.Gui/Views/Menu/Menu.cs b/Terminal.Gui/Views/Menu/Menu.cs
index 5bb2243997..9fcf3fd4c0 100644
--- a/Terminal.Gui/Views/Menu/Menu.cs
+++ b/Terminal.Gui/Views/Menu/Menu.cs
@@ -13,7 +13,7 @@ internal sealed class Menu : View
internal int _currentChild;
internal View? _previousSubFocused;
- internal static Rectangle MakeFrame (int x, int y, MenuItem []? items, Menu? parent = null)
+ internal static Rectangle MakeFrame (int x, int y, MenuItem? []? items, Menu? parent = null)
{
if (items is null || items.Length == 0)
{
diff --git a/Terminal.Gui/Views/Menu/MenuBar.cs b/Terminal.Gui/Views/Menu/MenuBar.cs
index 1415c2d767..76c00ed197 100644
--- a/Terminal.Gui/Views/Menu/MenuBar.cs
+++ b/Terminal.Gui/Views/Menu/MenuBar.cs
@@ -126,7 +126,12 @@ public MenuBar ()
return true;
}
);
- AddCommand (Command.ToggleExpandCollapse, ctx => Select (Menus.IndexOf (ctx.KeyBinding?.Context)));
+ AddCommand (Command.ToggleExpandCollapse, ctx =>
+ {
+ CloseOtherOpenedMenuBar ();
+
+ return Select (Menus.IndexOf (ctx.KeyBinding?.Context));
+ });
AddCommand (Command.Select, ctx =>
{
var res = Run ((ctx.KeyBinding?.Context as MenuItem)?.Action!);
@@ -387,6 +392,8 @@ public void OpenMenu ()
mbar?.CleanUp ();
+ CloseOtherOpenedMenuBar ();
+
if (!Enabled || _openMenu is { })
{
return;
@@ -528,11 +535,16 @@ internal void CloseAllMenus ()
_openedByAltKey = false;
OnMenuAllClosed ();
+ CloseOtherOpenedMenuBar ();
+ }
+
+ private void CloseOtherOpenedMenuBar ()
+ {
if (Application.Current is { })
{
// Close others menu bar opened
- View? cm = Application.Current.Subviews.FirstOrDefault (v => v is Menu cm && cm.Host != this && cm.Host.IsMenuOpen);
- (cm as Menu)?.Host.CleanUp ();
+ Menu? menu = Application.Current.Subviews.FirstOrDefault (v => v is Menu m && m.Host != this && m.Host.IsMenuOpen) as Menu;
+ menu?.Host.CleanUp ();
}
}
@@ -726,7 +738,7 @@ out OpenCurrentMenu._currentChild
else if (subMenu != null
|| (OpenCurrentMenu._currentChild > -1
&& !OpenCurrentMenu.BarItems!
- .Children! [OpenCurrentMenu._currentChild]
+ .Children! [OpenCurrentMenu._currentChild]!
.IsFromSubMenu))
{
_selectedSub++;
@@ -999,7 +1011,7 @@ internal bool Run (Action? action)
}
internal bool SelectEnabledItem (
- IEnumerable