Shortcut.cs 23 KB

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