From 5e7bfb890859a46fec8c6cb40b544367f5feeab8 Mon Sep 17 00:00:00 2001 From: Daniel Marbach Date: Sun, 31 Aug 2025 17:52:33 +0200 Subject: [PATCH] Root SchemeName can only be set when the popover is not null (#4226) * Root schema can only be set when the popover is not null * Fix event selection * Remove unnecessary null forgiving --------- Co-authored-by: Daniel Marbach Co-authored-by: Tig --- Terminal.Gui/Views/Menu/MenuBarv2.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Terminal.Gui/Views/Menu/MenuBarv2.cs b/Terminal.Gui/Views/Menu/MenuBarv2.cs index 7690e2b85..1385aa24e 100644 --- a/Terminal.Gui/Views/Menu/MenuBarv2.cs +++ b/Terminal.Gui/Views/Menu/MenuBarv2.cs @@ -397,10 +397,10 @@ public class MenuBarv2 : Menuv2, IDesignable // If the active Application Popover is part of this MenuBar, hide it. if (Application.Popover?.GetActivePopover () is PopoverMenu popoverMenu - && popoverMenu?.Root?.SuperMenuItem?.SuperView == this) + && popoverMenu.Root?.SuperMenuItem?.SuperView == this) { // Logging.Debug ($"{Title} - Calling Application.Popover?.Hide ({popoverMenu.Title})"); - Application.Popover?.Hide (popoverMenu); + Application.Popover.Hide (popoverMenu); } if (menuBarItem is null) @@ -416,6 +416,7 @@ public class MenuBarv2 : Menuv2, IDesignable if (menuBarItem.PopoverMenu?.Root is { }) { menuBarItem.PopoverMenu.Root.SuperMenuItem = menuBarItem; + menuBarItem.PopoverMenu.Root.SchemeName = SchemeName; } // Logging.Debug ($"{Title} - \"{menuBarItem.PopoverMenu?.Title}\".MakeVisible"); @@ -423,14 +424,15 @@ public class MenuBarv2 : Menuv2, IDesignable menuBarItem.Accepting += OnMenuItemAccepted; - menuBarItem.PopoverMenu!.Root.SchemeName = SchemeName; - return; void OnMenuItemAccepted (object? sender, EventArgs args) { // Logging.Debug ($"{Title} - OnMenuItemAccepted"); - menuBarItem.PopoverMenu!.VisibleChanged -= OnMenuItemAccepted; + if (menuBarItem.PopoverMenu is { }) + { + menuBarItem.PopoverMenu.VisibleChanged -= OnMenuItemAccepted; + } if (Active && menuBarItem.PopoverMenu is { Visible: false }) {