diff --git a/Terminal.Gui/Core/Toplevel.cs b/Terminal.Gui/Core/Toplevel.cs index f06345152c..f0ccd1aab7 100644 --- a/Terminal.Gui/Core/Toplevel.cs +++ b/Terminal.Gui/Core/Toplevel.cs @@ -218,6 +218,7 @@ public Toplevel () : base () void Initialize () { + CanFocus = true; ColorScheme = Colors.TopLevel; // Things this view knows how to do @@ -569,6 +570,9 @@ internal void AddMenuStatusBar (View view) /// public override void Remove (View view) { + if (InternalSubviews.Count < 1) { + CanFocus = false; + } if (this is Toplevel toplevel && toplevel.MenuBar != null) { RemoveMenuStatusBar (view); } diff --git a/Terminal.Gui/Core/Window.cs b/Terminal.Gui/Core/Window.cs index 53925f258e..2aa3238c15 100644 --- a/Terminal.Gui/Core/Window.cs +++ b/Terminal.Gui/Core/Window.cs @@ -182,7 +182,6 @@ public Window (ustring title = null, int padding = 0, Border border = null) : ba void Initialize (ustring title, Rect frame, int padding = 0, Border border = null) { - CanFocus = true; ColorScheme = Colors.Base; if (title == null) title = ustring.Empty; Title = title; diff --git a/UnitTests/TopLevels/ToplevelTests.cs b/UnitTests/TopLevels/ToplevelTests.cs index 120ed6b352..c76e0ad04c 100644 --- a/UnitTests/TopLevels/ToplevelTests.cs +++ b/UnitTests/TopLevels/ToplevelTests.cs @@ -1031,5 +1031,22 @@ public void PositionCursor_SetCursorVisibility_To_Invisible_If_Focused_Is_Null ( Application.Driver.GetCursorVisibility (out cursor); Assert.Equal (CursorVisibility.Invisible, cursor); } + + [Fact, AutoInitShutdown] + public void Activating_MenuBar_By_Alt_Key_Does_Not_Throw () + { + var menu = new MenuBar (new MenuBarItem [] { + new MenuBarItem ("Child", new MenuItem [] { + new MenuItem ("_Create Child", "", null) + }) + }); + var topChild = new Toplevel (); + topChild.Add (menu); + Application.Top.Add (topChild); + Application.Begin (Application.Top); + + var exception = Record.Exception (() => topChild.ProcessHotKey (new KeyEvent (Key.AltMask, new KeyModifiers { Alt = true }))); + Assert.Null (exception); + } } } \ No newline at end of file