View.Navigation.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813
  1. namespace Terminal.Gui;
  2. public partial class View // Focus and cross-view navigation management (TabStop, TabIndex, etc...)
  3. {
  4. /// <summary>Returns a value indicating if this View is currently on Top (Active)</summary>
  5. public bool IsCurrentTop => Application.Current == this;
  6. // BUGBUG: This API is poorly defined and implemented. It deeply intertwines the view hierarchy with the tab order.
  7. /// <summary>Exposed as `internal` for unit tests. Indicates focus navigation direction.</summary>
  8. internal enum NavigationDirection
  9. {
  10. /// <summary>Navigate forward.</summary>
  11. Forward,
  12. /// <summary>Navigate backwards.</summary>
  13. Backward
  14. }
  15. /// <summary>Invoked when this view is gaining focus (entering).</summary>
  16. /// <param name="leavingView">The view that is leaving focus.</param>
  17. /// <returns> <see langword="true"/>, if the event was handled, <see langword="false"/> otherwise.</returns>
  18. /// <remarks>
  19. /// <para>
  20. /// Overrides must call the base class method to ensure that the <see cref="Enter"/> event is raised. If the event
  21. /// is handled, the method should return <see langword="true"/>.
  22. /// </para>
  23. /// </remarks>
  24. public virtual bool OnEnter (View leavingView)
  25. {
  26. var args = new FocusEventArgs (leavingView, this);
  27. Enter?.Invoke (this, args);
  28. if (args.Handled)
  29. {
  30. return true;
  31. }
  32. return false;
  33. }
  34. /// <summary>Invoked when this view is losing focus (leaving).</summary>
  35. /// <param name="enteringView">The view that is entering focus.</param>
  36. /// <returns> <see langword="true"/>, if the event was handled, <see langword="false"/> otherwise.</returns>
  37. /// <remarks>
  38. /// <para>
  39. /// Overrides must call the base class method to ensure that the <see cref="Leave"/> event is raised. If the event
  40. /// is handled, the method should return <see langword="true"/>.
  41. /// </para>
  42. /// </remarks>
  43. public virtual bool OnLeave (View enteringView)
  44. {
  45. var args = new FocusEventArgs (this, enteringView);
  46. Leave?.Invoke (this, args);
  47. if (args.Handled)
  48. {
  49. return true;
  50. }
  51. return false;
  52. }
  53. /// <summary>Raised when the view is gaining (entering) focus. Can be cancelled.</summary>
  54. /// <remarks>
  55. /// Raised by the <see cref="OnEnter"/> virtual method.
  56. /// </remarks>
  57. public event EventHandler<FocusEventArgs> Enter;
  58. /// <summary>Raised when the view is losing (leaving) focus. Can be cancelled.</summary>
  59. /// <remarks>
  60. /// Raised by the <see cref="OnLeave"/> virtual method.
  61. /// </remarks>
  62. public event EventHandler<FocusEventArgs> Leave;
  63. private NavigationDirection _focusDirection;
  64. /// <summary>
  65. /// Gets or sets the focus direction for this view and all subviews.
  66. /// Setting this property will set the focus direction for all views up the SuperView hierarchy.
  67. /// </summary>
  68. internal NavigationDirection FocusDirection
  69. {
  70. get => SuperView?.FocusDirection ?? _focusDirection;
  71. set
  72. {
  73. if (SuperView is { })
  74. {
  75. SuperView.FocusDirection = value;
  76. }
  77. else
  78. {
  79. _focusDirection = value;
  80. }
  81. }
  82. }
  83. private bool _hasFocus;
  84. /// <summary>
  85. /// Gets or sets whether this view has focus.
  86. /// </summary>
  87. /// <remarks>
  88. /// <para>
  89. /// Causes the <see cref="OnEnter"/> and <see cref="OnLeave"/> virtual methods (and <see cref="Enter"/> and
  90. /// <see cref="Leave"/> events to be raised) when the value changes.
  91. /// </para>
  92. /// <para>
  93. /// Setting this property to <see langword="false"/> will recursively set <see cref="HasFocus"/> to
  94. /// <see langword="false"/>
  95. /// for any focused subviews.
  96. /// </para>
  97. /// </remarks>
  98. public bool HasFocus
  99. {
  100. // Force the specified view to have focus
  101. set => SetHasFocus (value, this, true);
  102. get => _hasFocus;
  103. }
  104. /// <summary>
  105. /// Internal API that sets <see cref="HasFocus"/>. This method is called by <c>HasFocus_set</c> and other methods that
  106. /// need to set or remove focus from a view.
  107. /// </summary>
  108. /// <param name="newHasFocus">The new setting for <see cref="HasFocus"/>.</param>
  109. /// <param name="view">The view that will be gaining or losing focus.</param>
  110. /// <param name="force">
  111. /// <see langword="true"/> to force Enter/Leave on <paramref name="view"/> regardless of whether it
  112. /// already HasFocus or not.
  113. /// </param>
  114. /// <remarks>
  115. /// If <paramref name="newHasFocus"/> is <see langword="false"/> and there is a focused subview (<see cref="Focused"/>
  116. /// is not <see langword="null"/>),
  117. /// this method will recursively remove focus from any focused subviews of <see cref="Focused"/>.
  118. /// </remarks>
  119. private void SetHasFocus (bool newHasFocus, View view, bool force = false)
  120. {
  121. if (HasFocus != newHasFocus || force)
  122. {
  123. _hasFocus = newHasFocus;
  124. if (newHasFocus)
  125. {
  126. OnEnter (view);
  127. }
  128. else
  129. {
  130. OnLeave (view);
  131. }
  132. SetNeedsDisplay ();
  133. }
  134. // Remove focus down the chain of subviews if focus is removed
  135. if (!newHasFocus && Focused is { })
  136. {
  137. View f = Focused;
  138. f.OnLeave (view);
  139. f.SetHasFocus (false, view);
  140. Focused = null;
  141. }
  142. }
  143. /// <summary>Raised when <see cref="CanFocus"/> has been changed.</summary>
  144. /// <remarks>
  145. /// Raised by the <see cref="OnCanFocusChanged"/> virtual method.
  146. /// </remarks>
  147. public event EventHandler CanFocusChanged;
  148. /// <summary>Invoked when the <see cref="CanFocus"/> property from a view is changed.</summary>
  149. /// <remarks>
  150. /// Raises the <see cref="CanFocusChanged"/> event.
  151. /// </remarks>
  152. public virtual void OnCanFocusChanged () { CanFocusChanged?.Invoke (this, EventArgs.Empty); }
  153. private bool _oldCanFocus;
  154. private bool _canFocus;
  155. /// <summary>Gets or sets a value indicating whether this <see cref="View"/> can be focused.</summary>
  156. /// <remarks>
  157. /// <para>
  158. /// <see cref="SuperView"/> must also have <see cref="CanFocus"/> set to <see langword="true"/>.
  159. /// </para>
  160. /// </remarks>
  161. public bool CanFocus
  162. {
  163. get => _canFocus;
  164. set
  165. {
  166. if (!_addingView && IsInitialized && SuperView?.CanFocus == false && value)
  167. {
  168. throw new InvalidOperationException ("Cannot set CanFocus to true if the SuperView CanFocus is false!");
  169. }
  170. if (_canFocus == value)
  171. {
  172. return;
  173. }
  174. _canFocus = value;
  175. switch (_canFocus)
  176. {
  177. case false when _tabIndex > -1:
  178. TabIndex = -1;
  179. break;
  180. case true when SuperView?.CanFocus == false && _addingView:
  181. SuperView.CanFocus = true;
  182. break;
  183. }
  184. if (_canFocus && _tabIndex == -1)
  185. {
  186. TabIndex = SuperView is { } ? SuperView._tabIndexes.IndexOf (this) : -1;
  187. }
  188. TabStop = _canFocus;
  189. if (!_canFocus && SuperView?.Focused == this)
  190. {
  191. SuperView.Focused = null;
  192. }
  193. if (!_canFocus && HasFocus)
  194. {
  195. SetHasFocus (false, this);
  196. SuperView?.EnsureFocus ();
  197. if (SuperView is { Focused: null })
  198. {
  199. SuperView.FocusNext ();
  200. if (SuperView.Focused is null && Application.Current is { })
  201. {
  202. Application.Current.FocusNext ();
  203. }
  204. ApplicationOverlapped.BringOverlappedTopToFront ();
  205. }
  206. }
  207. if (_subviews is { } && IsInitialized)
  208. {
  209. foreach (View view in _subviews)
  210. {
  211. if (view.CanFocus != value)
  212. {
  213. if (!value)
  214. {
  215. view._oldCanFocus = view.CanFocus;
  216. view._oldTabIndex = view._tabIndex;
  217. view.CanFocus = false;
  218. view._tabIndex = -1;
  219. }
  220. else
  221. {
  222. if (_addingView)
  223. {
  224. view._addingView = true;
  225. }
  226. view.CanFocus = view._oldCanFocus;
  227. view._tabIndex = view._oldTabIndex;
  228. view._addingView = false;
  229. }
  230. }
  231. }
  232. if (this is Toplevel && Application.Current.Focused != this)
  233. {
  234. ApplicationOverlapped.BringOverlappedTopToFront ();
  235. }
  236. }
  237. OnCanFocusChanged ();
  238. SetNeedsDisplay ();
  239. }
  240. }
  241. /// <summary>Returns the currently focused Subview inside this view, or <see langword="null"/> if nothing is focused.</summary>
  242. /// <value>The currently focused Subview.</value>
  243. public View Focused { get; private set; }
  244. /// <summary>
  245. /// Returns the most focused Subview in the chain of subviews (the leaf view that has the focus), or
  246. /// <see langword="null"/> if nothing is focused.
  247. /// </summary>
  248. /// <value>The most focused Subview.</value>
  249. public View MostFocused
  250. {
  251. get
  252. {
  253. if (Focused is null)
  254. {
  255. return null;
  256. }
  257. View most = Focused.MostFocused;
  258. if (most is { })
  259. {
  260. return most;
  261. }
  262. return Focused;
  263. }
  264. }
  265. /// <summary>Causes subview specified by <paramref name="view"/> to enter focus.</summary>
  266. /// <param name="view">View.</param>
  267. private void SetFocus (View view)
  268. {
  269. if (view is null)
  270. {
  271. return;
  272. }
  273. //Console.WriteLine ($"Request to focus {view}");
  274. if (!view.CanFocus || !view.Visible || !view.Enabled)
  275. {
  276. return;
  277. }
  278. if (Focused?._hasFocus == true && Focused == view)
  279. {
  280. return;
  281. }
  282. if ((Focused?._hasFocus == true && Focused?.SuperView == view) || view == this)
  283. {
  284. if (!view._hasFocus)
  285. {
  286. view._hasFocus = true;
  287. }
  288. return;
  289. }
  290. // Make sure that this view is a subview
  291. View c;
  292. for (c = view._superView; c != null; c = c._superView)
  293. {
  294. if (c == this)
  295. {
  296. break;
  297. }
  298. }
  299. if (c is null)
  300. {
  301. throw new ArgumentException ("the specified view is not part of the hierarchy of this view");
  302. }
  303. if (Focused is { })
  304. {
  305. Focused.SetHasFocus (false, view);
  306. }
  307. View f = Focused;
  308. Focused = view;
  309. Focused.SetHasFocus (true, f);
  310. Focused.EnsureFocus ();
  311. // Send focus upwards
  312. if (SuperView is { })
  313. {
  314. SuperView.SetFocus (this);
  315. }
  316. else
  317. {
  318. SetFocus (this);
  319. }
  320. }
  321. /// <summary>Causes this view to be focused and entire Superview hierarchy to have the focused order updated.</summary>
  322. public void SetFocus ()
  323. {
  324. if (!CanBeVisible (this) || !Enabled)
  325. {
  326. if (HasFocus)
  327. {
  328. SetHasFocus (false, this);
  329. }
  330. return;
  331. }
  332. if (SuperView is { })
  333. {
  334. SuperView.SetFocus (this);
  335. }
  336. else
  337. {
  338. SetFocus (this);
  339. }
  340. }
  341. /// <summary>
  342. /// If there is no focused subview, calls <see cref="FocusFirst"/> or <see cref="FocusLast"/> based on
  343. /// <see cref="FocusDirection"/>.
  344. /// does nothing.
  345. /// </summary>
  346. public void EnsureFocus ()
  347. {
  348. if (Focused is null && _subviews?.Count > 0)
  349. {
  350. if (FocusDirection == NavigationDirection.Forward)
  351. {
  352. FocusFirst ();
  353. }
  354. else
  355. {
  356. FocusLast ();
  357. }
  358. }
  359. }
  360. /// <summary>
  361. /// Focuses the last focusable view in <see cref="View.TabIndexes"/> if one exists. If there are no views in
  362. /// <see cref="View.TabIndexes"/> then the focus is set to the view itself.
  363. /// </summary>
  364. public void FocusFirst (bool overlapped = false)
  365. {
  366. if (!CanBeVisible (this))
  367. {
  368. return;
  369. }
  370. if (_tabIndexes is null)
  371. {
  372. SuperView?.SetFocus (this);
  373. return;
  374. }
  375. foreach (View view in _tabIndexes.Where (v => !overlapped || v.Arrangement.HasFlag (ViewArrangement.Overlapped)))
  376. {
  377. if (view.CanFocus && view._tabStop && view.Visible && view.Enabled)
  378. {
  379. SetFocus (view);
  380. return;
  381. }
  382. }
  383. }
  384. /// <summary>
  385. /// Focuses the last focusable view in <see cref="View.TabIndexes"/> if one exists. If there are no views in
  386. /// <see cref="View.TabIndexes"/> then the focus is set to the view itself.
  387. /// </summary>
  388. public void FocusLast (bool overlapped = false)
  389. {
  390. if (!CanBeVisible (this))
  391. {
  392. return;
  393. }
  394. if (_tabIndexes is null)
  395. {
  396. SuperView?.SetFocus (this);
  397. return;
  398. }
  399. foreach (View view in _tabIndexes.Where (v => !overlapped || v.Arrangement.HasFlag (ViewArrangement.Overlapped)).Reverse ())
  400. {
  401. if (view.CanFocus && view._tabStop && view.Visible && view.Enabled)
  402. {
  403. SetFocus (view);
  404. return;
  405. }
  406. }
  407. }
  408. /// <summary>
  409. /// Focuses the previous view in <see cref="View.TabIndexes"/>. If there is no previous view, the focus is set to the
  410. /// view itself.
  411. /// </summary>
  412. /// <returns><see langword="true"/> if previous was focused, <see langword="false"/> otherwise.</returns>
  413. public bool FocusPrev ()
  414. {
  415. if (!CanBeVisible (this))
  416. {
  417. return false;
  418. }
  419. FocusDirection = NavigationDirection.Backward;
  420. if (TabIndexes is null || TabIndexes.Count == 0)
  421. {
  422. return false;
  423. }
  424. if (Focused is null)
  425. {
  426. FocusLast ();
  427. return Focused != null;
  428. }
  429. int focusedIdx = -1;
  430. for (int i = TabIndexes.Count; i > 0;)
  431. {
  432. i--;
  433. View w = TabIndexes [i];
  434. if (w.HasFocus)
  435. {
  436. if (w.FocusPrev ())
  437. {
  438. return true;
  439. }
  440. focusedIdx = i;
  441. continue;
  442. }
  443. if (w.CanFocus && focusedIdx != -1 && w._tabStop && w.Visible && w.Enabled)
  444. {
  445. Focused.SetHasFocus (false, w);
  446. // If the focused view is overlapped don't focus on the next if it's not overlapped.
  447. if (Focused.Arrangement.HasFlag (ViewArrangement.Overlapped) && !w.Arrangement.HasFlag (ViewArrangement.Overlapped))
  448. {
  449. FocusLast (true);
  450. return true;
  451. }
  452. // If the focused view is not overlapped and the next is, skip it
  453. if (!Focused.Arrangement.HasFlag (ViewArrangement.Overlapped) && w.Arrangement.HasFlag (ViewArrangement.Overlapped))
  454. {
  455. continue;
  456. }
  457. if (w.CanFocus && w._tabStop && w.Visible && w.Enabled)
  458. {
  459. w.FocusLast ();
  460. }
  461. SetFocus (w);
  462. return true;
  463. }
  464. }
  465. // There's no prev view in tab indexes.
  466. if (Focused is { })
  467. {
  468. // Leave Focused
  469. Focused.SetHasFocus (false, this);
  470. if (Focused.Arrangement.HasFlag (ViewArrangement.Overlapped))
  471. {
  472. FocusLast (true);
  473. return true;
  474. }
  475. // Signal to caller no next view was found
  476. Focused = null;
  477. }
  478. return false;
  479. }
  480. /// <summary>
  481. /// Focuses the next view in <see cref="View.TabIndexes"/>. If there is no next view, the focus is set to the view
  482. /// itself.
  483. /// </summary>
  484. /// <returns><see langword="true"/> if next was focused, <see langword="false"/> otherwise.</returns>
  485. public bool FocusNext ()
  486. {
  487. if (!CanBeVisible (this))
  488. {
  489. return false;
  490. }
  491. FocusDirection = NavigationDirection.Forward;
  492. if (TabIndexes is null || TabIndexes.Count == 0)
  493. {
  494. return false;
  495. }
  496. if (Focused is null)
  497. {
  498. FocusFirst ();
  499. return Focused != null;
  500. }
  501. int focusedIdx = -1;
  502. for (var i = 0; i < TabIndexes.Count; i++)
  503. {
  504. View w = TabIndexes [i];
  505. if (w.HasFocus)
  506. {
  507. if (w.FocusNext ())
  508. {
  509. return true;
  510. }
  511. focusedIdx = i;
  512. continue;
  513. }
  514. if (w.CanFocus && focusedIdx != -1 && w._tabStop && w.Visible && w.Enabled)
  515. {
  516. Focused.SetHasFocus (false, w);
  517. //// If the focused view is overlapped don't focus on the next if it's not overlapped.
  518. //if (Focused.Arrangement.HasFlag (ViewArrangement.Overlapped)/* && !w.Arrangement.HasFlag (ViewArrangement.Overlapped)*/)
  519. //{
  520. // return false;
  521. //}
  522. //// If the focused view is not overlapped and the next is, skip it
  523. //if (!Focused.Arrangement.HasFlag (ViewArrangement.Overlapped) && w.Arrangement.HasFlag (ViewArrangement.Overlapped))
  524. //{
  525. // continue;
  526. //}
  527. if (w.CanFocus && w._tabStop && w.Visible && w.Enabled)
  528. {
  529. w.FocusFirst ();
  530. }
  531. SetFocus (w);
  532. return true;
  533. }
  534. }
  535. // There's no next view in tab indexes.
  536. if (Focused is { })
  537. {
  538. // Leave Focused
  539. Focused.SetHasFocus (false, this);
  540. //if (Focused.Arrangement.HasFlag (ViewArrangement.Overlapped))
  541. //{
  542. // FocusFirst (true);
  543. // return true;
  544. //}
  545. // Signal to caller no next view was found
  546. Focused = null;
  547. }
  548. return false;
  549. }
  550. private View GetMostFocused (View view)
  551. {
  552. if (view is null)
  553. {
  554. return null;
  555. }
  556. return view.Focused is { } ? GetMostFocused (view.Focused) : view;
  557. }
  558. #region Tab/Focus Handling
  559. private List<View> _tabIndexes;
  560. // TODO: This should be a get-only property?
  561. // BUGBUG: This returns an AsReadOnly list, but isn't declared as such.
  562. /// <summary>Gets a list of the subviews that are a <see cref="TabStop"/>.</summary>
  563. /// <value>The tabIndexes.</value>
  564. public IList<View> TabIndexes => _tabIndexes?.AsReadOnly () ?? _empty;
  565. // TODO: Change this to int? and use null to indicate the view is not in the tab order.
  566. private int _tabIndex = -1;
  567. private int _oldTabIndex;
  568. /// <summary>
  569. /// Indicates the index of the current <see cref="View"/> from the <see cref="TabIndexes"/> list. See also:
  570. /// <seealso cref="TabStop"/>.
  571. /// </summary>
  572. /// <remarks>
  573. /// <para>
  574. /// If the value is -1, the view is not part of the tab order.
  575. /// </para>
  576. /// <para>
  577. /// On set, if <see cref="CanFocus"/> is <see langword="false"/>, <see cref="TabIndex"/> will be set to -1.
  578. /// </para>
  579. /// <para>
  580. /// On set, if <see cref="SuperView"/> is <see langword="null"/> or has not TabStops, <see cref="TabIndex"/> will
  581. /// be set to 0.
  582. /// </para>
  583. /// <para>
  584. /// On set, if <see cref="SuperView"/> has only one TabStop, <see cref="TabIndex"/> will be set to 0.
  585. /// </para>
  586. /// </remarks>
  587. public int TabIndex
  588. {
  589. get => _tabIndex;
  590. set
  591. {
  592. if (!CanFocus)
  593. {
  594. // BUGBUG: Property setters should set the property to the value passed in and not have side effects.
  595. _tabIndex = -1;
  596. return;
  597. }
  598. if (SuperView?._tabIndexes is null || SuperView?._tabIndexes.Count == 1)
  599. {
  600. // BUGBUG: Property setters should set the property to the value passed in and not have side effects.
  601. _tabIndex = 0;
  602. return;
  603. }
  604. if (_tabIndex == value && TabIndexes.IndexOf (this) == value)
  605. {
  606. return;
  607. }
  608. _tabIndex = value > SuperView!.TabIndexes.Count - 1 ? SuperView._tabIndexes.Count - 1 :
  609. value < 0 ? 0 : value;
  610. _tabIndex = GetGreatestTabIndexInSuperView (_tabIndex);
  611. if (SuperView._tabIndexes.IndexOf (this) != _tabIndex)
  612. {
  613. // BUGBUG: we have to use _tabIndexes and not TabIndexes because TabIndexes returns is a read-only version of _tabIndexes
  614. SuperView._tabIndexes.Remove (this);
  615. SuperView._tabIndexes.Insert (_tabIndex, this);
  616. ReorderSuperViewTabIndexes ();
  617. }
  618. }
  619. }
  620. /// <summary>
  621. /// Gets the greatest <see cref="TabIndex"/> of the <see cref="SuperView"/>'s <see cref="TabIndexes"/> that is less
  622. /// than or equal to <paramref name="idx"/>.
  623. /// </summary>
  624. /// <param name="idx"></param>
  625. /// <returns>The minimum of <paramref name="idx"/> and the <see cref="SuperView"/>'s <see cref="TabIndexes"/>.</returns>
  626. private int GetGreatestTabIndexInSuperView (int idx)
  627. {
  628. var i = 0;
  629. foreach (View superViewTabStop in SuperView._tabIndexes)
  630. {
  631. if (superViewTabStop._tabIndex == -1 || superViewTabStop == this)
  632. {
  633. continue;
  634. }
  635. i++;
  636. }
  637. return Math.Min (i, idx);
  638. }
  639. /// <summary>
  640. /// Re-orders the <see cref="TabIndex"/>s of the views in the <see cref="SuperView"/>'s <see cref="TabIndexes"/>.
  641. /// </summary>
  642. private void ReorderSuperViewTabIndexes ()
  643. {
  644. var i = 0;
  645. foreach (View superViewTabStop in SuperView._tabIndexes)
  646. {
  647. if (superViewTabStop._tabIndex == -1)
  648. {
  649. continue;
  650. }
  651. superViewTabStop._tabIndex = i;
  652. i++;
  653. }
  654. }
  655. private bool _tabStop = true;
  656. /// <summary>
  657. /// Gets or sets whether the view is a stop-point for keyboard navigation of focus. Will be <see langword="true"/>
  658. /// only if <see cref="CanFocus"/> is <see langword="true"/>. Set to <see langword="false"/> to prevent the
  659. /// view from being a stop-point for keyboard navigation.
  660. /// </summary>
  661. /// <remarks>
  662. /// The default keyboard navigation keys are <c>Key.Tab</c> and <c>Key>Tab.WithShift</c>. These can be changed by
  663. /// modifying the key bindings (see <see cref="KeyBindings.Add(Key, Command[])"/>) of the SuperView.
  664. /// </remarks>
  665. public bool TabStop
  666. {
  667. get => _tabStop;
  668. set
  669. {
  670. if (_tabStop == value)
  671. {
  672. return;
  673. }
  674. _tabStop = CanFocus && value;
  675. }
  676. }
  677. #endregion Tab/Focus Handling
  678. }