MenuBar.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765
  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. private bool _active;
  183. /// <summary>
  184. /// Gets or sets whether the menu bar is active or not. When active, the MenuBar can focus and moving the mouse
  185. /// over a MenuBarItem will switch focus to that item. Use <see cref="IsOpen"/> to determine if a PopoverMenu of
  186. /// a MenuBarItem is open.
  187. /// </summary>
  188. /// <returns></returns>
  189. public bool Active
  190. {
  191. get => _active;
  192. internal set
  193. {
  194. if (_active == value)
  195. {
  196. return;
  197. }
  198. _active = value;
  199. // Logging.Debug ($"Active set to {_active} - CanFocus: {CanFocus}, HasFocus: {HasFocus}");
  200. if (!_active)
  201. {
  202. // Hide open Popovers
  203. HideActiveItem ();
  204. }
  205. CanFocus = value;
  206. // Logging.Debug ($"Set CanFocus: {CanFocus}, HasFocus: {HasFocus}");
  207. }
  208. }
  209. /// <inheritdoc/>
  210. protected override bool OnMouseEnter (CancelEventArgs eventArgs)
  211. {
  212. // If the MenuBar does not have focus and the mouse enters: Enable CanFocus
  213. // But do NOT show a Popover unless the user clicks or presses a hotkey
  214. // Logging.Debug ($"CanFocus = {CanFocus}, HasFocus = {HasFocus}");
  215. if (!HasFocus)
  216. {
  217. Active = true;
  218. }
  219. return base.OnMouseEnter (eventArgs);
  220. }
  221. /// <inheritdoc/>
  222. protected override void OnMouseLeave ()
  223. {
  224. // Logging.Debug ($"CanFocus = {CanFocus}, HasFocus = {HasFocus}");
  225. if (!IsOpen ())
  226. {
  227. Active = false;
  228. }
  229. base.OnMouseLeave ();
  230. }
  231. /// <inheritdoc/>
  232. protected override void OnHasFocusChanged (bool newHasFocus, View? previousFocusedView, View? focusedView)
  233. {
  234. // Logging.Debug ($"CanFocus = {CanFocus}, HasFocus = {HasFocus}");
  235. if (!newHasFocus)
  236. {
  237. Active = false;
  238. }
  239. }
  240. /// <inheritdoc/>
  241. protected override void OnSelectedMenuItemChanged (MenuItem? selected)
  242. {
  243. // Logging.Debug ($"{Title} ({selected?.Title}) - IsOpen: {IsOpen ()}");
  244. if (IsOpen () && selected is MenuBarItem { PopoverMenuOpen: false } selectedMenuBarItem)
  245. {
  246. ShowItem (selectedMenuBarItem);
  247. }
  248. }
  249. /// <inheritdoc/>
  250. public override void EndInit ()
  251. {
  252. base.EndInit ();
  253. if (Border is { })
  254. {
  255. Border.Thickness = new (0);
  256. Border.LineStyle = LineStyle.None;
  257. }
  258. // TODO: This needs to be done whenever a menuitem in any MenuBarItem changes
  259. foreach (MenuBarItem? mbi in SubViews.Select (s => s as MenuBarItem))
  260. {
  261. App?.Popover?.Register (mbi?.PopoverMenu);
  262. }
  263. }
  264. /// <inheritdoc/>
  265. protected override bool OnAccepting (CommandEventArgs args)
  266. {
  267. // Logging.Debug ($"{Title} ({args.Context?.Source?.Title})");
  268. // TODO: Ensure sourceMenuBar is actually one of our bar items
  269. if (Visible && Enabled && args.Context?.Source is MenuBarItem { PopoverMenuOpen: false } sourceMenuBarItem)
  270. {
  271. if (!CanFocus)
  272. {
  273. Debug.Assert (!Active);
  274. // We are not Active; change that
  275. Active = true;
  276. ShowItem (sourceMenuBarItem);
  277. if (!sourceMenuBarItem.HasFocus)
  278. {
  279. sourceMenuBarItem.SetFocus ();
  280. }
  281. }
  282. else
  283. {
  284. Debug.Assert (Active);
  285. ShowItem (sourceMenuBarItem);
  286. }
  287. return true;
  288. }
  289. return false;
  290. }
  291. /// <inheritdoc/>
  292. protected override void OnAccepted (CommandEventArgs args)
  293. {
  294. // Logging.Debug ($"{Title} ({args.Context?.Source?.Title}) Command: {args.Context?.Command}");
  295. base.OnAccepted (args);
  296. if (SubViews.OfType<MenuBarItem> ().Contains (args.Context?.Source))
  297. {
  298. return;
  299. }
  300. Active = false;
  301. }
  302. /// <summary>
  303. /// Shows the specified popover, but only if the menu bar is active.
  304. /// </summary>
  305. /// <param name="menuBarItem"></param>
  306. private void ShowItem (MenuBarItem? menuBarItem)
  307. {
  308. // Logging.Debug ($"{Title} - {menuBarItem?.Id}");
  309. if (!Active || !Visible)
  310. {
  311. // Logging.Debug ($"{Title} - {menuBarItem?.Id} - Not Active, not showing.");
  312. return;
  313. }
  314. // TODO: We should init the PopoverMenu in a smarter way
  315. if (menuBarItem?.PopoverMenu is { IsInitialized: false })
  316. {
  317. menuBarItem.PopoverMenu.BeginInit ();
  318. menuBarItem.PopoverMenu.EndInit ();
  319. }
  320. // If the active Application Popover is part of this MenuBar, hide it.
  321. if (App?.Popover?.GetActivePopover () is PopoverMenu popoverMenu
  322. && popoverMenu.Root?.SuperMenuItem?.SuperView == this)
  323. {
  324. // Logging.Debug ($"{Title} - Calling App?.Popover?.Hide ({popoverMenu.Title})");
  325. App?.Popover.Hide (popoverMenu);
  326. }
  327. if (menuBarItem is null)
  328. {
  329. // Logging.Debug ($"{Title} - menuBarItem is null.");
  330. return;
  331. }
  332. Active = true;
  333. menuBarItem.SetFocus ();
  334. if (menuBarItem.PopoverMenu?.Root is { })
  335. {
  336. menuBarItem.PopoverMenu.Root.SuperMenuItem = menuBarItem;
  337. menuBarItem.PopoverMenu.Root.SchemeName = SchemeName;
  338. }
  339. // Logging.Debug ($"{Title} - \"{menuBarItem.PopoverMenu?.Title}\".MakeVisible");
  340. if (menuBarItem.PopoverMenu is { })
  341. {
  342. menuBarItem.PopoverMenu.App ??= App;
  343. menuBarItem.PopoverMenu.MakeVisible (new Point (menuBarItem.FrameToScreen ().X, menuBarItem.FrameToScreen ().Bottom));
  344. }
  345. menuBarItem.Accepting += OnMenuItemAccepted;
  346. return;
  347. void OnMenuItemAccepted (object? sender, EventArgs args)
  348. {
  349. // Logging.Debug ($"{Title} - OnMenuItemAccepted");
  350. if (menuBarItem.PopoverMenu is { })
  351. {
  352. menuBarItem.PopoverMenu.VisibleChanged -= OnMenuItemAccepted;
  353. }
  354. if (Active && menuBarItem.PopoverMenu is { Visible: false })
  355. {
  356. Active = false;
  357. HasFocus = false;
  358. }
  359. }
  360. }
  361. private MenuBarItem? GetActiveItem () { return SubViews.OfType<MenuBarItem> ().FirstOrDefault (sv => sv is { PopoverMenu: { Visible: true } }); }
  362. /// <summary>
  363. /// Hides the popover menu associated with the active menu bar item and updates the focus state.
  364. /// </summary>
  365. /// <returns><see langword="true"/> if the popover was hidden</returns>
  366. public bool HideActiveItem () { return HideItem (GetActiveItem ()); }
  367. /// <summary>
  368. /// Hides popover menu associated with the specified menu bar item and updates the focus state.
  369. /// </summary>
  370. /// <param name="activeItem"></param>
  371. /// <returns><see langword="true"/> if the popover was hidden</returns>
  372. public bool HideItem (MenuBarItem? activeItem)
  373. {
  374. // Logging.Debug ($"{Title} ({activeItem?.Title}) - Active: {Active}, CanFocus: {CanFocus}, HasFocus: {HasFocus}");
  375. if (activeItem is null || !activeItem.PopoverMenu!.Visible)
  376. {
  377. // Logging.Debug ($"{Title} No active item.");
  378. return false;
  379. }
  380. // IMPORTANT: Set Visible false before setting Active to false (Active changes Can/HasFocus)
  381. activeItem.PopoverMenu!.Visible = false;
  382. Active = false;
  383. HasFocus = false;
  384. return true;
  385. }
  386. /// <summary>
  387. /// Gets all menu items with the specified Title, anywhere in the menu hierarchy.
  388. /// </summary>
  389. /// <param name="title"></param>
  390. /// <returns></returns>
  391. public IEnumerable<MenuItem> GetMenuItemsWithTitle (string title)
  392. {
  393. List<MenuItem> menuItems = new ();
  394. if (string.IsNullOrEmpty (title))
  395. {
  396. return menuItems;
  397. }
  398. foreach (MenuBarItem mbi in SubViews.OfType<MenuBarItem> ())
  399. {
  400. if (mbi.PopoverMenu is { })
  401. {
  402. menuItems.AddRange (mbi.PopoverMenu.GetMenuItemsOfAllSubMenus ());
  403. }
  404. }
  405. return menuItems.Where (mi => mi.Title == title);
  406. }
  407. /// <inheritdoc/>
  408. public bool EnableForDesign<TContext> (ref TContext targetView) where TContext : notnull
  409. {
  410. // Note: This menu is used by unit tests. If you modify it, you'll likely have to update
  411. // unit tests.
  412. if (targetView is View target)
  413. {
  414. App ??= target.App;
  415. }
  416. Id = "DemoBar";
  417. var bordersCb = new CheckBox
  418. {
  419. Title = "_Borders",
  420. CheckedState = CheckState.Checked
  421. };
  422. var autoSaveCb = new CheckBox
  423. {
  424. Title = "_Auto Save"
  425. };
  426. var enableOverwriteCb = new CheckBox
  427. {
  428. Title = "Enable _Overwrite"
  429. };
  430. var mutuallyExclusiveOptionsSelector = new OptionSelector
  431. {
  432. Labels = ["G_ood", "_Bad", "U_gly"],
  433. Value = 0
  434. };
  435. var menuBgColorCp = new ColorPicker
  436. {
  437. Width = 30
  438. };
  439. menuBgColorCp.ColorChanged += (sender, args) =>
  440. {
  441. // BUGBUG: This is weird.
  442. SetScheme (
  443. GetScheme () with
  444. {
  445. Normal = new (
  446. GetAttributeForRole (VisualRole.Normal).Foreground,
  447. args.Result,
  448. GetAttributeForRole (VisualRole.Normal).Style)
  449. });
  450. };
  451. Add (
  452. new MenuBarItem (
  453. "_File",
  454. [
  455. new MenuItem (targetView as View, Command.New),
  456. new MenuItem (targetView as View, Command.Open),
  457. new MenuItem (targetView as View, Command.Save),
  458. new MenuItem (targetView as View, Command.SaveAs),
  459. new Line (),
  460. new MenuItem
  461. {
  462. Title = "_File Options",
  463. SubMenu = new (
  464. [
  465. new ()
  466. {
  467. Id = "AutoSave",
  468. Text = "(no Command)",
  469. Key = Key.F10,
  470. CommandView = autoSaveCb
  471. },
  472. new ()
  473. {
  474. Text = "Overwrite",
  475. Id = "Overwrite",
  476. Key = Key.W.WithCtrl,
  477. CommandView = enableOverwriteCb,
  478. Command = Command.EnableOverwrite,
  479. TargetView = targetView as View
  480. },
  481. new ()
  482. {
  483. Title = "_File Settings...",
  484. HelpText = "More file settings",
  485. Action = () => MessageBox.Query (App,
  486. "File Settings",
  487. "This is the File Settings Dialog\n",
  488. "_Ok",
  489. "_Cancel")
  490. }
  491. ]
  492. )
  493. },
  494. new Line (),
  495. new MenuItem
  496. {
  497. Title = "_Preferences",
  498. SubMenu = new (
  499. [
  500. new MenuItem
  501. {
  502. CommandView = bordersCb,
  503. HelpText = "Toggle Menu Borders",
  504. Action = ToggleMenuBorders
  505. },
  506. new MenuItem
  507. {
  508. HelpText = "3 Mutually Exclusive Options",
  509. CommandView = mutuallyExclusiveOptionsSelector,
  510. Key = Key.F7
  511. },
  512. new Line (),
  513. new MenuItem
  514. {
  515. HelpText = "MenuBar BG Color",
  516. CommandView = menuBgColorCp,
  517. Key = Key.F8
  518. }
  519. ]
  520. )
  521. },
  522. new Line (),
  523. new MenuItem
  524. {
  525. TargetView = targetView as View,
  526. Key = Application.QuitKey,
  527. Command = Command.Quit
  528. }
  529. ]
  530. )
  531. );
  532. Add (
  533. new MenuBarItem (
  534. "_Edit",
  535. [
  536. new MenuItem (targetView as View, Command.Cut),
  537. new MenuItem (targetView as View, Command.Copy),
  538. new MenuItem (targetView as View, Command.Paste),
  539. new Line (),
  540. new MenuItem (targetView as View, Command.SelectAll),
  541. new Line (),
  542. new MenuItem
  543. {
  544. Title = "_Details",
  545. SubMenu = new (ConfigureDetailsSubMenu ())
  546. }
  547. ]
  548. )
  549. );
  550. Add (
  551. new MenuBarItem (
  552. "_Help",
  553. [
  554. new MenuItem
  555. {
  556. Title = "_Online Help...",
  557. Action = () => MessageBox.Query (App, "Online Help", "https://gui-cs.github.io/Terminal.Gui", "Ok")
  558. },
  559. new MenuItem
  560. {
  561. Title = "About...",
  562. Action = () => MessageBox.Query (App, "About", "Something About Mary.", "Ok")
  563. }
  564. ]
  565. )
  566. );
  567. return true;
  568. void ToggleMenuBorders ()
  569. {
  570. foreach (MenuBarItem mbi in SubViews.OfType<MenuBarItem> ())
  571. {
  572. if (mbi is not { PopoverMenu: { } })
  573. {
  574. continue;
  575. }
  576. foreach (Menu? subMenu in mbi.PopoverMenu.GetAllSubMenus ())
  577. {
  578. if (bordersCb.CheckedState == CheckState.Checked)
  579. {
  580. subMenu.Border!.Thickness = new (1);
  581. }
  582. else
  583. {
  584. subMenu.Border!.Thickness = new (0);
  585. }
  586. }
  587. }
  588. }
  589. MenuItem [] ConfigureDetailsSubMenu ()
  590. {
  591. var detail = new MenuItem
  592. {
  593. Title = "_Detail 1",
  594. Text = "Some detail #1"
  595. };
  596. var nestedSubMenu = new MenuItem
  597. {
  598. Title = "_Moar Details",
  599. SubMenu = new (ConfigureMoreDetailsSubMenu ())
  600. };
  601. var editMode = new MenuItem
  602. {
  603. Text = "App Binding to Command.Edit",
  604. Id = "EditMode",
  605. Command = Command.Edit,
  606. CommandView = new CheckBox
  607. {
  608. Title = "E_dit Mode"
  609. }
  610. };
  611. return [detail, nestedSubMenu, null!, editMode];
  612. View [] ConfigureMoreDetailsSubMenu ()
  613. {
  614. var deeperDetail = new MenuItem
  615. {
  616. Title = "_Deeper Detail",
  617. Text = "Deeper Detail",
  618. Action = () => { MessageBox.Query (App, "Deeper Detail", "Lots of details", "_Ok"); }
  619. };
  620. var belowLineDetail = new MenuItem
  621. {
  622. Title = "_Even more detail",
  623. Text = "Below the line"
  624. };
  625. // This ensures the checkbox state toggles when the hotkey of Title is pressed.
  626. //shortcut4.Accepting += (sender, args) => args.Cancel = true;
  627. return [deeperDetail, new Line (), belowLineDetail];
  628. }
  629. }
  630. }
  631. /// <inheritdoc/>
  632. protected override void Dispose (bool disposing)
  633. {
  634. base.Dispose (disposing);
  635. if (disposing)
  636. {
  637. SuperViewChanged += OnSuperViewChanged;
  638. ConfigurationManager.Applied -= OnConfigurationManagerApplied;
  639. }
  640. }
  641. }