1
1
#nullable enable
2
2
using System . Diagnostics ;
3
- using System . Reflection . PortableExecutable ;
4
3
5
4
namespace Terminal . Gui ;
6
5
@@ -18,7 +17,8 @@ public partial class View // Focus and cross-view navigation management (TabStop
18
17
/// If there is no next/previous view to advance to, the focus is set to the view itself.
19
18
/// </para>
20
19
/// <para>
21
- /// See the View Navigation Deep Dive for more information: <see href="https://gui-cs.github.io/Terminal.GuiV2Docs/docs/navigation.html"/>
20
+ /// See the View Navigation Deep Dive for more information:
21
+ /// <see href="https://gui-cs.github.io/Terminal.GuiV2Docs/docs/navigation.html"/>
22
22
/// </para>
23
23
/// </remarks>
24
24
/// <param name="direction"></param>
@@ -136,8 +136,11 @@ public bool AdvanceFocus (NavigationDirection direction, TabBehavior? behavior)
136
136
if ( view != this )
137
137
{
138
138
// Tell it to try the other way.
139
- return view . RaiseAdvancingFocus ( direction == NavigationDirection . Forward ? NavigationDirection . Backward : NavigationDirection . Forward , behavior ) ;
139
+ return view . RaiseAdvancingFocus (
140
+ direction == NavigationDirection . Forward ? NavigationDirection . Backward : NavigationDirection . Forward ,
141
+ behavior ) ;
140
142
}
143
+
141
144
return view == this ;
142
145
}
143
146
@@ -172,6 +175,10 @@ private bool RaiseAdvancingFocus (NavigationDirection direction, TabBehavior? be
172
175
/// Called when <see cref="View.AdvanceFocus"/> is about to advance focus.
173
176
/// </summary>
174
177
/// <remarks>
178
+ /// <para>
179
+ /// If a view cancels the event and the focus could not otherwise advance, the Navigation direction will be
180
+ /// reversed and the event will be raised again.
181
+ /// </para>
175
182
/// </remarks>
176
183
/// <returns>
177
184
/// <see langword="true"/>, if the focus advance is to be cancelled, <see langword="false"/>
@@ -187,16 +194,17 @@ private bool RaiseAdvancingFocus (NavigationDirection direction, TabBehavior? be
187
194
/// Cancel the event to prevent the focus from advancing.
188
195
/// </para>
189
196
/// <para>
190
- /// Use <see cref="HasFocusChanged"/> to be notified after the focus has changed.
197
+ /// If a view cancels the event and the focus could not otherwise advance, the Navigation direction will be
198
+ /// reversed and the event will be raised again.
191
199
/// </para>
192
200
/// </remarks>
193
201
public event EventHandler < AdvanceFocusEventArgs > ? AdvancingFocus ;
194
202
195
-
196
203
/// <summary>Gets or sets a value indicating whether this <see cref="View"/> can be focused.</summary>
197
204
/// <remarks>
198
205
/// <para>
199
- /// See the View Navigation Deep Dive for more information: <see href="https://gui-cs.github.io/Terminal.GuiV2Docs/docs/navigation.html"/>
206
+ /// See the View Navigation Deep Dive for more information:
207
+ /// <see href="https://gui-cs.github.io/Terminal.GuiV2Docs/docs/navigation.html"/>
200
208
/// </para>
201
209
/// <para>
202
210
/// <see cref="SuperView"/> must also have <see cref="CanFocus"/> set to <see langword="true"/>.
@@ -235,13 +243,9 @@ public bool CanFocus
235
243
236
244
if ( ! _canFocus && HasFocus )
237
245
{
238
- if ( Title == "AdornmentsEditor" )
239
- {
240
-
241
- }
242
246
// If CanFocus is set to false and this view has focus, make it leave focus
243
- // Set traverssingdown so we don't go back up the hierachy ...
244
- SetHasFocusFalse ( null , traversingDown : false ) ;
247
+ // Set transversing down so we don't go back up the hierarchy ...
248
+ SetHasFocusFalse ( null , false ) ;
245
249
}
246
250
247
251
if ( _canFocus && ! HasFocus && Visible && SuperView is { Focused : null } )
@@ -390,7 +394,8 @@ internal bool RestoreFocus ()
390
394
/// </summary>
391
395
/// <remarks>
392
396
/// <para>
393
- /// See the View Navigation Deep Dive for more information: <see href="https://gui-cs.github.io/Terminal.GuiV2Docs/docs/navigation.html"/>
397
+ /// See the View Navigation Deep Dive for more information:
398
+ /// <see href="https://gui-cs.github.io/Terminal.GuiV2Docs/docs/navigation.html"/>
394
399
/// </para>
395
400
/// <para>
396
401
/// Only Views that are visible, enabled, and have <see cref="CanFocus"/> set to <see langword="true"/> are
@@ -442,6 +447,7 @@ public bool HasFocus
442
447
SetHasFocusFalse ( null ) ;
443
448
444
449
Debug . Assert ( ! _hasFocus ) ;
450
+
445
451
if ( _hasFocus )
446
452
{
447
453
// force it.
@@ -458,7 +464,8 @@ public bool HasFocus
458
464
/// </summary>
459
465
/// <remarks>
460
466
/// <para>
461
- /// See the View Navigation Deep Dive for more information: <see href="https://gui-cs.github.io/Terminal.GuiV2Docs/docs/navigation.html"/>
467
+ /// See the View Navigation Deep Dive for more information:
468
+ /// <see href="https://gui-cs.github.io/Terminal.GuiV2Docs/docs/navigation.html"/>
462
469
/// </para>
463
470
/// </remarks>
464
471
/// <returns><see langword="true"/> if the focus changed; <see langword="true"/> false otherwise.</returns>
@@ -677,7 +684,8 @@ private bool RaiseFocusChanging (bool currentHasFocus, bool newHasFocus, View? c
677
684
/// </param>
678
685
/// <param name="traversingDown">
679
686
/// Set to true to traverse down the focus
680
- /// chain only. If false, the method will attempt to AdvanceFocus on the superview or restorefocus on Application.Navigation.GetFocused().
687
+ /// chain only. If false, the method will attempt to AdvanceFocus on the superview or restorefocus on
688
+ /// Application.Navigation.GetFocused().
681
689
/// </param>
682
690
/// <exception cref="InvalidOperationException"></exception>
683
691
private void SetHasFocusFalse ( View ? newFocusedView , bool traversingDown = false )
@@ -707,6 +715,7 @@ private void SetHasFocusFalse (View? newFocusedView, bool traversingDown = false
707
715
{
708
716
// The above will cause SetHasFocusFalse, so we can return
709
717
Debug . Assert ( ! _hasFocus ) ;
718
+
710
719
return ;
711
720
}
712
721
}
@@ -744,6 +753,7 @@ private void SetHasFocusFalse (View? newFocusedView, bool traversingDown = false
744
753
{
745
754
// The above caused SetHasFocusFalse, so we can return
746
755
Debug . Assert ( ! _hasFocus ) ;
756
+
747
757
return ;
748
758
}
749
759
}
@@ -765,9 +775,11 @@ private void SetHasFocusFalse (View? newFocusedView, bool traversingDown = false
765
775
{
766
776
// The above caused SetHasFocusFalse, so we can return
767
777
Debug . Assert ( ! _hasFocus ) ;
778
+
768
779
return ;
769
780
}
770
781
}
782
+
771
783
// No other focusable view to be found. Just "leave" us...
772
784
}
773
785
@@ -880,7 +892,8 @@ protected virtual void OnHasFocusChanged (bool newHasFocus, View? previousFocuse
880
892
#region Tab/Focus Handling
881
893
882
894
/// <summary>
883
- /// Gets the subviews and Adornments of this view that are scoped to the specified behavior and direction. If behavior is null, all focusable subviews and
895
+ /// Gets the subviews and Adornments of this view that are scoped to the specified behavior and direction. If behavior
896
+ /// is null, all focusable subviews and
884
897
/// Adornments are returned.
885
898
/// </summary>
886
899
/// <param name="direction"></param>
@@ -899,7 +912,6 @@ internal View [] GetFocusChain (NavigationDirection direction, TabBehavior? beha
899
912
filteredSubviews = _subviews ? . Where ( v => v is { CanFocus : true , Visible : true , Enabled : true } ) ;
900
913
}
901
914
902
-
903
915
// How about in Adornments?
904
916
if ( Padding is { CanFocus : true , Visible : true , Enabled : true } && Padding . TabStop == behavior )
905
917
{
@@ -930,11 +942,14 @@ internal View [] GetFocusChain (NavigationDirection direction, TabBehavior? beha
930
942
/// Gets or sets the behavior of <see cref="AdvanceFocus"/> for keyboard navigation.
931
943
/// </summary>
932
944
/// <remarks>
933
- /// <remarks>
945
+ /// <remarks>
946
+ /// <para>
947
+ /// See the View Navigation Deep Dive for more information:
948
+ /// <see href="https://gui-cs.github.io/Terminal.GuiV2Docs/docs/navigation.html"/>
949
+ /// </para>
950
+ /// </remarks>
951
+ /// ///
934
952
/// <para>
935
- /// See the View Navigation Deep Dive for more information: <see href="https://gui-cs.github.io/Terminal.GuiV2Docs/docs/navigation.html"/>
936
- /// </para>
937
- /// </remarks> /// <para>
938
953
/// If <see langword="null"/> the tab stop has not been set and setting <see cref="CanFocus"/> to true will set it
939
954
/// to
940
955
/// <see cref="TabBehavior.TabStop"/>.
0 commit comments