Shortcut.cs 23 KB

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