Преглед изворни кода

Fixes #3754. UICatalog throws System.NullReferenceException on MenuBar in Linux. (#3755)

BDisp пре 10 месеци
родитељ
комит
85fcbdf24e
2 измењених фајлова са 25 додато и 1 уклоњено
  1. 1 1
      Terminal.Gui/Views/Menu/Menu.cs
  2. 24 0
      UnitTests/Views/MenuBarTests.cs

+ 1 - 1
Terminal.Gui/Views/Menu/Menu.cs

@@ -101,7 +101,7 @@ internal sealed class Menu : View
 
             for (var i = 0; i < _barItems.Children?.Length; i++)
             {
-                if (_barItems.Children [i]!.IsEnabled ())
+                if (_barItems.Children [i]?.IsEnabled () == true)
                 {
                     _currentChild = i;
 

+ 24 - 0
UnitTests/Views/MenuBarTests.cs

@@ -148,6 +148,30 @@ public class MenuBarTests (ITestOutputHelper output)
         top.Dispose ();
     }
 
+    [Fact]
+    [AutoInitShutdown]
+    public void CanExecute_False_Does_Not_Throws ()
+    {
+        var menu = new MenuBar
+        {
+            Menus =
+            [
+                new ("File", new MenuItem []
+                {
+                    new ("New", "", null, () => false),
+                    null,
+                    new ("Quit", "", null)
+                })
+            ]
+        };
+        var top = new Toplevel ();
+        top.Add (menu);
+        Application.Begin (top);
+
+        Assert.True (menu.NewKeyDownEvent (menu.Key));
+        Assert.True (menu.IsMenuOpen);
+    }
+
     [Fact]
     [AutoInitShutdown]
     public void CanExecute_HotKey ()