Shortcut.cs 22 KB

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