Shortcut.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767
  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. var args = new HandledEventArgs ();
  365. Accept?.Invoke (this, args);
  366. if (args.Handled)
  367. {
  368. e.Cancel = args.Handled;
  369. }
  370. //e.Cancel = true;
  371. }
  372. }
  373. }
  374. private void SetCommandViewDefaultLayout ()
  375. {
  376. CommandView.Margin.Thickness = GetMarginThickness ();
  377. CommandView.X = Pos.Align (Alignment.End, AlignmentModes);
  378. CommandView.Y = 0; //Pos.Center (),
  379. }
  380. private void Shortcut_TitleChanged (object sender, StateEventArgs<string> e)
  381. {
  382. // If the Title changes, update the CommandView text.
  383. // This is a helper to make it easier to set the CommandView text.
  384. // CommandView is public and replaceable, but this is a convenience.
  385. _commandView.Text = Title;
  386. }
  387. #endregion Command
  388. #region Help
  389. /// <summary>
  390. /// The subview that displays the help text for the command. Internal for unit testing.
  391. /// </summary>
  392. internal View HelpView { get; } = new ();
  393. private void SetHelpViewDefaultLayout ()
  394. {
  395. HelpView.Margin.Thickness = GetMarginThickness ();
  396. HelpView.X = Pos.Align (Alignment.End, AlignmentModes);
  397. HelpView.Y = 0; //Pos.Center (),
  398. HelpView.Width = Dim.Auto (DimAutoStyle.Text);
  399. HelpView.Height = CommandView?.IsAdded == true ? Dim.Height (CommandView) : 1;
  400. HelpView.Visible = true;
  401. HelpView.VerticalTextAlignment = Alignment.Center;
  402. }
  403. /// <summary>
  404. /// Gets or sets the help text displayed in the middle of the Shortcut. Identical in function to <see cref="HelpText"/>
  405. /// .
  406. /// </summary>
  407. public override string Text
  408. {
  409. get => HelpView?.Text;
  410. set
  411. {
  412. if (HelpView != null)
  413. {
  414. HelpView.Text = value;
  415. ShowHide ();
  416. }
  417. }
  418. }
  419. /// <summary>
  420. /// Gets or sets the help text displayed in the middle of the Shortcut.
  421. /// </summary>
  422. public string HelpText
  423. {
  424. get => HelpView?.Text;
  425. set
  426. {
  427. if (HelpView != null)
  428. {
  429. HelpView.Text = value;
  430. ShowHide ();
  431. }
  432. }
  433. }
  434. #endregion Help
  435. #region Key
  436. private Key _key = Key.Empty;
  437. /// <summary>
  438. /// Gets or sets the <see cref="Key"/> that will be bound to the <see cref="Command.Accept"/> command.
  439. /// </summary>
  440. public Key Key
  441. {
  442. get => _key;
  443. set
  444. {
  445. if (value == null)
  446. {
  447. throw new ArgumentNullException ();
  448. }
  449. _key = value;
  450. UpdateKeyBinding ();
  451. KeyView.Text = Key == Key.Empty ? string.Empty : $"{Key}";
  452. ShowHide ();
  453. }
  454. }
  455. private KeyBindingScope _keyBindingScope = KeyBindingScope.HotKey;
  456. /// <summary>
  457. /// Gets or sets the scope for the key binding for how <see cref="Key"/> is bound to <see cref="Command"/>.
  458. /// </summary>
  459. public KeyBindingScope KeyBindingScope
  460. {
  461. get => _keyBindingScope;
  462. set
  463. {
  464. _keyBindingScope = value;
  465. UpdateKeyBinding ();
  466. }
  467. }
  468. // TODO: Make internal once Bar is done
  469. /// <summary>
  470. /// Gets the subview that displays the key. Internal for unit testing.
  471. /// </summary>
  472. public View KeyView { get; } = new ();
  473. private int _minimumKeyViewSize;
  474. /// <summary>
  475. /// </summary>
  476. public int MinimumKeyViewSize
  477. {
  478. get => _minimumKeyViewSize;
  479. set
  480. {
  481. if (value == _minimumKeyViewSize)
  482. {
  483. //return;
  484. }
  485. _minimumKeyViewSize = value;
  486. SetKeyViewDefaultLayout ();
  487. CommandView.SetNeedsLayout ();
  488. HelpView.SetNeedsLayout ();
  489. KeyView.SetNeedsLayout ();
  490. SetSubViewNeedsDisplay ();
  491. }
  492. }
  493. private int GetMinimumKeyViewSize () { return MinimumKeyViewSize; }
  494. private void SetKeyViewDefaultLayout ()
  495. {
  496. KeyView.Margin.Thickness = GetMarginThickness ();
  497. KeyView.X = Pos.Align (Alignment.End, AlignmentModes);
  498. //KeyView.Y = Pos.Center ();
  499. KeyView.Width = Dim.Auto (DimAutoStyle.Text, Dim.Func (GetMinimumKeyViewSize));
  500. KeyView.Height = CommandView?.IsAdded == true ? Dim.Height (CommandView) : 1;
  501. KeyView.Visible = true;
  502. // Right align the text in the keyview
  503. KeyView.TextAlignment = Alignment.End;
  504. KeyView.VerticalTextAlignment = Alignment.Center;
  505. KeyView.KeyBindings.Clear ();
  506. }
  507. private void UpdateKeyBinding ()
  508. {
  509. if (Key != null)
  510. {
  511. KeyBindings.Remove (Key);
  512. KeyBindings.Add (Key, KeyBindingScope, Command.Accept);
  513. }
  514. }
  515. #endregion Key
  516. #region Accept Handling
  517. /// <summary>
  518. /// The event fired when the <see cref="Command.Accept"/> command is received. This
  519. /// occurs if the user clicks on the Shortcut or presses <see cref="Key"/>.
  520. /// </summary>
  521. public new event EventHandler<HandledEventArgs> Accept;
  522. /// <summary>
  523. /// Called when the <see cref="Command.Accept"/> command is received. This
  524. /// occurs if the user clicks on the Bar with the mouse or presses the key bound to
  525. /// Command.Accept (Space by default).
  526. /// </summary>
  527. protected new bool? OnAccept ()
  528. {
  529. var handled = true;
  530. switch (KeyBindingScope)
  531. {
  532. case KeyBindingScope.Application:
  533. handled = false;
  534. break;
  535. case KeyBindingScope.Focused:
  536. // TODO: Figure this out
  537. handled = false;
  538. break;
  539. case KeyBindingScope.HotKey:
  540. handled = _commandView.InvokeCommand (Command.HotKey) == true;
  541. handled = false;
  542. break;
  543. }
  544. if (handled == false)
  545. {
  546. var args = new HandledEventArgs ();
  547. Accept?.Invoke (this, args);
  548. if (args.Handled is false)
  549. {
  550. Action?.Invoke ();
  551. }
  552. args.Handled = true;
  553. }
  554. return true;
  555. }
  556. /// <summary>
  557. /// Gets or sets the action to be invoked when the shortcut key is pressed or the shortcut is clicked on with the mouse.
  558. /// </summary>
  559. /// <remarks>
  560. /// Note, the <see cref="Accept"/> event is fired first, and if cancelled, <see cref="Action"/> will not be invoked.
  561. /// </remarks>
  562. [CanBeNull]
  563. public Action Action { get; set; }
  564. #endregion Accept Handling
  565. #region Focus
  566. /// <inheritdoc/>
  567. public override ColorScheme ColorScheme
  568. {
  569. get => base.ColorScheme;
  570. set
  571. {
  572. base.ColorScheme = value;
  573. SetColorScheme ();
  574. }
  575. }
  576. public void SetColorScheme ()
  577. {
  578. // Border should match superview.
  579. Border.ColorScheme = SuperView?.ColorScheme;
  580. if (HasFocus)
  581. {
  582. // When we have focus, we invert the colors
  583. base.ColorScheme = new (base.ColorScheme)
  584. {
  585. Normal = base.ColorScheme.Focus,
  586. HotNormal = base.ColorScheme.HotFocus,
  587. HotFocus = base.ColorScheme.HotNormal,
  588. Focus = base.ColorScheme.Normal
  589. };
  590. }
  591. else
  592. {
  593. base.ColorScheme = SuperView?.ColorScheme;
  594. }
  595. // Set KeyView's colors to show "hot"
  596. if (IsInitialized)
  597. {
  598. var cs = new ColorScheme (base.ColorScheme)
  599. {
  600. Normal = base.ColorScheme.HotNormal,
  601. HotNormal = base.ColorScheme.Normal
  602. };
  603. KeyView.ColorScheme = cs;
  604. }
  605. }
  606. /// <inheritdoc/>
  607. public override bool OnEnter (View view)
  608. {
  609. SetColorScheme ();
  610. return base.OnEnter (view);
  611. }
  612. /// <inheritdoc/>
  613. public override bool OnLeave (View view)
  614. {
  615. SetColorScheme ();
  616. return base.OnLeave (view);
  617. }
  618. #endregion Focus
  619. /// <inheritdoc />
  620. protected override void Dispose (bool disposing)
  621. {
  622. if (disposing)
  623. {
  624. if (CommandView?.IsAdded == false)
  625. {
  626. CommandView.Dispose ();
  627. }
  628. if (HelpView?.IsAdded == false)
  629. {
  630. HelpView.Dispose ();
  631. }
  632. if (KeyView?.IsAdded == false)
  633. {
  634. KeyView.Dispose ();
  635. }
  636. }
  637. base.Dispose (disposing);
  638. }
  639. }