Skip to content

Commit

Permalink
Fixes #3754. UICatalog throws System.NullReferenceException on MenuBa…
Browse files Browse the repository at this point in the history
…r in Linux. (#3755)
  • Loading branch information
BDisp committed Sep 24, 2024
1 parent ee13e2c commit 85fcbdf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Terminal.Gui/Views/Menu/Menu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public override void BeginInit ()

for (var i = 0; i < _barItems.Children?.Length; i++)
{
if (_barItems.Children [i]!.IsEnabled ())
if (_barItems.Children [i]?.IsEnabled () == true)
{
_currentChild = i;

Expand Down
24 changes: 24 additions & 0 deletions UnitTests/Views/MenuBarTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,30 @@ Nullable Checked
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 ()
Expand Down

0 comments on commit 85fcbdf

Please sign in to comment.