|
@@ -3,7 +3,7 @@ using Terminal.Gui;
|
|
|
|
|
|
namespace UICatalog.Scenarios;
|
|
|
|
|
|
-[ScenarioMetadata ("MenuBar", "Demonstrates the MenuBar using the same menu used in unit tests.")]
|
|
|
+[ScenarioMetadata ("MenuBar", "Demonstrates the MenuBar using the demo menu.")]
|
|
|
[ScenarioCategory ("Controls")]
|
|
|
[ScenarioCategory ("Menus")]
|
|
|
public class MenuBarScenario : Scenario
|
|
@@ -14,186 +14,6 @@ public class MenuBarScenario : Scenario
|
|
|
private Label _lastAction;
|
|
|
private Label _lastKey;
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// This method creates at test menu bar. It is called by the MenuBar unit tests, so it's possible to do both unit
|
|
|
- /// testing and user-experience testing with the same setup.
|
|
|
- /// </summary>
|
|
|
- /// <param name="actionFn"></param>
|
|
|
- /// <returns></returns>
|
|
|
- public static MenuBar CreateTestMenu (Func<string, bool> actionFn)
|
|
|
- {
|
|
|
- // TODO: add a disabled menu item to this
|
|
|
- var mb = new MenuBar
|
|
|
- {
|
|
|
- Menus =
|
|
|
- [
|
|
|
- new MenuBarItem (
|
|
|
- "_File",
|
|
|
- new MenuItem []
|
|
|
- {
|
|
|
- new (
|
|
|
- "_New",
|
|
|
- "",
|
|
|
- () => actionFn ("New"),
|
|
|
- null,
|
|
|
- null,
|
|
|
- KeyCode.CtrlMask | KeyCode.N
|
|
|
- ),
|
|
|
- new (
|
|
|
- "_Open",
|
|
|
- "",
|
|
|
- () => actionFn ("Open"),
|
|
|
- null,
|
|
|
- null,
|
|
|
- KeyCode.CtrlMask | KeyCode.O
|
|
|
- ),
|
|
|
- new (
|
|
|
- "_Save",
|
|
|
- "",
|
|
|
- () => actionFn ("Save"),
|
|
|
- null,
|
|
|
- null,
|
|
|
- KeyCode.CtrlMask | KeyCode.S
|
|
|
- ),
|
|
|
- null,
|
|
|
-
|
|
|
- // Don't use Application.Quit so we can disambiguate between quitting and closing the toplevel
|
|
|
- new (
|
|
|
- "_Quit",
|
|
|
- "",
|
|
|
- () => actionFn ("Quit"),
|
|
|
- null,
|
|
|
- null,
|
|
|
- KeyCode.CtrlMask | KeyCode.Q
|
|
|
- )
|
|
|
- }
|
|
|
- ),
|
|
|
- new MenuBarItem (
|
|
|
- "_Edit",
|
|
|
- new MenuItem []
|
|
|
- {
|
|
|
- new (
|
|
|
- "_Copy",
|
|
|
- "",
|
|
|
- () => actionFn ("Copy"),
|
|
|
- null,
|
|
|
- null,
|
|
|
- KeyCode.CtrlMask | KeyCode.C
|
|
|
- ),
|
|
|
- new (
|
|
|
- "C_ut",
|
|
|
- "",
|
|
|
- () => actionFn ("Cut"),
|
|
|
- null,
|
|
|
- null,
|
|
|
- KeyCode.CtrlMask | KeyCode.X
|
|
|
- ),
|
|
|
- new (
|
|
|
- "_Paste",
|
|
|
- "",
|
|
|
- () => actionFn ("Paste"),
|
|
|
- null,
|
|
|
- null,
|
|
|
- KeyCode.CtrlMask | KeyCode.V
|
|
|
- ),
|
|
|
- new MenuBarItem (
|
|
|
- "_Find and Replace",
|
|
|
- new MenuItem []
|
|
|
- {
|
|
|
- new (
|
|
|
- "F_ind",
|
|
|
- "",
|
|
|
- () => actionFn ("Find"),
|
|
|
- null,
|
|
|
- null,
|
|
|
- KeyCode.CtrlMask | KeyCode.F
|
|
|
- ),
|
|
|
- new (
|
|
|
- "_Replace",
|
|
|
- "",
|
|
|
- () => actionFn ("Replace"),
|
|
|
- null,
|
|
|
- null,
|
|
|
- KeyCode.CtrlMask | KeyCode.H
|
|
|
- ),
|
|
|
- new MenuBarItem (
|
|
|
- "_3rd Level",
|
|
|
- new MenuItem []
|
|
|
- {
|
|
|
- new (
|
|
|
- "_1st",
|
|
|
- "",
|
|
|
- () => actionFn (
|
|
|
- "1"
|
|
|
- ),
|
|
|
- null,
|
|
|
- null,
|
|
|
- KeyCode.F1
|
|
|
- ),
|
|
|
- new (
|
|
|
- "_2nd",
|
|
|
- "",
|
|
|
- () => actionFn (
|
|
|
- "2"
|
|
|
- ),
|
|
|
- null,
|
|
|
- null,
|
|
|
- KeyCode.F2
|
|
|
- )
|
|
|
- }
|
|
|
- ),
|
|
|
- new MenuBarItem (
|
|
|
- "_4th Level",
|
|
|
- new MenuItem []
|
|
|
- {
|
|
|
- new (
|
|
|
- "_5th",
|
|
|
- "",
|
|
|
- () => actionFn (
|
|
|
- "5"
|
|
|
- ),
|
|
|
- null,
|
|
|
- null,
|
|
|
- KeyCode.CtrlMask
|
|
|
- | KeyCode.D5
|
|
|
- ),
|
|
|
- new (
|
|
|
- "_6th",
|
|
|
- "",
|
|
|
- () => actionFn (
|
|
|
- "6"
|
|
|
- ),
|
|
|
- null,
|
|
|
- null,
|
|
|
- KeyCode.CtrlMask
|
|
|
- | KeyCode.D6
|
|
|
- )
|
|
|
- }
|
|
|
- )
|
|
|
- }
|
|
|
- ),
|
|
|
- new (
|
|
|
- "_Select All",
|
|
|
- "",
|
|
|
- () => actionFn ("Select All"),
|
|
|
- null,
|
|
|
- null,
|
|
|
- KeyCode.CtrlMask
|
|
|
- | KeyCode.ShiftMask
|
|
|
- | KeyCode.S
|
|
|
- )
|
|
|
- }
|
|
|
- ),
|
|
|
- new MenuBarItem ("_About", "Top-Level", () => actionFn ("About"))
|
|
|
- ]
|
|
|
- };
|
|
|
- mb.UseKeysUpDownAsKeysLeftRight = true;
|
|
|
- mb.Key = KeyCode.F9;
|
|
|
- mb.Title = "TestMenuBar";
|
|
|
-
|
|
|
- return mb;
|
|
|
- }
|
|
|
-
|
|
|
public override void Main ()
|
|
|
{
|
|
|
// Init
|
|
@@ -239,14 +59,19 @@ public class MenuBarScenario : Scenario
|
|
|
_focusedView = new Label { X = Pos.Right (label), Y = Pos.Top (label), Text = "" };
|
|
|
appWindow.Add (_focusedView);
|
|
|
|
|
|
- MenuBar menuBar = CreateTestMenu (
|
|
|
- s =>
|
|
|
- {
|
|
|
- _lastAction.Text = s;
|
|
|
+ MenuBar menuBar = new MenuBar ();
|
|
|
+ menuBar.UseKeysUpDownAsKeysLeftRight = true;
|
|
|
+ menuBar.Key = KeyCode.F9;
|
|
|
+ menuBar.Title = "TestMenuBar";
|
|
|
+
|
|
|
+ bool fnAction (string s)
|
|
|
+ {
|
|
|
+ _lastAction.Text = s;
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
|
|
|
- return true;
|
|
|
- }
|
|
|
- );
|
|
|
+ menuBar.EnableForDesign ((Func<string, bool>)fnAction);
|
|
|
|
|
|
menuBar.MenuOpening += (s, e) =>
|
|
|
{
|