Shortcut.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758
  1. using System.ComponentModel;
  2. using System.Reflection.Metadata;
  3. using Terminal.Gui.Analyzers.Internal.Attributes;
  4. namespace Terminal.Gui;
  5. // TODO: I don't love the name Shortcut, but I can't think of a better one right now. Shortcut is a bit overloaded.
  6. // TODO: It can mean "Application-scoped key binding" or "A key binding that is displayed in a visual way".
  7. // TODO: I tried `BarItem` but that's not great either as it implies it can only be used in `Bar`s.
  8. [Flags]
  9. [GenerateEnumExtensionMethods (FastHasFlags = true)]
  10. public enum ShortcutStyles
  11. {
  12. None = 0,
  13. SeparatorBefore = 8,
  14. SeparatorAfter = 16,
  15. }
  16. /// <summary>
  17. /// Displays a command, help text, and a key binding. When the key is pressed, the command will be invoked. Useful for
  18. /// displaying a command in <see cref="Bar"/> such as a
  19. /// menu, toolbar, or status bar.
  20. /// </summary>
  21. /// <remarks>
  22. /// <para>
  23. /// When the user clicks on the <see cref="Shortcut"/> or presses the key
  24. /// specified by <see cref="Key"/> the <see cref="Command.Accept"/> command is invoked, causing the
  25. /// <see cref="Accept"/> event to be fired
  26. /// </para>
  27. /// <para>
  28. /// If <see cref="KeyBindingScope"/> is <see cref="KeyBindingScope.Application"/>, the <see cref="Command.Accept"/>
  29. /// command
  30. /// be invoked regardless of what View has focus, enabling an application-wide keyboard shortcut.
  31. /// </para>
  32. /// <para>
  33. /// A Shortcut displays the command text on the left side, the help text in the middle, and the key binding on the
  34. /// right side.
  35. /// </para>
  36. /// <para>
  37. /// The command text can be set by setting the <see cref="CommandView"/>'s Text property.
  38. /// </para>
  39. /// <para>
  40. /// The help text can be set by setting the <see cref="HelpText"/> property or by setting <see cref="View.Text"/>.
  41. /// </para>
  42. /// <para>
  43. /// The key text is set by setting the <see cref="Key"/> property.
  44. /// If the <see cref="Key"/> is <see cref="Key.Empty"/>, the <see cref="Key"/> text is not displayed.
  45. /// </para>
  46. /// </remarks>
  47. public class Shortcut : View
  48. {
  49. /// <summary>
  50. /// Creates a new instance of <see cref="Shortcut"/>;
  51. /// </summary>
  52. /// <param name="key"></param>
  53. /// <param name="command"></param>
  54. /// <param name="action"></param>
  55. public Shortcut (Key key, string commandText, Action action, string helpText = null)
  56. {
  57. Id = "_shortcut";
  58. HighlightStyle = HighlightStyle.Pressed;
  59. Highlight += Shortcut_Highlight;
  60. CanFocus = true;
  61. Width = GetWidthDimAuto ();
  62. Height = Dim.Auto (DimAutoStyle.Content, 1);
  63. AddCommand (Command.HotKey, OnAccept);
  64. AddCommand (Command.Accept, OnAccept);
  65. KeyBindings.Add (KeyCode.Space, Command.Accept);
  66. KeyBindings.Add (KeyCode.Enter, Command.Accept);
  67. TitleChanged += Shortcut_TitleChanged; // This needs to be set before CommandView is set
  68. CommandView = new ()
  69. {
  70. Width = Dim.Auto (),
  71. Height = Dim.Auto (),
  72. };
  73. HelpView.Id = "_helpView";
  74. HelpView.CanFocus = false;
  75. HelpView.Text = helpText;
  76. Add (HelpView);
  77. KeyView.Id = "_keyView";
  78. KeyView.CanFocus = false;
  79. Add (KeyView);
  80. // If the user clicks anywhere on the Shortcut, other than the CommandView, invoke the Command
  81. MouseClick += Shortcut_MouseClick;
  82. HelpView.MouseClick += Shortcut_MouseClick;
  83. KeyView.MouseClick += Shortcut_MouseClick;
  84. LayoutStarted += OnLayoutStarted;
  85. Initialized += OnInitialized;
  86. if (key is null)
  87. {
  88. key = Key.Empty;
  89. }
  90. Key = key;
  91. Title = commandText;
  92. Action = action;
  93. return;
  94. void OnInitialized (object sender, EventArgs e)
  95. {
  96. SuperViewRendersLineCanvas = true;
  97. Border.ShowTitle = false;
  98. ShowHide ();
  99. // Force Width to DimAuto to calculate natural width and then set it back
  100. Dim savedDim = Width;
  101. Width = GetWidthDimAuto ();
  102. _minimumDimAutoWidth = Frame.Width;
  103. Width = savedDim;
  104. SetCommandViewDefaultLayout ();
  105. SetHelpViewDefaultLayout ();
  106. SetKeyViewDefaultLayout ();
  107. SetColorScheme ();
  108. }
  109. // Helper to set Width consistently
  110. Dim GetWidthDimAuto ()
  111. {
  112. // TODO: PosAlign.CalculateMinDimension is a hack. Need to figure out a better way of doing this.
  113. return Dim.Auto (DimAutoStyle.Content, minimumContentDim: Dim.Func (() => PosAlign.CalculateMinDimension (0, Subviews, Dimension.Width)), maximumContentDim: Dim.Func (() => PosAlign.CalculateMinDimension (0, Subviews, Dimension.Width)));
  114. }
  115. }
  116. /// <summary>
  117. /// Creates a new instance of <see cref="Shortcut"/>.
  118. /// </summary>
  119. public Shortcut () : this (Gui.Key.Empty, string.Empty, null) { }
  120. /// <summary>
  121. /// Gets or sets the <see cref="Orientation"/> for this <see cref="Shortcut"/>. The default is
  122. /// <see cref="Orientation.Horizontal"/>, which is ideal for status bars and toolbars. If set to <see cref="Orientation.Vertical"/>,
  123. /// the Shortcut will be configured for vertical layout, which is ideal for menus.
  124. /// </summary>
  125. public Orientation Orientation { get; set; } = Orientation.Horizontal;
  126. private AlignmentModes _alignmentModes = AlignmentModes.StartToEnd | AlignmentModes.IgnoreFirstOrLast;
  127. /// <summary>
  128. /// Gets or sets the <see cref="AlignmentModes"/> for this <see cref="Shortcut"/>. The default is <see cref="AlignmentModes.StartToEnd"/>.
  129. /// </summary>
  130. public AlignmentModes AlignmentModes
  131. {
  132. get => _alignmentModes;
  133. set
  134. {
  135. _alignmentModes = value;
  136. SetCommandViewDefaultLayout ();
  137. SetHelpViewDefaultLayout ();
  138. SetKeyViewDefaultLayout ();
  139. }
  140. }
  141. public ShortcutStyles ShortcutStyle { get; set; } = ShortcutStyles.None;
  142. // When one of the subviews is "empty" we don't want to show it. So we
  143. // Use Add/Remove. We need to be careful to add them in the right order
  144. // so Pos.Align works correctly.
  145. private void ShowHide ()
  146. {
  147. RemoveAll ();
  148. if (CommandView.Visible)
  149. {
  150. Add (CommandView);
  151. }
  152. if (HelpView.Visible && !string.IsNullOrEmpty (HelpView.Text))
  153. {
  154. Add (HelpView);
  155. }
  156. if (KeyView.Visible && Key != Key.Empty)
  157. {
  158. Add (KeyView);
  159. }
  160. }
  161. // This is used to calculate the minimum width of the Shortcut when the width is NOT Dim.Auto
  162. private int? _minimumDimAutoWidth;
  163. // When layout starts, we need to adjust the layout of the HelpView and KeyView
  164. private void OnLayoutStarted (object sender, LayoutEventArgs e)
  165. {
  166. if (Width is DimAuto widthAuto)
  167. {
  168. _minimumDimAutoWidth = Frame.Width;
  169. }
  170. else
  171. {
  172. if (string.IsNullOrEmpty (HelpView.Text))
  173. {
  174. return;
  175. }
  176. int currentWidth = Frame.Width;
  177. // If our width is smaller than the natural then reduce width of HelpView.
  178. if (currentWidth < _minimumDimAutoWidth)
  179. {
  180. int delta = _minimumDimAutoWidth.Value - currentWidth;
  181. int maxHelpWidth = int.Max (0, HelpView.Text.GetColumns () + Margin.Thickness.Horizontal - delta);
  182. switch (maxHelpWidth)
  183. {
  184. case 0:
  185. // Hide HelpView
  186. HelpView.Visible = false;
  187. HelpView.X = 0;
  188. break;
  189. case 1:
  190. // Scrunch it by removing margins
  191. HelpView.Margin.Thickness = new (0, 0, 0, 0);
  192. break;
  193. case 2:
  194. // Scrunch just the right margin
  195. var t = GetMarginThickness ();
  196. HelpView.Margin.Thickness = new (t.Right, t.Top, t.Left - 1, t.Bottom);
  197. break;
  198. default:
  199. // Default margin
  200. HelpView.Margin.Thickness = GetMarginThickness ();
  201. break;
  202. }
  203. if (maxHelpWidth > 0)
  204. {
  205. HelpView.X = Pos.Align (Alignment.End, AlignmentModes);
  206. // Leverage Dim.Auto's max:
  207. HelpView.Width = Dim.Auto (DimAutoStyle.Text, maximumContentDim: maxHelpWidth);
  208. HelpView.Visible = true;
  209. }
  210. }
  211. else
  212. {
  213. // Reset to default
  214. //SetCommandViewDefaultLayout();
  215. SetHelpViewDefaultLayout ();
  216. //SetKeyViewDefaultLayout ();
  217. }
  218. }
  219. }
  220. private Thickness GetMarginThickness ()
  221. {
  222. if (Orientation == Orientation.Vertical)
  223. {
  224. return new Thickness (1, 0, 1, 0);
  225. }
  226. else
  227. {
  228. return new Thickness (1, 0, 1, 0);
  229. }
  230. }
  231. private Color? _savedForeColor;
  232. private void Shortcut_Highlight (object sender, HighlightEventArgs e)
  233. {
  234. if (e.HighlightStyle.HasFlag (HighlightStyle.Pressed))
  235. {
  236. if (!_savedForeColor.HasValue)
  237. {
  238. _savedForeColor = base.ColorScheme.Normal.Foreground;
  239. }
  240. var cs = new ColorScheme (base.ColorScheme)
  241. {
  242. Normal = new (ColorScheme.Normal.Foreground.GetHighlightColor (), base.ColorScheme.Normal.Background)
  243. };
  244. base.ColorScheme = cs;
  245. }
  246. if (e.HighlightStyle == HighlightStyle.None && _savedForeColor.HasValue)
  247. {
  248. var cs = new ColorScheme (base.ColorScheme)
  249. {
  250. Normal = new (_savedForeColor.Value, base.ColorScheme.Normal.Background)
  251. };
  252. base.ColorScheme = cs;
  253. }
  254. SuperView?.SetNeedsDisplay ();
  255. e.Cancel = true;
  256. }
  257. private void Shortcut_MouseClick (object sender, MouseEventEventArgs e)
  258. {
  259. // When the Shortcut is clicked, we want to invoke the Command and Set focus
  260. var view = sender as View;
  261. if (view != CommandView)
  262. {
  263. CommandView.InvokeCommand (Command.Accept);
  264. e.Handled = true;
  265. }
  266. if (!e.Handled)
  267. {
  268. // If the subview (likely CommandView) didn't handle the mouse click, invoke the command.
  269. bool? handled = false;
  270. handled = InvokeCommand (Command.Accept);
  271. if (handled.HasValue)
  272. {
  273. e.Handled = handled.Value;
  274. }
  275. }
  276. if (CanFocus)
  277. {
  278. SetFocus ();
  279. }
  280. e.Handled = true;
  281. }
  282. #region Command
  283. private View _commandView = new ();
  284. /// <summary>
  285. /// Gets or sets the View that displays the command text and hotkey.
  286. /// </summary>
  287. /// <remarks>
  288. /// <para>
  289. /// By default, the <see cref="View.Title"/> of the <see cref="CommandView"/> is displayed as the Shortcut's
  290. /// command text.
  291. /// </para>
  292. /// <para>
  293. /// By default, the CommandView is a <see cref="View"/> with <see cref="View.CanFocus"/> set to
  294. /// <see langword="false"/>.
  295. /// </para>
  296. /// <para>
  297. /// Setting the <see cref="CommandView"/> will add it to the <see cref="Shortcut"/> and remove any existing
  298. /// <see cref="CommandView"/>.
  299. /// </para>
  300. /// </remarks>
  301. /// <example>
  302. /// <para>
  303. /// This example illustrates how to add a <see cref="Shortcut"/> to a <see cref="StatusBar"/> that toggles the
  304. /// <see cref="Application.Force16Colors"/> property.
  305. /// </para>
  306. /// <code>
  307. /// var force16ColorsShortcut = new Shortcut
  308. /// {
  309. /// Key = Key.F6,
  310. /// KeyBindingScope = KeyBindingScope.HotKey,
  311. /// CommandView = new CheckBox { Text = "Force 16 Colors" }
  312. /// };
  313. /// var cb = force16ColorsShortcut.CommandView as CheckBox;
  314. /// cb.Checked = Application.Force16Colors;
  315. ///
  316. /// cb.Toggled += (s, e) =>
  317. /// {
  318. /// var cb = s as CheckBox;
  319. /// Application.Force16Colors = cb!.Checked == true;
  320. /// Application.Refresh();
  321. /// };
  322. /// StatusBar.Add(force16ColorsShortcut);
  323. /// </code>
  324. /// </example>
  325. public View CommandView
  326. {
  327. get => _commandView;
  328. set
  329. {
  330. if (value == null)
  331. {
  332. throw new ArgumentNullException ();
  333. }
  334. if (_commandView is { })
  335. {
  336. Remove (_commandView);
  337. _commandView?.Dispose ();
  338. }
  339. _commandView = value;
  340. _commandView.Id = "_commandView";
  341. _commandView.MouseClick += Shortcut_MouseClick;
  342. _commandView.Accept += CommandViewAccept;
  343. _commandView.HotKeyChanged += (s, e) =>
  344. {
  345. if (e.NewKey != Key.Empty)
  346. {
  347. // Add it
  348. AddKeyBindingsForHotKey (e.OldKey, e.NewKey);
  349. }
  350. };
  351. _commandView.HotKeySpecifier = new ('_');
  352. Title = _commandView.Text;
  353. SetCommandViewDefaultLayout ();
  354. SetHelpViewDefaultLayout ();
  355. SetKeyViewDefaultLayout ();
  356. ShowHide ();
  357. UpdateKeyBinding ();
  358. return;
  359. void CommandViewTextChanged (object sender, StateEventArgs<string> e)
  360. {
  361. Title = _commandView.Text;
  362. ShowHide ();
  363. }
  364. void CommandViewAccept (object sender, CancelEventArgs e)
  365. {
  366. // When the CommandView fires its Accept event, we want to act as though the
  367. // Shortcut was clicked.
  368. if (base.OnAccept() == true)
  369. {
  370. e.Cancel = true;
  371. }
  372. //e.Cancel = true;
  373. }
  374. }
  375. }
  376. private void SetCommandViewDefaultLayout ()
  377. {
  378. CommandView.Margin.Thickness = GetMarginThickness ();
  379. CommandView.X = Pos.Align (Alignment.End, AlignmentModes);
  380. CommandView.Y = 0;//Pos.Center ();
  381. }
  382. private void Shortcut_TitleChanged (object sender, StateEventArgs<string> e)
  383. {
  384. // If the Title changes, update the CommandView text.
  385. // This is a helper to make it easier to set the CommandView text.
  386. // CommandView is public and replaceable, but this is a convenience.
  387. _commandView.Text = Title;
  388. }
  389. #endregion Command
  390. #region Help
  391. /// <summary>
  392. /// The subview that displays the help text for the command. Internal for unit testing.
  393. /// </summary>
  394. internal View HelpView { get; } = new ();
  395. private void SetHelpViewDefaultLayout ()
  396. {
  397. HelpView.Margin.Thickness = GetMarginThickness ();
  398. HelpView.X = Pos.Align (Alignment.End, AlignmentModes);
  399. HelpView.Y = 0;//Pos.Center ();
  400. HelpView.Width = Dim.Auto (DimAutoStyle.Text);
  401. HelpView.Height = CommandView?.Visible == true ? Dim.Height (CommandView) : 1;
  402. HelpView.Visible = true;
  403. HelpView.VerticalTextAlignment = Alignment.Center;
  404. }
  405. /// <summary>
  406. /// Gets or sets the help text displayed in the middle of the Shortcut. Identical in function to <see cref="HelpText"/>
  407. /// .
  408. /// </summary>
  409. public override string Text
  410. {
  411. get => HelpView?.Text;
  412. set
  413. {
  414. if (HelpView != null)
  415. {
  416. HelpView.Text = value;
  417. ShowHide ();
  418. }
  419. }
  420. }
  421. /// <summary>
  422. /// Gets or sets the help text displayed in the middle of the Shortcut.
  423. /// </summary>
  424. public string HelpText
  425. {
  426. get => HelpView?.Text;
  427. set
  428. {
  429. if (HelpView != null)
  430. {
  431. HelpView.Text = value;
  432. ShowHide ();
  433. }
  434. }
  435. }
  436. #endregion Help
  437. #region Key
  438. private Key _key = Key.Empty;
  439. /// <summary>
  440. /// Gets or sets the <see cref="Key"/> that will be bound to the <see cref="Command.Accept"/> command.
  441. /// </summary>
  442. public Key Key
  443. {
  444. get => _key;
  445. set
  446. {
  447. if (value == null)
  448. {
  449. throw new ArgumentNullException ();
  450. }
  451. _key = value;
  452. UpdateKeyBinding ();
  453. KeyView.Text = Key == Key.Empty ? string.Empty : $"{Key}";
  454. ShowHide ();
  455. }
  456. }
  457. private KeyBindingScope _keyBindingScope = KeyBindingScope.HotKey;
  458. /// <summary>
  459. /// Gets or sets the scope for the key binding for how <see cref="Key"/> is bound to <see cref="Command"/>.
  460. /// </summary>
  461. public KeyBindingScope KeyBindingScope
  462. {
  463. get => _keyBindingScope;
  464. set
  465. {
  466. _keyBindingScope = value;
  467. UpdateKeyBinding ();
  468. }
  469. }
  470. // TODO: Make internal once Bar is done
  471. /// <summary>
  472. /// Gets the subview that displays the key. Internal for unit testing.
  473. /// </summary>
  474. public View KeyView { get; } = new ();
  475. private int _minimumKeyViewSize;
  476. /// <summary>
  477. /// </summary>
  478. public int MinimumKeyViewSize
  479. {
  480. get => _minimumKeyViewSize;
  481. set
  482. {
  483. if (value == _minimumKeyViewSize)
  484. {
  485. //return;
  486. }
  487. _minimumKeyViewSize = value;
  488. SetKeyViewDefaultLayout ();
  489. CommandView.SetNeedsLayout ();
  490. HelpView.SetNeedsLayout ();
  491. KeyView.SetNeedsLayout ();
  492. SetSubViewNeedsDisplay ();
  493. }
  494. }
  495. private int GetMinimumKeyViewSize () { return MinimumKeyViewSize; }
  496. private void SetKeyViewDefaultLayout ()
  497. {
  498. KeyView.Margin.Thickness = GetMarginThickness ();
  499. KeyView.X = Pos.Align (Alignment.End, AlignmentModes);
  500. KeyView.Y = 0;//Pos.Center ();
  501. KeyView.Width = Dim.Auto (DimAutoStyle.Text, Dim.Func (GetMinimumKeyViewSize));
  502. KeyView.Height = CommandView?.Visible == true ? Dim.Height (CommandView) : 1;
  503. KeyView.Visible = true;
  504. // Right align the text in the keyview
  505. KeyView.TextAlignment = Alignment.End;
  506. KeyView.VerticalTextAlignment = Alignment.Center;
  507. KeyView.KeyBindings.Clear ();
  508. }
  509. private void UpdateKeyBinding ()
  510. {
  511. if (Key != null)
  512. {
  513. KeyBindings.Remove (Key);
  514. KeyBindings.Add (Key, KeyBindingScope, Command.Accept);
  515. }
  516. }
  517. #endregion Key
  518. #region Accept Handling
  519. /// <summary>
  520. /// Called when the <see cref="Command.Accept"/> command is received. This
  521. /// occurs if the user clicks on the Bar with the mouse or presses the key bound to
  522. /// Command.Accept (Space by default).
  523. /// </summary>
  524. protected new bool? OnAccept ()
  525. {
  526. var handled = true;
  527. switch (KeyBindingScope)
  528. {
  529. case KeyBindingScope.Application:
  530. handled = false;
  531. break;
  532. case KeyBindingScope.Focused:
  533. // TODO: Figure this out
  534. handled = false;
  535. break;
  536. case KeyBindingScope.HotKey:
  537. handled = _commandView.InvokeCommand (Command.HotKey) == true;
  538. handled = false;
  539. break;
  540. }
  541. if (handled == false)
  542. {
  543. if (base.OnAccept () is false)
  544. {
  545. Action?.Invoke ();
  546. }
  547. }
  548. return false;
  549. }
  550. /// <summary>
  551. /// Gets or sets the action to be invoked when the shortcut key is pressed or the shortcut is clicked on with the mouse.
  552. /// </summary>
  553. /// <remarks>
  554. /// Note, the <see cref="Accept"/> event is fired first, and if cancelled, <see cref="Action"/> will not be invoked.
  555. /// </remarks>
  556. [CanBeNull]
  557. public Action Action { get; set; }
  558. #endregion Accept Handling
  559. #region Focus
  560. /// <inheritdoc/>
  561. public override ColorScheme ColorScheme
  562. {
  563. get => base.ColorScheme;
  564. set
  565. {
  566. base.ColorScheme = value;
  567. SetColorScheme ();
  568. }
  569. }
  570. public void SetColorScheme ()
  571. {
  572. // Border should match superview.
  573. Border.ColorScheme = SuperView?.ColorScheme;
  574. if (HasFocus)
  575. {
  576. // When we have focus, we invert the colors
  577. base.ColorScheme = new (base.ColorScheme)
  578. {
  579. Normal = base.ColorScheme.Focus,
  580. HotNormal = base.ColorScheme.HotFocus,
  581. HotFocus = base.ColorScheme.HotNormal,
  582. Focus = base.ColorScheme.Normal
  583. };
  584. }
  585. else
  586. {
  587. base.ColorScheme = SuperView?.ColorScheme;
  588. }
  589. // Set KeyView's colors to show "hot"
  590. if (IsInitialized && base.ColorScheme is {})
  591. {
  592. var cs = new ColorScheme (base.ColorScheme)
  593. {
  594. Normal = base.ColorScheme.HotNormal,
  595. HotNormal = base.ColorScheme.Normal
  596. };
  597. KeyView.ColorScheme = cs;
  598. }
  599. }
  600. /// <inheritdoc/>
  601. public override bool OnEnter (View view)
  602. {
  603. SetColorScheme ();
  604. return base.OnEnter (view);
  605. }
  606. /// <inheritdoc/>
  607. public override bool OnLeave (View view)
  608. {
  609. SetColorScheme ();
  610. return base.OnLeave (view);
  611. }
  612. #endregion Focus
  613. /// <inheritdoc />
  614. protected override void Dispose (bool disposing)
  615. {
  616. if (disposing)
  617. {
  618. if (CommandView?.IsAdded == false)
  619. {
  620. CommandView.Dispose ();
  621. }
  622. if (HelpView?.IsAdded == false)
  623. {
  624. HelpView.Dispose ();
  625. }
  626. if (KeyView?.IsAdded == false)
  627. {
  628. KeyView.Dispose ();
  629. }
  630. }
  631. base.Dispose (disposing);
  632. }
  633. }