diff --git a/Terminal.Gui/Views/ContextMenu.cs b/Terminal.Gui/Views/ContextMenu.cs index e0e5eca56f..e8520f98eb 100644 --- a/Terminal.Gui/Views/ContextMenu.cs +++ b/Terminal.Gui/Views/ContextMenu.cs @@ -79,7 +79,6 @@ public void Dispose () } if (container != null) { container.Closing -= Container_Closing; - container.Resized -= Container_Resized; } } @@ -93,7 +92,6 @@ public void Show () } container = Application.Current; container.Closing += Container_Closing; - container.Resized += Container_Resized; var frame = container.Frame; var position = Position; if (Host != null) { @@ -145,13 +143,6 @@ public void Show () menuBar.OpenMenu (); } - private void Container_Resized (Size obj) - { - if (IsShow) { - Show (); - } - } - private void Container_Closing (ToplevelClosingEventArgs obj) { Hide (); diff --git a/Terminal.Gui/Views/Menu.cs b/Terminal.Gui/Views/Menu.cs index 28cb46db00..444f695a6e 100644 --- a/Terminal.Gui/Views/Menu.cs +++ b/Terminal.Gui/Views/Menu.cs @@ -424,6 +424,10 @@ public Menu (MenuBar host, int x, int y, MenuBarItem barItems, Menu parent = nul WantMousePositionReports = host.WantMousePositionReports; } + if (Application.Current != null) { + Application.Current.Resized += Current_Resized; + } + // Things this view knows how to do AddCommand (Command.LineUp, () => MoveUp ()); AddCommand (Command.LineDown, () => MoveDown ()); @@ -449,6 +453,13 @@ public Menu (MenuBar host, int x, int y, MenuBarItem barItems, Menu parent = nul AddKeyBinding (Key.Enter, Command.Accept); } + private void Current_Resized (Size obj) + { + if (host.IsMenuOpen) { + host.CloseAllMenus (); + } + } + internal Attribute DetermineColorSchemeFor (MenuItem item, int index) { if (item != null) { @@ -846,6 +857,15 @@ public override bool OnEnter (View view) return base.OnEnter (view); } + + protected override void Dispose (bool disposing) + { + if (Application.Current != null) { + Application.Current.Resized -= Current_Resized; + } + + base.Dispose (disposing); + } } /// diff --git a/UnitTests/Menus/ContextMenuTests.cs b/UnitTests/Menus/ContextMenuTests.cs index 3807e971a8..dd493358f4 100644 --- a/UnitTests/Menus/ContextMenuTests.cs +++ b/UnitTests/Menus/ContextMenuTests.cs @@ -385,6 +385,8 @@ public void Show_Display_Below_The_Bottom_Host_If_Has_Enough_Space () [Fact, AutoInitShutdown] public void Show_Display_At_Zero_If_The_Toplevel_Width_Is_Less_Than_The_Menu_Width () { + ((FakeDriver)Application.Driver).SetBufferSize (5, 25); + var cm = new ContextMenu (0, 0, new MenuBarItem (new MenuItem [] { new MenuItem ("One", "", null), @@ -397,7 +399,6 @@ public void Show_Display_At_Zero_If_The_Toplevel_Width_Is_Less_Than_The_Menu_Wid cm.Show (); Assert.Equal (new Point (0, 0), cm.Position); Application.Begin (Application.Top); - ((FakeDriver)Application.Driver).SetBufferSize (5, 25); var expected = @" ┌──── @@ -416,6 +417,8 @@ public void Show_Display_At_Zero_If_The_Toplevel_Width_Is_Less_Than_The_Menu_Wid [Fact, AutoInitShutdown] public void Show_Display_At_Zero_If_The_Toplevel_Height_Is_Less_Than_The_Menu_Height () { + ((FakeDriver)Application.Driver).SetBufferSize (80, 3); + var cm = new ContextMenu (0, 0, new MenuBarItem (new MenuItem [] { new MenuItem ("One", "", null), @@ -428,7 +431,6 @@ public void Show_Display_At_Zero_If_The_Toplevel_Height_Is_Less_Than_The_Menu_He cm.Show (); Assert.Equal (new Point (0, 0), cm.Position); Application.Begin (Application.Top); - ((FakeDriver)Application.Driver).SetBufferSize (80, 3); var expected = @" ┌──────┐ diff --git a/UnitTests/UnitTests.csproj b/UnitTests/UnitTests.csproj index 2816d89f24..76d83ea4b4 100644 --- a/UnitTests/UnitTests.csproj +++ b/UnitTests/UnitTests.csproj @@ -21,8 +21,8 @@ - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive