Bläddra i källkod

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 <[email protected]>
Co-authored-by: Tig <[email protected]>
Daniel Marbach 1 vecka sedan
förälder
incheckning
5e7bfb8908
1 ändrade filer med 7 tillägg och 5 borttagningar
  1. 7 5
      Terminal.Gui/Views/Menu/MenuBarv2.cs

+ 7 - 5
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 })
             {