MenuBar.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789
  1. using System.ComponentModel;
  2. using System.Diagnostics;
  3. namespace Terminal.Gui.Views;
  4. /// <summary>
  5. /// A horizontal list of <see cref="MenuBarItem"/>s. Each <see cref="MenuBarItem"/> can have a
  6. /// <see cref="PopoverMenu"/> that is shown when the <see cref="MenuBarItem"/> is selected.
  7. /// </summary>
  8. /// <remarks>
  9. /// MenuBars may be hosted by any View and will, by default, be positioned the full width across the top of the View's
  10. /// Viewport.
  11. /// </remarks>
  12. public class MenuBar : Menu, IDesignable
  13. {
  14. /// <inheritdoc/>
  15. public MenuBar () : this ([]) { }
  16. /// <inheritdoc/>
  17. public MenuBar (IEnumerable<MenuBarItem> menuBarItems) : base (menuBarItems)
  18. {
  19. CanFocus = false;
  20. TabStop = TabBehavior.TabGroup;
  21. Y = 0;
  22. Width = Dim.Fill ();
  23. Height = Dim.Auto ();
  24. Orientation = Orientation.Horizontal;
  25. Key = DefaultKey;
  26. AddCommand (
  27. Command.HotKey,
  28. (ctx) =>
  29. {
  30. // Logging.Debug ($"{Title} - Command.HotKey");
  31. if (RaiseHandlingHotKey (ctx) is true)
  32. {
  33. return true;
  34. }
  35. if (HideActiveItem ())
  36. {
  37. return true;
  38. }
  39. if (SubViews.OfType<MenuBarItem> ().FirstOrDefault (mbi => mbi.PopoverMenu is { }) is { } first)
  40. {
  41. Active = true;
  42. ShowItem (first);
  43. return true;
  44. }
  45. return false;
  46. });
  47. // If we're not focused, Key activates/deactivates
  48. HotKeyBindings.Add (Key, Command.HotKey);
  49. KeyBindings.Add (Key, Command.Quit);
  50. KeyBindings.ReplaceCommands (Application.QuitKey, Command.Quit);
  51. AddCommand (
  52. Command.Quit,
  53. ctx =>
  54. {
  55. // Logging.Debug ($"{Title} - Command.Quit");
  56. if (HideActiveItem ())
  57. {
  58. return true;
  59. }
  60. if (CanFocus)
  61. {
  62. CanFocus = false;
  63. Active = false;
  64. return true;
  65. }
  66. return false; //RaiseAccepted (ctx);
  67. });
  68. AddCommand (Command.Right, MoveRight);
  69. KeyBindings.Add (Key.CursorRight, Command.Right);
  70. AddCommand (Command.Left, MoveLeft);
  71. KeyBindings.Add (Key.CursorLeft, Command.Left);
  72. BorderStyle = DefaultBorderStyle;
  73. ConfigurationManager.Applied += OnConfigurationManagerApplied;
  74. SuperViewChanged += OnSuperViewChanged;
  75. return;
  76. bool? MoveLeft (ICommandContext? ctx) { return AdvanceFocus (NavigationDirection.Backward, TabBehavior.TabStop); }
  77. bool? MoveRight (ICommandContext? ctx) { return AdvanceFocus (NavigationDirection.Forward, TabBehavior.TabStop); }
  78. }
  79. private void OnSuperViewChanged (object? sender, SuperViewChangedEventArgs e)
  80. {
  81. if (SuperView is null)
  82. {
  83. // BUGBUG: This is a hack for avoiding a race condition in ConfigurationManager.Apply
  84. // BUGBUG: For some reason in some unit tests, when Top is disposed, MenuBar.Dispose does not get called.
  85. // BUGBUG: Yet, the MenuBar does get Removed from Top (and it's SuperView set to null).
  86. // BUGBUG: Related: https://github.com/gui-cs/Terminal.Gui/issues/4021
  87. ConfigurationManager.Applied -= OnConfigurationManagerApplied;
  88. }
  89. }
  90. private void OnConfigurationManagerApplied (object? sender, ConfigurationManagerEventArgs e) { BorderStyle = DefaultBorderStyle; }
  91. /// <inheritdoc/>
  92. protected override bool OnBorderStyleChanged ()
  93. {
  94. //HideActiveItem ();
  95. return base.OnBorderStyleChanged ();
  96. }
  97. /// <summary>
  98. /// Gets or sets the default Border Style for the MenuBar. The default is <see cref="LineStyle.None"/>.
  99. /// </summary>
  100. [ConfigurationProperty (Scope = typeof (ThemeScope))]
  101. public new static LineStyle DefaultBorderStyle { get; set; } = LineStyle.None;
  102. private Key _key = DefaultKey;
  103. /// <summary>Specifies the key that will activate the context menu.</summary>
  104. public Key Key
  105. {
  106. get => _key;
  107. set
  108. {
  109. Key oldKey = _key;
  110. _key = value;
  111. KeyChanged?.Invoke (this, new (oldKey, _key));
  112. }
  113. }
  114. /// <summary>
  115. /// Sets the Menu Bar Items for this Menu Bar. This will replace any existing Menu Bar Items.
  116. /// </summary>
  117. /// <remarks>
  118. /// <para>
  119. /// This is a convenience property to help porting from the v1 MenuBar.
  120. /// </para>
  121. /// </remarks>
  122. public MenuBarItem []? Menus
  123. {
  124. set
  125. {
  126. RemoveAll ();
  127. if (value is null)
  128. {
  129. return;
  130. }
  131. foreach (MenuBarItem mbi in value)
  132. {
  133. Add (mbi);
  134. }
  135. }
  136. }
  137. /// <inheritdoc/>
  138. protected override void OnSubViewAdded (View view)
  139. {
  140. base.OnSubViewAdded (view);
  141. if (view is MenuBarItem mbi)
  142. {
  143. mbi.Accepted += OnMenuBarItemAccepted;
  144. mbi.PopoverMenuOpenChanged += OnMenuBarItemPopoverMenuOpenChanged;
  145. }
  146. }
  147. /// <inheritdoc/>
  148. protected override void OnSubViewRemoved (View view)
  149. {
  150. base.OnSubViewRemoved (view);
  151. if (view is MenuBarItem mbi)
  152. {
  153. mbi.Accepted -= OnMenuBarItemAccepted;
  154. mbi.PopoverMenuOpenChanged -= OnMenuBarItemPopoverMenuOpenChanged;
  155. }
  156. }
  157. private void OnMenuBarItemPopoverMenuOpenChanged (object? sender, EventArgs<bool> e)
  158. {
  159. if (sender is MenuBarItem mbi)
  160. {
  161. if (e.Value)
  162. {
  163. Active = true;
  164. }
  165. }
  166. }
  167. private void OnMenuBarItemAccepted (object? sender, CommandEventArgs e)
  168. {
  169. // Logging.Debug ($"{Title} ({e.Context?.Source?.Title}) Command: {e.Context?.Command}");
  170. RaiseAccepted (e.Context);
  171. }
  172. /// <summary>Raised when <see cref="Key"/> is changed.</summary>
  173. public event EventHandler<KeyChangedEventArgs>? KeyChanged;
  174. /// <summary>The default key for activating menu bars.</summary>
  175. [ConfigurationProperty (Scope = typeof (SettingsScope))]
  176. public static Key DefaultKey { get; set; } = Key.F9;
  177. /// <summary>
  178. /// Gets whether any of the menu bar items have a visible <see cref="PopoverMenu"/>.
  179. /// </summary>
  180. /// <exception cref="NotImplementedException"></exception>
  181. public bool IsOpen () { return SubViews.OfType<MenuBarItem> ().Count (sv => sv is { PopoverMenuOpen: true }) > 0; }
  182. /// <summary>
  183. /// Opens the first menu item with a <see cref="PopoverMenu"/>. This is useful for programmatically opening
  184. /// the menu, for example when using the MenuBar as a dropdown list.
  185. /// </summary>
  186. /// <returns><see langword="true"/> if a menu was opened; <see langword="false"/> otherwise.</returns>
  187. /// <remarks>
  188. /// <para>
  189. /// This method activates the MenuBar and shows the first MenuBarItem that has a PopoverMenu.
  190. /// The first menu item in the PopoverMenu will be selected and focused.
  191. /// </para>
  192. /// </remarks>
  193. public bool OpenMenu ()
  194. {
  195. if (SubViews.OfType<MenuBarItem> ().FirstOrDefault (mbi => mbi.PopoverMenu is { }) is { } first)
  196. {
  197. Active = true;
  198. ShowItem (first);
  199. return true;
  200. }
  201. return false;
  202. }
  203. private bool _active;
  204. /// <summary>
  205. /// Gets or sets whether the menu bar is active or not. When active, the MenuBar can focus and moving the mouse
  206. /// over a MenuBarItem will switch focus to that item. Use <see cref="IsOpen"/> to determine if a PopoverMenu of
  207. /// a MenuBarItem is open.
  208. /// </summary>
  209. /// <returns></returns>
  210. public bool Active
  211. {
  212. get => _active;
  213. internal set
  214. {
  215. if (_active == value)
  216. {
  217. return;
  218. }
  219. _active = value;
  220. // Logging.Debug ($"Active set to {_active} - CanFocus: {CanFocus}, HasFocus: {HasFocus}");
  221. if (!_active)
  222. {
  223. // Hide open Popovers
  224. HideActiveItem ();
  225. }
  226. CanFocus = value;
  227. // Logging.Debug ($"Set CanFocus: {CanFocus}, HasFocus: {HasFocus}");
  228. }
  229. }
  230. /// <inheritdoc/>
  231. protected override bool OnMouseEnter (CancelEventArgs eventArgs)
  232. {
  233. // If the MenuBar does not have focus and the mouse enters: Enable CanFocus
  234. // But do NOT show a Popover unless the user clicks or presses a hotkey
  235. // Logging.Debug ($"CanFocus = {CanFocus}, HasFocus = {HasFocus}");
  236. if (!HasFocus)
  237. {
  238. Active = true;
  239. }
  240. return base.OnMouseEnter (eventArgs);
  241. }
  242. /// <inheritdoc/>
  243. protected override void OnMouseLeave ()
  244. {
  245. // Logging.Debug ($"CanFocus = {CanFocus}, HasFocus = {HasFocus}");
  246. if (!IsOpen ())
  247. {
  248. Active = false;
  249. }
  250. base.OnMouseLeave ();
  251. }
  252. /// <inheritdoc/>
  253. protected override void OnHasFocusChanged (bool newHasFocus, View? previousFocusedView, View? focusedView)
  254. {
  255. // Logging.Debug ($"CanFocus = {CanFocus}, HasFocus = {HasFocus}");
  256. if (!newHasFocus)
  257. {
  258. Active = false;
  259. }
  260. }
  261. /// <inheritdoc/>
  262. protected override void OnSelectedMenuItemChanged (MenuItem? selected)
  263. {
  264. // Logging.Debug ($"{Title} ({selected?.Title}) - IsOpen: {IsOpen ()}");
  265. if (IsOpen () && selected is MenuBarItem { PopoverMenuOpen: false } selectedMenuBarItem)
  266. {
  267. ShowItem (selectedMenuBarItem);
  268. }
  269. }
  270. /// <inheritdoc/>
  271. public override void EndInit ()
  272. {
  273. base.EndInit ();
  274. if (Border is { })
  275. {
  276. Border.Thickness = new (0);
  277. Border.LineStyle = LineStyle.None;
  278. }
  279. // TODO: This needs to be done whenever a menuitem in any MenuBarItem changes
  280. foreach (MenuBarItem? mbi in SubViews.Select (s => s as MenuBarItem))
  281. {
  282. App?.Popover?.Register (mbi?.PopoverMenu);
  283. }
  284. }
  285. /// <inheritdoc/>
  286. protected override bool OnAccepting (CommandEventArgs args)
  287. {
  288. // Logging.Debug ($"{Title} ({args.Context?.Source?.Title})");
  289. // TODO: Ensure sourceMenuBar is actually one of our bar items
  290. if (Visible && Enabled && args.Context?.Source is MenuBarItem { PopoverMenuOpen: false } sourceMenuBarItem)
  291. {
  292. if (!CanFocus)
  293. {
  294. Debug.Assert (!Active);
  295. // We are not Active; change that
  296. Active = true;
  297. ShowItem (sourceMenuBarItem);
  298. if (!sourceMenuBarItem.HasFocus)
  299. {
  300. sourceMenuBarItem.SetFocus ();
  301. }
  302. }
  303. else
  304. {
  305. Debug.Assert (Active);
  306. ShowItem (sourceMenuBarItem);
  307. }
  308. return true;
  309. }
  310. return false;
  311. }
  312. /// <inheritdoc/>
  313. protected override void OnAccepted (CommandEventArgs args)
  314. {
  315. // Logging.Debug ($"{Title} ({args.Context?.Source?.Title}) Command: {args.Context?.Command}");
  316. base.OnAccepted (args);
  317. if (SubViews.OfType<MenuBarItem> ().Contains (args.Context?.Source))
  318. {
  319. return;
  320. }
  321. Active = false;
  322. }
  323. /// <summary>
  324. /// Shows the specified popover, but only if the menu bar is active.
  325. /// </summary>
  326. /// <param name="menuBarItem"></param>
  327. private void ShowItem (MenuBarItem? menuBarItem)
  328. {
  329. // Logging.Debug ($"{Title} - {menuBarItem?.Id}");
  330. if (!Active || !Visible)
  331. {
  332. // Logging.Debug ($"{Title} - {menuBarItem?.Id} - Not Active, not showing.");
  333. return;
  334. }
  335. // TODO: We should init the PopoverMenu in a smarter way
  336. if (menuBarItem?.PopoverMenu is { IsInitialized: false })
  337. {
  338. menuBarItem.PopoverMenu.BeginInit ();
  339. menuBarItem.PopoverMenu.EndInit ();
  340. }
  341. // If the active Application Popover is part of this MenuBar, hide it.
  342. if (App?.Popover?.GetActivePopover () is PopoverMenu popoverMenu
  343. && popoverMenu.Root?.SuperMenuItem?.SuperView == this)
  344. {
  345. // Logging.Debug ($"{Title} - Calling App?.Popover?.Hide ({popoverMenu.Title})");
  346. App?.Popover.Hide (popoverMenu);
  347. }
  348. if (menuBarItem is null)
  349. {
  350. // Logging.Debug ($"{Title} - menuBarItem is null.");
  351. return;
  352. }
  353. Active = true;
  354. menuBarItem.SetFocus ();
  355. if (menuBarItem.PopoverMenu?.Root is { })
  356. {
  357. menuBarItem.PopoverMenu.Root.SuperMenuItem = menuBarItem;
  358. menuBarItem.PopoverMenu.Root.SchemeName = SchemeName;
  359. }
  360. // Logging.Debug ($"{Title} - \"{menuBarItem.PopoverMenu?.Title}\".MakeVisible");
  361. if (menuBarItem.PopoverMenu is { })
  362. {
  363. menuBarItem.PopoverMenu.App ??= App;
  364. menuBarItem.PopoverMenu.MakeVisible (new Point (menuBarItem.FrameToScreen ().X, menuBarItem.FrameToScreen ().Bottom));
  365. }
  366. menuBarItem.Accepting += OnMenuItemAccepted;
  367. return;
  368. void OnMenuItemAccepted (object? sender, EventArgs args)
  369. {
  370. // Logging.Debug ($"{Title} - OnMenuItemAccepted");
  371. if (menuBarItem.PopoverMenu is { })
  372. {
  373. menuBarItem.PopoverMenu.VisibleChanged -= OnMenuItemAccepted;
  374. }
  375. if (Active && menuBarItem.PopoverMenu is { Visible: false })
  376. {
  377. Active = false;
  378. HasFocus = false;
  379. }
  380. }
  381. }
  382. private MenuBarItem? GetActiveItem () { return SubViews.OfType<MenuBarItem> ().FirstOrDefault (sv => sv is { PopoverMenu: { Visible: true } }); }
  383. /// <summary>
  384. /// Hides the popover menu associated with the active menu bar item and updates the focus state.
  385. /// </summary>
  386. /// <returns><see langword="true"/> if the popover was hidden</returns>
  387. public bool HideActiveItem () { return HideItem (GetActiveItem ()); }
  388. /// <summary>
  389. /// Hides popover menu associated with the specified menu bar item and updates the focus state.
  390. /// </summary>
  391. /// <param name="activeItem"></param>
  392. /// <returns><see langword="true"/> if the popover was hidden</returns>
  393. public bool HideItem (MenuBarItem? activeItem)
  394. {
  395. // Logging.Debug ($"{Title} ({activeItem?.Title}) - Active: {Active}, CanFocus: {CanFocus}, HasFocus: {HasFocus}");
  396. if (activeItem is null || !activeItem.PopoverMenu!.Visible)
  397. {
  398. // Logging.Debug ($"{Title} No active item.");
  399. return false;
  400. }
  401. // IMPORTANT: Set Visible false before setting Active to false (Active changes Can/HasFocus)
  402. activeItem.PopoverMenu!.Visible = false;
  403. Active = false;
  404. HasFocus = false;
  405. return true;
  406. }
  407. /// <summary>
  408. /// Gets all menu items with the specified Title, anywhere in the menu hierarchy.
  409. /// </summary>
  410. /// <param name="title"></param>
  411. /// <returns></returns>
  412. public IEnumerable<MenuItem> GetMenuItemsWithTitle (string title)
  413. {
  414. List<MenuItem> menuItems = new ();
  415. if (string.IsNullOrEmpty (title))
  416. {
  417. return menuItems;
  418. }
  419. foreach (MenuBarItem mbi in SubViews.OfType<MenuBarItem> ())
  420. {
  421. if (mbi.PopoverMenu is { })
  422. {
  423. menuItems.AddRange (mbi.PopoverMenu.GetMenuItemsOfAllSubMenus ());
  424. }
  425. }
  426. return menuItems.Where (mi => mi.Title == title);
  427. }
  428. /// <inheritdoc/>
  429. public bool EnableForDesign<TContext> (ref TContext targetView) where TContext : notnull
  430. {
  431. // Note: This menu is used by unit tests. If you modify it, you'll likely have to update
  432. // unit tests.
  433. if (targetView is View target)
  434. {
  435. App ??= target.App;
  436. }
  437. Id = "DemoBar";
  438. var bordersCb = new CheckBox
  439. {
  440. Title = "_Borders",
  441. CheckedState = CheckState.Checked
  442. };
  443. var autoSaveCb = new CheckBox
  444. {
  445. Title = "_Auto Save"
  446. };
  447. var enableOverwriteCb = new CheckBox
  448. {
  449. Title = "Enable _Overwrite"
  450. };
  451. var mutuallyExclusiveOptionsSelector = new OptionSelector
  452. {
  453. Labels = ["G_ood", "_Bad", "U_gly"],
  454. Value = 0
  455. };
  456. var menuBgColorCp = new ColorPicker
  457. {
  458. Width = 30
  459. };
  460. menuBgColorCp.ColorChanged += (sender, args) =>
  461. {
  462. // BUGBUG: This is weird.
  463. SetScheme (
  464. GetScheme () with
  465. {
  466. Normal = new (
  467. GetAttributeForRole (VisualRole.Normal).Foreground,
  468. args.Result,
  469. GetAttributeForRole (VisualRole.Normal).Style)
  470. });
  471. };
  472. Add (
  473. new MenuBarItem (
  474. "_File",
  475. [
  476. new MenuItem (targetView as View, Command.New),
  477. new MenuItem (targetView as View, Command.Open),
  478. new MenuItem (targetView as View, Command.Save),
  479. new MenuItem (targetView as View, Command.SaveAs),
  480. new Line (),
  481. new MenuItem
  482. {
  483. Title = "_File Options",
  484. SubMenu = new (
  485. [
  486. new ()
  487. {
  488. Id = "AutoSave",
  489. Text = "(no Command)",
  490. Key = Key.F10,
  491. CommandView = autoSaveCb
  492. },
  493. new ()
  494. {
  495. Text = "Overwrite",
  496. Id = "Overwrite",
  497. Key = Key.W.WithCtrl,
  498. CommandView = enableOverwriteCb,
  499. Command = Command.EnableOverwrite,
  500. TargetView = targetView as View
  501. },
  502. new ()
  503. {
  504. Title = "_File Settings...",
  505. HelpText = "More file settings",
  506. Action = () => MessageBox.Query (
  507. "File Settings",
  508. "This is the File Settings Dialog\n",
  509. "_Ok",
  510. "_Cancel")
  511. }
  512. ]
  513. )
  514. },
  515. new Line (),
  516. new MenuItem
  517. {
  518. Title = "_Preferences",
  519. SubMenu = new (
  520. [
  521. new MenuItem
  522. {
  523. CommandView = bordersCb,
  524. HelpText = "Toggle Menu Borders",
  525. Action = ToggleMenuBorders
  526. },
  527. new MenuItem
  528. {
  529. HelpText = "3 Mutually Exclusive Options",
  530. CommandView = mutuallyExclusiveOptionsSelector,
  531. Key = Key.F7
  532. },
  533. new Line (),
  534. new MenuItem
  535. {
  536. HelpText = "MenuBar BG Color",
  537. CommandView = menuBgColorCp,
  538. Key = Key.F8
  539. }
  540. ]
  541. )
  542. },
  543. new Line (),
  544. new MenuItem
  545. {
  546. TargetView = targetView as View,
  547. Key = Application.QuitKey,
  548. Command = Command.Quit
  549. }
  550. ]
  551. )
  552. );
  553. Add (
  554. new MenuBarItem (
  555. "_Edit",
  556. [
  557. new MenuItem (targetView as View, Command.Cut),
  558. new MenuItem (targetView as View, Command.Copy),
  559. new MenuItem (targetView as View, Command.Paste),
  560. new Line (),
  561. new MenuItem (targetView as View, Command.SelectAll),
  562. new Line (),
  563. new MenuItem
  564. {
  565. Title = "_Details",
  566. SubMenu = new (ConfigureDetailsSubMenu ())
  567. }
  568. ]
  569. )
  570. );
  571. Add (
  572. new MenuBarItem (
  573. "_Help",
  574. [
  575. new MenuItem
  576. {
  577. Title = "_Online Help...",
  578. Action = () => MessageBox.Query ("Online Help", "https://gui-cs.github.io/Terminal.Gui", "Ok")
  579. },
  580. new MenuItem
  581. {
  582. Title = "About...",
  583. Action = () => MessageBox.Query ("About", "Something About Mary.", "Ok")
  584. }
  585. ]
  586. )
  587. );
  588. return true;
  589. void ToggleMenuBorders ()
  590. {
  591. foreach (MenuBarItem mbi in SubViews.OfType<MenuBarItem> ())
  592. {
  593. if (mbi is not { PopoverMenu: { } })
  594. {
  595. continue;
  596. }
  597. foreach (Menu? subMenu in mbi.PopoverMenu.GetAllSubMenus ())
  598. {
  599. if (bordersCb.CheckedState == CheckState.Checked)
  600. {
  601. subMenu.Border!.Thickness = new (1);
  602. }
  603. else
  604. {
  605. subMenu.Border!.Thickness = new (0);
  606. }
  607. }
  608. }
  609. }
  610. MenuItem [] ConfigureDetailsSubMenu ()
  611. {
  612. var detail = new MenuItem
  613. {
  614. Title = "_Detail 1",
  615. Text = "Some detail #1"
  616. };
  617. var nestedSubMenu = new MenuItem
  618. {
  619. Title = "_Moar Details",
  620. SubMenu = new (ConfigureMoreDetailsSubMenu ())
  621. };
  622. var editMode = new MenuItem
  623. {
  624. Text = "App Binding to Command.Edit",
  625. Id = "EditMode",
  626. Command = Command.Edit,
  627. CommandView = new CheckBox
  628. {
  629. Title = "E_dit Mode"
  630. }
  631. };
  632. return [detail, nestedSubMenu, null!, editMode];
  633. View [] ConfigureMoreDetailsSubMenu ()
  634. {
  635. var deeperDetail = new MenuItem
  636. {
  637. Title = "_Deeper Detail",
  638. Text = "Deeper Detail",
  639. Action = () => { MessageBox.Query ("Deeper Detail", "Lots of details", "_Ok"); }
  640. };
  641. var belowLineDetail = new MenuItem
  642. {
  643. Title = "_Even more detail",
  644. Text = "Below the line"
  645. };
  646. // This ensures the checkbox state toggles when the hotkey of Title is pressed.
  647. //shortcut4.Accepting += (sender, args) => args.Cancel = true;
  648. return [deeperDetail, new Line (), belowLineDetail];
  649. }
  650. }
  651. }
  652. /// <inheritdoc/>
  653. protected override void Dispose (bool disposing)
  654. {
  655. base.Dispose (disposing);
  656. if (disposing)
  657. {
  658. SuperViewChanged += OnSuperViewChanged;
  659. ConfigurationManager.Applied -= OnConfigurationManagerApplied;
  660. }
  661. }
  662. }