Removes the v1 Menu stuff. Preps for #4148 (#4402)

This commit is contained in:
Tig
2025-11-21 06:51:56 -07:00
committed by GitHub
parent a229f4e3e9
commit 171a26a350
76 changed files with 4614 additions and 13105 deletions

View File

@@ -1,4 +1,4 @@
using System.Linq;
#nullable enable
namespace UICatalog.Scenarios;
@@ -7,46 +7,54 @@ namespace UICatalog.Scenarios;
[ScenarioCategory ("TreeView")]
public class InteractiveTree : Scenario
{
private TreeView _treeView;
private TreeView? _treeView;
public override void Main ()
{
Application.Init ();
var appWindow = new Toplevel ()
Window appWindow = new ()
{
Title = GetName (),
BorderStyle = LineStyle.None
};
var menu = new MenuBar
{
Menus =
[
new ("_File", new MenuItem [] { new ("_Quit", "", Quit) })
]
};
appWindow.Add (menu);
// MenuBar
MenuBar menu = new ();
menu.Add (
new MenuBarItem (
"_File",
[
new MenuItem
{
Title = "_Quit",
Action = Quit
}
]
)
);
_treeView = new ()
{
X = 0,
Y = 1,
Y = Pos.Bottom (menu),
Width = Dim.Fill (),
Height = Dim.Fill (1)
};
_treeView.KeyDown += TreeView_KeyPress;
appWindow.Add (_treeView);
// StatusBar
StatusBar statusBar = new (
[
new (Application.QuitKey, "Quit", Quit),
new (Key.C.WithCtrl, "Add Child", AddChildNode),
new (Key.T.WithCtrl, "Add Root", AddRootNode),
new (Key.R.WithCtrl, "Rename Node", RenameNode)
]
);
var statusBar = new StatusBar (
new Shortcut []
{
new (Application.QuitKey, "Quit", Quit),
new (Key.C.WithCtrl, "Add Child", AddChildNode),
new (Key.T.WithCtrl, "Add Root", AddRootNode),
new (Key.R.WithCtrl, "Rename Node", RenameNode)
}
);
appWindow.Add (statusBar);
appWindow.Add (menu, _treeView, statusBar);
Application.Run (appWindow);
appWindow.Dispose ();
@@ -55,9 +63,14 @@ public class InteractiveTree : Scenario
private void AddChildNode ()
{
ITreeNode node = _treeView.SelectedObject;
if (_treeView is null)
{
return;
}
if (node != null)
ITreeNode? node = _treeView.SelectedObject;
if (node is { })
{
if (GetText ("Text", "Enter text for node:", "", out string entered))
{
@@ -69,6 +82,11 @@ public class InteractiveTree : Scenario
private void AddRootNode ()
{
if (_treeView is null)
{
return;
}
if (GetText ("Text", "Enter text for node:", "", out string entered))
{
_treeView.AddObject (new TreeNode (entered));
@@ -79,20 +97,20 @@ public class InteractiveTree : Scenario
{
var okPressed = false;
var ok = new Button { Text = "Ok", IsDefault = true };
Button ok = new () { Text = "Ok", IsDefault = true };
ok.Accepting += (s, e) =>
{
okPressed = true;
Application.RequestStop ();
};
var cancel = new Button { Text = "Cancel" };
{
okPressed = true;
Application.RequestStop ();
};
Button cancel = new () { Text = "Cancel" };
cancel.Accepting += (s, e) => Application.RequestStop ();
var d = new Dialog { Title = title, Buttons = [ok, cancel] };
Dialog d = new () { Title = title, Buttons = [ok, cancel] };
var lbl = new Label { X = 0, Y = 1, Text = label };
Label lbl = new () { X = 0, Y = 1, Text = label };
var tf = new TextField { Text = initialText, X = 0, Y = 2, Width = Dim.Fill () };
TextField tf = new () { Text = initialText, X = 0, Y = 2, Width = Dim.Fill () };
d.Add (lbl, tf);
tf.SetFocus ();
@@ -100,7 +118,7 @@ public class InteractiveTree : Scenario
Application.Run (d);
d.Dispose ();
enteredText = okPressed ? tf.Text : null;
enteredText = okPressed ? tf.Text : string.Empty;
return okPressed;
}
@@ -109,9 +127,14 @@ public class InteractiveTree : Scenario
private void RenameNode ()
{
ITreeNode node = _treeView.SelectedObject;
if (_treeView is null)
{
return;
}
if (node != null)
ITreeNode? node = _treeView.SelectedObject;
if (node is { })
{
if (GetText ("Text", "Enter text for node:", node.Text, out string entered))
{
@@ -121,13 +144,18 @@ public class InteractiveTree : Scenario
}
}
private void TreeView_KeyPress (object sender, Key obj)
private void TreeView_KeyPress (object? sender, Key obj)
{
if (_treeView is null)
{
return;
}
if (obj.KeyCode == Key.Delete)
{
ITreeNode toDelete = _treeView.SelectedObject;
ITreeNode? toDelete = _treeView.SelectedObject;
if (toDelete == null)
if (toDelete is null)
{
return;
}
@@ -141,9 +169,9 @@ public class InteractiveTree : Scenario
}
else
{
ITreeNode parent = _treeView.GetParent (toDelete);
ITreeNode? parent = _treeView.GetParent (toDelete);
if (parent == null)
if (parent is null)
{
MessageBox.ErrorQuery (
"Could not delete",