MenuBarItemv2.cs 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #nullable enable
  2. namespace Terminal.Gui;
  3. /// <summary>
  4. /// A <see cref="Shortcut"/>-derived object to be used as items in a <see cref="MenuBarv2"/>.
  5. /// MenuBarItems have a title, a hotkey, and an action to execute on activation.
  6. /// </summary>
  7. public class MenuBarItemv2 : MenuItemv2
  8. {
  9. /// <summary>
  10. /// Creates a new instance of <see cref="MenuBarItemv2"/>.
  11. /// </summary>
  12. public MenuBarItemv2 () : base (null, Command.NotBound) { }
  13. /// <summary>
  14. /// Creates a new instance of <see cref="MenuBarItemv2"/>. Each MenuBarItem typically has a <see cref="PopoverMenu"/>
  15. /// that is
  16. /// shown when the item is selected.
  17. /// </summary>
  18. /// <remarks>
  19. /// </remarks>
  20. /// <param name="targetView">
  21. /// The View that <paramref name="command"/> will be invoked on when user does something that causes the MenuBarItems's
  22. /// Accept event to be raised.
  23. /// </param>
  24. /// <param name="command">
  25. /// The Command to invoke on <paramref name="targetView"/>. The Key <paramref name="targetView"/>
  26. /// has bound to <paramref name="command"/> will be used as <see cref="Key"/>
  27. /// </param>
  28. /// <param name="commandText">The text to display for the command.</param>
  29. /// <param name="popoverMenu">The Popover Menu that will be displayed when this item is selected.</param>
  30. public MenuBarItemv2 (View? targetView, Command command, string? commandText, PopoverMenu? popoverMenu = null)
  31. : base (
  32. targetView,
  33. command,
  34. commandText)
  35. {
  36. TargetView = targetView;
  37. Command = command;
  38. PopoverMenu = popoverMenu;
  39. }
  40. /// <summary>
  41. /// Creates a new instance of <see cref="MenuBarItemv2"/> with the specified <paramref name="popoverMenu"/>. This is a
  42. /// helper for the most common MenuBar use-cases.
  43. /// </summary>
  44. /// <remarks>
  45. /// </remarks>
  46. /// <param name="commandText">The text to display for the command.</param>
  47. /// <param name="popoverMenu">The Popover Menu that will be displayed when this item is selected.</param>
  48. public MenuBarItemv2 (string commandText, PopoverMenu? popoverMenu = null)
  49. : this (
  50. null,
  51. Command.NotBound,
  52. commandText,
  53. popoverMenu)
  54. { }
  55. /// <summary>
  56. /// Creates a new instance of <see cref="MenuBarItemv2"/> with the <paramref name="menuItems"/> automatcialy added to a
  57. /// <see cref="PopoverMenu"/>.
  58. /// This is a helper for the most common MenuBar use-cases.
  59. /// </summary>
  60. /// <remarks>
  61. /// </remarks>
  62. /// <param name="commandText">The text to display for the command.</param>
  63. /// <param name="menuItems">
  64. /// The menu items that will be added to the Popover Menu that will be displayed when this item is
  65. /// selected.
  66. /// </param>
  67. public MenuBarItemv2 (string commandText, IEnumerable<View> menuItems)
  68. : this (
  69. null,
  70. Command.NotBound,
  71. commandText,
  72. new (new (menuItems)))
  73. { }
  74. // TODO: Hide base.SubMenu?
  75. /// <summary>
  76. /// The Popover Menu that will be displayed when this item is selected.
  77. /// </summary>
  78. public PopoverMenu? PopoverMenu { get; set; }
  79. /// <inheritdoc/>
  80. protected override void Dispose (bool disposing)
  81. {
  82. if (disposing)
  83. {
  84. PopoverMenu?.Dispose ();
  85. PopoverMenu = null;
  86. }
  87. base.Dispose (disposing);
  88. }
  89. }