diff --git a/README.md b/README.md
index 803d3e698..5e6742332 100644
--- a/README.md
+++ b/README.md
@@ -35,7 +35,7 @@ dotnet run
* [API Documentation](https://gui-cs.github.io/Terminal.GuiV2Docs/api/Terminal.Gui.html)
* [Documentation Home](https://gui-cs.github.io/Terminal.GuiV2Docs)
-_The Documentation matches the most recent Nuget release from the `v2_develop` branch. The documentation for v1 is here: ([](https://www.nuget.org/packages/Terminal.Gui))_
+The above documentation matches the most recent Nuget release from the `v2_develop` branch. Get the [v1 documentation here]( (This is the v2 API documentation. For v1 go here: https://gui-cs.github.io/Terminal.Gui/api/Terminal.Gui.html)
See the [`Terminal.Gui/` README](https://github.com/gui-cs/Terminal.Gui/tree/master/Terminal.Gui) for an overview of how the library is structured.
diff --git a/Terminal.Gui/Application/Application.Run.cs b/Terminal.Gui/Application/Application.Run.cs
index 9ebe0c3b8..c29c0272f 100644
--- a/Terminal.Gui/Application/Application.Run.cs
+++ b/Terminal.Gui/Application/Application.Run.cs
@@ -222,7 +222,7 @@ public static partial class Application // Run (Begin, Run, End, Stop)
internal static bool PositionCursor (View view)
{
// Find the most focused view and position the cursor there.
- View? mostFocused = view?.GetMostFocused ();
+ View? mostFocused = view?.MostFocused;
if (mostFocused is null)
{
diff --git a/Terminal.Gui/Application/ApplicationOverlapped.cs b/Terminal.Gui/Application/ApplicationOverlapped.cs
index 4a8d55d47..14a4163ea 100644
--- a/Terminal.Gui/Application/ApplicationOverlapped.cs
+++ b/Terminal.Gui/Application/ApplicationOverlapped.cs
@@ -75,7 +75,7 @@ public static class ApplicationOverlapped
return;
}
- View? top = FindTopFromView (Application.Top?.GetMostFocused ());
+ View? top = FindTopFromView (Application.Top?.MostFocused);
if (top is Toplevel && Application.Top?.Subviews.Count > 1 && Application.Top.Subviews [^1] != top)
{
diff --git a/Terminal.Gui/View/View.Hierarchy.cs b/Terminal.Gui/View/View.Hierarchy.cs
index 21a84d345..8c7eddd22 100644
--- a/Terminal.Gui/View/View.Hierarchy.cs
+++ b/Terminal.Gui/View/View.Hierarchy.cs
@@ -196,7 +196,7 @@ public partial class View // SuperView/SubView hierarchy management (SuperView,
// If a view being removed is focused, it should lose focus.
if (view.HasFocus)
{
- view.LeaveFocus(this, true);
+ view.FocusChanged(this, true);
}
Rectangle touched = view.Frame;
@@ -217,7 +217,7 @@ public partial class View // SuperView/SubView hierarchy management (SuperView,
if (HasFocus)
{
- FocusDeepest (TabStop, NavigationDirection.Forward);
+ FocusDeepest (NavigationDirection.Forward, TabStop);
}
OnRemoved (new (this, view));
diff --git a/Terminal.Gui/View/View.Navigation.cs b/Terminal.Gui/View/View.Navigation.cs
index c4744081b..6ba3ed1e6 100644
--- a/Terminal.Gui/View/View.Navigation.cs
+++ b/Terminal.Gui/View/View.Navigation.cs
@@ -21,8 +21,8 @@ public partial class View // Focus and cross-view navigation management (TabStop
/// these conditions are not met when this property is set to will not change.
///
///
- /// Setting this property causes the and virtual methods (and and
- /// events to be raised). If the event is cancelled, will not be changed.
+ /// Setting this property causes the and virtual methods (and and
+ /// events to be raised). If the event is cancelled, will not be changed.
///
///
/// Setting this property to will recursively set to
@@ -45,7 +45,7 @@ public partial class View // Focus and cross-view navigation management (TabStop
{
if (value)
{
- if (EnterFocus (Application.Navigation!.GetFocused ()))
+ if (FocusChanging (Application.Navigation!.GetFocused ()))
{
// The change happened
// HasFocus is now true
@@ -53,7 +53,7 @@ public partial class View // Focus and cross-view navigation management (TabStop
}
else
{
- LeaveFocus (null);
+ FocusChanged (null);
}
}
}
@@ -66,18 +66,18 @@ public partial class View // Focus and cross-view navigation management (TabStop
///
public bool SetFocus ()
{
- return EnterFocus (Application.Navigation?.GetFocused ());
+ return FocusChanging (Application.Navigation?.GetFocused ());
}
///
- /// Called when view is entering focus. This method is called by and other methods that
+ /// INTERNAL: Called when focus is going to change to this view. This method is called by and other methods that
/// set or remove focus from a view.
///
- /// The previously focused view. If there is no previously focused view.
+ /// The previously focused view. If there is no previously focused view.
///
/// if was changed to .
///
- private bool EnterFocus ([CanBeNull] View leavingView, bool traversingUp = false)
+ private bool FocusChanging ([CanBeNull] View previousFocusedView, bool traversingUp = false)
{
Debug.Assert (ApplicationNavigation.IsInHierarchy (SuperView, this));
@@ -89,7 +89,7 @@ public partial class View // Focus and cross-view navigation management (TabStop
if (CanFocus && SuperView is { CanFocus: false })
{
- Debug.WriteLine($@"WARNING: Attempt to EnterFocus where SuperView.CanFocus == false. {this}");
+ Debug.WriteLine($@"WARNING: Attempt to FocusChanging where SuperView.CanFocus == false. {this}");
return false;
}
@@ -107,7 +107,7 @@ public partial class View // Focus and cross-view navigation management (TabStop
if (!traversingUp)
{
- if (CancelEnterFocus (leavingView))
+ if (NotifyFocusChanging (previousFocusedView))
{
return false;
}
@@ -134,14 +134,14 @@ public partial class View // Focus and cross-view navigation management (TabStop
// If we previously had a subview with focus (`Focused = subview`), we need to make sure that all subviews down the `subview`-hierarchy LeaveFocus.
// LeaveFocus will recurse down the subview hierarchy and will also set PreviouslyMostFocused
View focused = Focused;
- focused?.LeaveFocus (this, true);
+ focused?.FocusChanged (this, true);
// We need to ensure all superviews up the superview hierarchy have focus.
// Any of them may cancel gaining focus. In which case we need to back out.
if (SuperView is { HasFocus: false } sv)
{
// Tell EnterFocus that we're traversing up the superview hierarchy
- if (!sv.EnterFocus (leavingView, true))
+ if (!sv.FocusChanging (previousFocusedView, true))
{
// The change was cancelled
return false;
@@ -160,7 +160,7 @@ public partial class View // Focus and cross-view navigation management (TabStop
_hasFocus = true;
// Ensure that the peer loses focus
- focusedPeer?.LeaveFocus (this, true);
+ focusedPeer?.FocusChanged (this, true);
// We're the most focused view in the application, we need to set the focused view to this view.
Application.Navigation?.SetFocused (this);
@@ -170,24 +170,24 @@ public partial class View // Focus and cross-view navigation management (TabStop
// Post-conditions - prove correctness
if (HasFocus == previousValue)
{
- throw new InvalidOperationException ($"EnterFocus was not cancelled and the HasFocus value did not change.");
+ throw new InvalidOperationException ($"FocusChanging was not cancelled and the HasFocus value did not change.");
}
return true;
}
- private bool CancelEnterFocus (View leavingView)
+ private bool NotifyFocusChanging (View leavingView)
{
// Call the virtual method
- if (OnEnter (leavingView))
+ if (OnHasFocusChanging (leavingView))
{
// The event was cancelled
return true;
}
var args = new FocusEventArgs (leavingView, this);
- Enter?.Invoke (this, args);
+ HasFocusChanging?.Invoke (this, args);
if (args.Cancel)
{
@@ -198,48 +198,44 @@ public partial class View // Focus and cross-view navigation management (TabStop
return false;
}
- /// Virtual method invoked when this view is gaining focus (entering).
- /// The view that is leaving focus.
+ /// Virtual method invoked when the focus is changing to this View.
+ /// The view that is currently Focused. May be .
/// , if the event is to be cancelled, otherwise.
- protected virtual bool OnEnter ([CanBeNull] View leavingView)
+ protected virtual bool OnHasFocusChanging ([CanBeNull] View currentlyFocusedView)
{
return false;
}
/// Raised when the view is gaining (entering) focus. Can be cancelled.
- ///
- /// Raised by .
- ///
- public event EventHandler Enter;
+ public event EventHandler HasFocusChanging;
///
- /// Called when view is losing focus.
+ /// Called when focus has changed to another view.
///
- /// The previously focused view. If there is no previously focused view.
- /// if was changed.
+ /// The view that now has focus. If there is no view that has focus.
///
- private void LeaveFocus ([CanBeNull] View enteringView, bool traversingDown = false)
+ private void FocusChanged ([CanBeNull] View focusedVew, bool traversingDown = false)
{
// Pre-conditions
if (!_hasFocus)
{
- throw new InvalidOperationException ($"LeaveFocus should not be called if the view does not have focus.");
+ throw new InvalidOperationException ($"FocusChanged should not be called if the view does not have focus.");
}
// If enteringView is null, we need to find the view that should get focus, and SetFocus on it.
- if (!traversingDown && enteringView is null)
+ if (!traversingDown && focusedVew is null)
{
if (SuperView?._previouslyMostFocused is { } && SuperView?._previouslyMostFocused != this)
{
SuperView?._previouslyMostFocused?.SetFocus ();
- // The above will cause LeaveFocus, so we can return
+ // The above will cause FocusChanged, so we can return
return;
}
if (SuperView is {} && SuperView.AdvanceFocus (NavigationDirection.Forward, TabStop))
{
- // The above will cause LeaveFocus, so we can return
+ // The above will cause FocusChanged, so we can return
return;
}
@@ -259,8 +255,8 @@ public partial class View // Focus and cross-view navigation management (TabStop
}
// Before we can leave focus, we need to make sure that all views down the subview-hierarchy have left focus.
- View mostFocused = GetMostFocused ();
- if (mostFocused is { } && (enteringView is null || mostFocused != enteringView))
+ View mostFocused = MostFocused;
+ if (mostFocused is { } && (focusedVew is null || mostFocused != focusedVew))
{
// Start at the bottom and work our way up to us
View bottom = mostFocused;
@@ -269,7 +265,7 @@ public partial class View // Focus and cross-view navigation management (TabStop
{
if (bottom.HasFocus)
{
- bottom.LeaveFocus (enteringView, true);
+ bottom.FocusChanged (focusedVew, true);
}
bottom = bottom.SuperView;
}
@@ -279,10 +275,10 @@ public partial class View // Focus and cross-view navigation management (TabStop
bool previousValue = HasFocus;
// Call the virtual method - NOTE: Leave cannot be cancelled
- OnLeave (enteringView);
+ OnHasFocusChanged (focusedVew);
- var args = new FocusEventArgs (enteringView, this);
- Leave?.Invoke (this, args);
+ var args = new FocusEventArgs (focusedVew, this);
+ HasFocusChanged?.Invoke (this, args);
// Get whatever peer has focus, if any
View focusedPeer = SuperView?.Focused;
@@ -293,7 +289,7 @@ public partial class View // Focus and cross-view navigation management (TabStop
// Now ensure all views up the superview-hierarchy are unfocused
if (SuperView is { HasFocus: true } && focusedPeer == this)
{
- SuperView.LeaveFocus (enteringView);
+ SuperView.FocusChanged (focusedVew);
}
}
@@ -312,18 +308,15 @@ public partial class View // Focus and cross-view navigation management (TabStop
[CanBeNull]
private View _previouslyMostFocused;
- /// Virtual method invoked when this view is losing focus (leaving).
- /// The view that is gaining focus.
- protected virtual void OnLeave ([CanBeNull] View enteringView)
+ /// Virtual method invoked after another view gets focus. May be .
+ /// The view is now focused.
+ protected virtual void OnHasFocusChanged ([CanBeNull] View focusedVew)
{
return;
}
- /// Raised when the view is gaining (entering) focus. Can NOT be cancelled.
- ///
- /// Raised by .
- ///
- public event EventHandler Leave;
+ /// Raised when the view is gaining (entering) focus. Can not be cancelled.
+ public event EventHandler HasFocusChanged;
#endregion HasFocus
@@ -399,7 +392,7 @@ public partial class View // Focus and cross-view navigation management (TabStop
}
// The subview does not have focus, but at least one other that can. Can this one be focused?
- return view.EnterFocus (Focused);
+ return view.FocusChanging (Focused);
}
@@ -426,22 +419,26 @@ public partial class View // Focus and cross-view navigation management (TabStop
///
/// Returns the most focused Subview down the subview-hierarchy.
///
- /// The most focused Subview, or if no Subview is focused.
- public View GetMostFocused ()
+ /// The most focused Subview, or if no Subview is focused.
+ public View MostFocused
{
- if (Focused is null)
+ get
{
- return null;
+ // TODO: Remove this API. It's duplicative of Application.Navigation.GetFocused.
+ if (Focused is null)
+ {
+ return null;
+ }
+
+ View most = Focused!.MostFocused;
+
+ if (most is { })
+ {
+ return most;
+ }
+
+ return Focused;
}
-
- View most = Focused!.GetMostFocused ();
-
- if (most is { })
- {
- return most;
- }
-
- return Focused;
}
/////
diff --git a/Terminal.Gui/Views/ComboBox.cs b/Terminal.Gui/Views/ComboBox.cs
index 3a5202694..22f62c238 100644
--- a/Terminal.Gui/Views/ComboBox.cs
+++ b/Terminal.Gui/Views/ComboBox.cs
@@ -299,7 +299,7 @@ public class ComboBox : View, IDesignable
}
///
- protected override bool OnEnter (View view)
+ protected override bool OnHasFocusChanging (View view)
{
if (!_search.HasFocus && !_listview.HasFocus)
{
@@ -315,7 +315,7 @@ public class ComboBox : View, IDesignable
public virtual void OnExpanded () { Expanded?.Invoke (this, EventArgs.Empty); }
///
- protected override void OnLeave (View view)
+ protected override void OnHasFocusChanged (View view)
{
if (_source?.Count > 0
&& _selectedItem > -1
@@ -940,7 +940,7 @@ public class ComboBox : View, IDesignable
}
}
- protected override bool OnEnter (View view)
+ protected override bool OnHasFocusChanging (View view)
{
if (_hideDropdownListOnClick)
{
@@ -952,7 +952,7 @@ public class ComboBox : View, IDesignable
return false; // Don't cancel the focus switch
}
- protected override void OnLeave (View view)
+ protected override void OnHasFocusChanged (View view)
{
if (_hideDropdownListOnClick)
{
diff --git a/Terminal.Gui/Views/FileDialog.cs b/Terminal.Gui/Views/FileDialog.cs
index 64345ae32..6251c12fb 100644
--- a/Terminal.Gui/Views/FileDialog.cs
+++ b/Terminal.Gui/Views/FileDialog.cs
@@ -518,7 +518,7 @@ public class FileDialog : Dialog
};
AllowedTypeMenuClicked (0);
- _allowedTypeMenuBar.Enter += (s, e) => { _allowedTypeMenuBar.OpenMenu (0); };
+ _allowedTypeMenuBar.HasFocusChanging += (s, e) => { _allowedTypeMenuBar.OpenMenu (0); };
_allowedTypeMenuBar.DrawContentComplete += (s, e) =>
{
@@ -538,7 +538,7 @@ public class FileDialog : Dialog
// to streamline user experience and allow direct typing of paths
// with zero navigation we start with focus in the text box and any
// default/current path fully selected and ready to be overwritten
- _tbPath.FocusDeepest (null, NavigationDirection.Forward);
+ _tbPath.FocusDeepest (NavigationDirection.Forward, null);
_tbPath.SelectAll ();
if (string.IsNullOrEmpty (Title))
@@ -1050,7 +1050,7 @@ public class FileDialog : Dialog
{
if (keyEvent.KeyCode == isKey)
{
- to.FocusDeepest (null, NavigationDirection.Forward);
+ to.FocusDeepest (NavigationDirection.Forward, null);
if (to == _tbPath)
{
@@ -1439,7 +1439,7 @@ public class FileDialog : Dialog
{
if (_treeView.HasFocus && Separators.Contains ((char)keyEvent))
{
- _tbPath.FocusDeepest (null, NavigationDirection.Forward);
+ _tbPath.FocusDeepest (NavigationDirection.Forward, null);
// let that keystroke go through on the tbPath instead
return true;
diff --git a/Terminal.Gui/Views/ListView.cs b/Terminal.Gui/Views/ListView.cs
index 303e524ba..daff465b7 100644
--- a/Terminal.Gui/Views/ListView.cs
+++ b/Terminal.Gui/Views/ListView.cs
@@ -739,7 +739,7 @@ public class ListView : View, IDesignable
}
///
- protected override bool OnEnter (View view)
+ protected override bool OnHasFocusChanging (View view)
{
if (_lastSelectedItem != _selected)
{
diff --git a/Terminal.Gui/Views/Menu/Menu.cs b/Terminal.Gui/Views/Menu/Menu.cs
index 860ddc6da..1de4f77b9 100644
--- a/Terminal.Gui/Views/Menu/Menu.cs
+++ b/Terminal.Gui/Views/Menu/Menu.cs
@@ -587,7 +587,7 @@ internal sealed class Menu : View
_host.Run (action);
}
- protected override void OnLeave (View view)
+ protected override void OnHasFocusChanged (View view)
{
_host.LostFocus (view);
diff --git a/Terminal.Gui/Views/Menu/MenuBar.cs b/Terminal.Gui/Views/Menu/MenuBar.cs
index cb3f5afac..a900d060e 100644
--- a/Terminal.Gui/Views/Menu/MenuBar.cs
+++ b/Terminal.Gui/Views/Menu/MenuBar.cs
@@ -755,7 +755,7 @@ public class MenuBar : View, IDesignable
{
case null:
// Open a submenu below a MenuBar
- _lastFocused ??= SuperView is null ? Application.Current?.GetMostFocused () : SuperView.GetMostFocused ();
+ _lastFocused ??= SuperView is null ? Application.Current?.MostFocused : SuperView.MostFocused;
if (_openSubMenu is { } && !CloseMenu (false, true))
{
diff --git a/Terminal.Gui/Views/Shortcut.cs b/Terminal.Gui/Views/Shortcut.cs
index c9ec4a541..754b89061 100644
--- a/Terminal.Gui/Views/Shortcut.cs
+++ b/Terminal.Gui/Views/Shortcut.cs
@@ -837,7 +837,7 @@ public class Shortcut : View, IOrientation, IDesignable
private View _lastFocusedView;
///
- protected override bool OnEnter (View view)
+ protected override bool OnHasFocusChanging (View view)
{
SetColors ();
_lastFocusedView = view;
@@ -846,7 +846,7 @@ public class Shortcut : View, IOrientation, IDesignable
}
///
- protected override void OnLeave (View view)
+ protected override void OnHasFocusChanged (View view)
{
SetColors ();
_lastFocusedView = this;
diff --git a/Terminal.Gui/Views/TextField.cs b/Terminal.Gui/Views/TextField.cs
index 5a958d414..f52b02972 100644
--- a/Terminal.Gui/Views/TextField.cs
+++ b/Terminal.Gui/Views/TextField.cs
@@ -1033,7 +1033,7 @@ public class TextField : View
}
///
- protected override void OnLeave (View view)
+ protected override void OnHasFocusChanged (View view)
{
if (Application.MouseGrabView is { } && Application.MouseGrabView == this)
{
diff --git a/Terminal.Gui/Views/TextView.cs b/Terminal.Gui/Views/TextView.cs
index 1258596bb..58b2c75b5 100644
--- a/Terminal.Gui/Views/TextView.cs
+++ b/Terminal.Gui/Views/TextView.cs
@@ -3650,7 +3650,7 @@ public class TextView : View
}
///
- protected override void OnLeave (View view)
+ protected override void OnHasFocusChanged (View view)
{
if (Application.MouseGrabView is { } && Application.MouseGrabView == this)
{
diff --git a/Terminal.Gui/Views/TreeView/TreeView.cs b/Terminal.Gui/Views/TreeView/TreeView.cs
index d34408a65..c6cca5991 100644
--- a/Terminal.Gui/Views/TreeView/TreeView.cs
+++ b/Terminal.Gui/Views/TreeView/TreeView.cs
@@ -1155,7 +1155,7 @@ public class TreeView : View, ITreeView where T : class
}
///
- protected override bool OnEnter (View view)
+ protected override bool OnHasFocusChanging (View view)
{
if (SelectedObject is null && Objects.Any ())
{
diff --git a/UICatalog/KeyBindingsDialog.cs b/UICatalog/KeyBindingsDialog.cs
index 4fbfad24a..c746137ac 100644
--- a/UICatalog/KeyBindingsDialog.cs
+++ b/UICatalog/KeyBindingsDialog.cs
@@ -60,7 +60,7 @@ internal class KeyBindingsDialog : Dialog
AddButton (cancel);
// Register event handler as the last thing in constructor to prevent early calls
- // before it is even shown (e.g. OnEnter)
+ // before it is even shown (e.g. OnHasFocusChanging)
_commandsListView.SelectedItemChanged += CommandsListView_SelectedItemChanged;
// Setup to show first ListView entry
diff --git a/UICatalog/Scenarios/ASCIICustomButton.cs b/UICatalog/Scenarios/ASCIICustomButton.cs
index 27c4f0810..90f18eb87 100644
--- a/UICatalog/Scenarios/ASCIICustomButton.cs
+++ b/UICatalog/Scenarios/ASCIICustomButton.cs
@@ -110,7 +110,7 @@ public class ASCIICustomButtonTest : Scenario
Add (_border, _fill, title);
}
- protected override bool OnEnter (View view)
+ protected override bool OnHasFocusChanging (View view)
{
_border.Visible = false;
_fill.Visible = true;
@@ -119,7 +119,7 @@ public class ASCIICustomButtonTest : Scenario
return false; // don't cancel
}
- protected override void OnLeave (View view)
+ protected override void OnHasFocusChanged (View view)
{
_border.Visible = true;
_fill.Visible = false;
diff --git a/UICatalog/Scenarios/ConfigurationEditor.cs b/UICatalog/Scenarios/ConfigurationEditor.cs
index d2d80b859..988766dfd 100644
--- a/UICatalog/Scenarios/ConfigurationEditor.cs
+++ b/UICatalog/Scenarios/ConfigurationEditor.cs
@@ -101,7 +101,7 @@ public class ConfigurationEditor : Scenario
}
public void Save ()
{
- if (_tileView.GetMostFocused () is ConfigTextView editor)
+ if (_tileView.MostFocused is ConfigTextView editor)
{
editor.Save ();
}
@@ -133,7 +133,7 @@ public class ConfigurationEditor : Scenario
textView.Read ();
- textView.Enter += (s, e) => { _lenShortcut.Title = $"Len:{textView.Text.Length}"; };
+ textView.HasFocusChanging += (s, e) => { _lenShortcut.Title = $"Len:{textView.Text.Length}"; };
}
Application.Top.LayoutSubviews ();
@@ -172,7 +172,7 @@ public class ConfigurationEditor : Scenario
private void Reload ()
{
- if (_tileView.GetMostFocused () is ConfigTextView editor)
+ if (_tileView.MostFocused is ConfigTextView editor)
{
editor.Read ();
}
diff --git a/UICatalog/Scenarios/DynamicMenuBar.cs b/UICatalog/Scenarios/DynamicMenuBar.cs
index 1cd3ae0ef..25152ecd8 100644
--- a/UICatalog/Scenarios/DynamicMenuBar.cs
+++ b/UICatalog/Scenarios/DynamicMenuBar.cs
@@ -938,7 +938,7 @@ public class DynamicMenuBar : Scenario
SetFrameDetails (menuBarItem);
};
- _lstMenus.Enter += (s, e) =>
+ _lstMenus.HasFocusChanging += (s, e) =>
{
MenuItem menuBarItem = _lstMenus.SelectedItem > -1 && DataContext.Menus.Count > 0
? DataContext.Menus [_lstMenus.SelectedItem].MenuItem
@@ -966,7 +966,7 @@ public class DynamicMenuBar : Scenario
SelectCurrentMenuBarItem ();
};
- lblMenuBar.Enter += (s, e) =>
+ lblMenuBar.HasFocusChanging += (s, e) =>
{
if (_menuBar?.Menus != null)
{
diff --git a/UICatalog/Scenarios/DynamicStatusBar.cs b/UICatalog/Scenarios/DynamicStatusBar.cs
index 828b2dab7..6ef18b55c 100644
--- a/UICatalog/Scenarios/DynamicStatusBar.cs
+++ b/UICatalog/Scenarios/DynamicStatusBar.cs
@@ -440,7 +440,7 @@ public class DynamicStatusBar : Scenario
}
};
- _lstItems.Enter += (s, e) =>
+ _lstItems.HasFocusChanging += (s, e) =>
{
Shortcut statusItem = DataContext.Items.Count > 0
? DataContext.Items [_lstItems.SelectedItem].Shortcut
diff --git a/UICatalog/Scenarios/Editor.cs b/UICatalog/Scenarios/Editor.cs
index 73b0773ca..652ecc733 100644
--- a/UICatalog/Scenarios/Editor.cs
+++ b/UICatalog/Scenarios/Editor.cs
@@ -860,7 +860,7 @@ public class Editor : Scenario
Width = Dim.Fill (1),
Text = _textToFind
};
- txtToFind.Enter += (s, e) => txtToFind.Text = _textToFind;
+ txtToFind.HasFocusChanging += (s, e) => txtToFind.Text = _textToFind;
d.Add (txtToFind);
var btnFindNext = new Button
@@ -1088,7 +1088,7 @@ public class Editor : Scenario
Width = Dim.Fill (1),
Text = _textToFind
};
- txtToFind.Enter += (s, e) => txtToFind.Text = _textToFind;
+ txtToFind.HasFocusChanging += (s, e) => txtToFind.Text = _textToFind;
d.Add (txtToFind);
var btnFindNext = new Button
diff --git a/UICatalog/Scenarios/KeyBindings.cs b/UICatalog/Scenarios/KeyBindings.cs
index 1854da2eb..2da18601c 100644
--- a/UICatalog/Scenarios/KeyBindings.cs
+++ b/UICatalog/Scenarios/KeyBindings.cs
@@ -125,8 +125,8 @@ public sealed class KeyBindings : Scenario
};
appWindow.Add (_focusedBindingsListView);
- appWindow.Leave += AppWindow_Leave;
- appWindow.Enter += AppWindow_Leave;
+ appWindow.HasFocusChanged += AppWindow_Leave;
+ appWindow.HasFocusChanging += AppWindow_Leave;
appWindow.DrawContent += AppWindow_DrawContent;
// Run - Start the application.
@@ -139,10 +139,10 @@ public sealed class KeyBindings : Scenario
private void AppWindow_DrawContent (object sender, DrawEventArgs e)
{
- _focusedBindingsListView.Title = $"_Focused ({Application.Top.GetMostFocused ().GetType ().Name}) Bindings";
+ _focusedBindingsListView.Title = $"_Focused ({Application.Top.MostFocused.GetType ().Name}) Bindings";
_focusedBindings.Clear ();
- foreach (var binding in Application.Top.GetMostFocused ().KeyBindings.Bindings.Where (b => b.Value.Scope == KeyBindingScope.Focused))
+ foreach (var binding in Application.Top.MostFocused.KeyBindings.Bindings.Where (b => b.Value.Scope == KeyBindingScope.Focused))
{
_focusedBindings.Add ($"{binding.Key} -> {binding.Value.Commands [0]}");
}
@@ -150,7 +150,7 @@ public sealed class KeyBindings : Scenario
private void AppWindow_Leave (object sender, FocusEventArgs e)
{
- foreach (var binding in Application.Top.GetMostFocused ().KeyBindings.Bindings.Where (b => b.Value.Scope == KeyBindingScope.Focused))
+ foreach (var binding in Application.Top.MostFocused.KeyBindings.Bindings.Where (b => b.Value.Scope == KeyBindingScope.Focused))
{
_focusedBindings.Add ($"{binding.Key} -> {binding.Value.Commands [0]}");
}
diff --git a/UICatalog/Scenarios/MenuBarScenario.cs b/UICatalog/Scenarios/MenuBarScenario.cs
index edac4a054..b9c6bee67 100644
--- a/UICatalog/Scenarios/MenuBarScenario.cs
+++ b/UICatalog/Scenarios/MenuBarScenario.cs
@@ -107,7 +107,7 @@ public class MenuBarScenario : Scenario
};
// There's no focus change event, so this is a bit of a hack.
- menuBar.LayoutComplete += (s, e) => { _focusedView.Text = appWindow.GetMostFocused ()?.ToString () ?? "None"; };
+ menuBar.LayoutComplete += (s, e) => { _focusedView.Text = appWindow.MostFocused?.ToString () ?? "None"; };
var openBtn = new Button { X = Pos.Center (), Y = 4, Text = "_Open Menu", IsDefault = true };
openBtn.Accept += (s, e) => { menuBar.OpenMenu (); };
diff --git a/UICatalog/Scenarios/Notepad.cs b/UICatalog/Scenarios/Notepad.cs
index 0836be60c..31e6f3513 100644
--- a/UICatalog/Scenarios/Notepad.cs
+++ b/UICatalog/Scenarios/Notepad.cs
@@ -84,7 +84,7 @@ public class Notepad : Scenario
_focusedTabView = _tabView;
_tabView.SelectedTabChanged += TabView_SelectedTabChanged;
- _tabView.Enter += (s, e) => _focusedTabView = _tabView;
+ _tabView.HasFocusChanging += (s, e) => _focusedTabView = _tabView;
top.Ready += (s, e) =>
{
@@ -241,7 +241,7 @@ public class Notepad : Scenario
tv.TabClicked += TabView_TabClicked;
tv.SelectedTabChanged += TabView_SelectedTabChanged;
- tv.Enter += (s, e) => _focusedTabView = tv;
+ tv.HasFocusChanging += (s, e) => _focusedTabView = tv;
return tv;
}
@@ -309,7 +309,7 @@ public class Notepad : Scenario
tab.CloneTo (newTabView);
newTile.ContentView.Add (newTabView);
- newTabView.FocusDeepest (null, NavigationDirection.Forward);
+ newTabView.FocusDeepest (NavigationDirection.Forward, null);
newTabView.AdvanceFocus (NavigationDirection.Forward, null);
}
diff --git a/UnitTests/FileServices/FileDialogTests.cs b/UnitTests/FileServices/FileDialogTests.cs
index 873819f7c..1c0954168 100644
--- a/UnitTests/FileServices/FileDialogTests.cs
+++ b/UnitTests/FileServices/FileDialogTests.cs
@@ -107,8 +107,8 @@ public class FileDialogTests (ITestOutputHelper output)
Application.OnKeyDown (Key.Tab);
#endif
- Assert.IsType (dlg.GetMostFocused ());
- var tf = (TextField)dlg.GetMostFocused ();
+ Assert.IsType (dlg.MostFocused);
+ var tf = (TextField)dlg.MostFocused;
Assert.Equal ("Enter Search", tf.Caption);
// Dialog has not yet been confirmed with a choice
@@ -142,9 +142,9 @@ public class FileDialogTests (ITestOutputHelper output)
AssertIsTheStartingDirectory (dlg.Path);
- Assert.IsType (dlg.GetMostFocused ());
+ Assert.IsType (dlg.MostFocused);
Send ('v', ConsoleKey.DownArrow);
- Assert.IsType (dlg.GetMostFocused ());
+ Assert.IsType (dlg.MostFocused);
// ".." should be the first thing selected
// ".." should not mess with the displayed path
@@ -181,9 +181,9 @@ public class FileDialogTests (ITestOutputHelper output)
IReadOnlyCollection eventMultiSelected = null;
dlg.FilesSelected += (s, e) => { eventMultiSelected = e.Dialog.MultiSelected; };
- Assert.IsType (dlg.GetMostFocused ());
+ Assert.IsType (dlg.MostFocused);
Send ('v', ConsoleKey.DownArrow);
- Assert.IsType (dlg.GetMostFocused ());
+ Assert.IsType (dlg.MostFocused);
// Try to toggle '..'
Send (' ', ConsoleKey.Spacebar);
@@ -236,9 +236,9 @@ public class FileDialogTests (ITestOutputHelper output)
IReadOnlyCollection eventMultiSelected = null;
dlg.FilesSelected += (s, e) => { eventMultiSelected = e.Dialog.MultiSelected; };
- Assert.IsType (dlg.GetMostFocused ());
+ Assert.IsType (dlg.MostFocused);
Send ('v', ConsoleKey.DownArrow);
- Assert.IsType (dlg.GetMostFocused ());
+ Assert.IsType (dlg.MostFocused);
// Move selection to subfolder
Send ('v', ConsoleKey.DownArrow);
@@ -288,9 +288,9 @@ public class FileDialogTests (ITestOutputHelper output)
IReadOnlyCollection eventMultiSelected = null;
dlg.FilesSelected += (s, e) => { eventMultiSelected = e.Dialog.MultiSelected; };
- Assert.IsType (dlg.GetMostFocused ());
+ Assert.IsType (dlg.MostFocused);
Send ('v', ConsoleKey.DownArrow);
- Assert.IsType (dlg.GetMostFocused ());
+ Assert.IsType (dlg.MostFocused);
// Move selection to subfolder
Send ('v', ConsoleKey.DownArrow);
@@ -331,9 +331,9 @@ public class FileDialogTests (ITestOutputHelper output)
dlg.OpenMode = openModeMixed ? OpenMode.Mixed : OpenMode.Directory;
dlg.AllowsMultipleSelection = multiple;
- Assert.IsType (dlg.GetMostFocused ());
+ Assert.IsType (dlg.MostFocused);
Send ('v', ConsoleKey.DownArrow);
- Assert.IsType (dlg.GetMostFocused ());
+ Assert.IsType (dlg.MostFocused);
// Should be selecting ..
Send ('v', ConsoleKey.DownArrow);
diff --git a/UnitTests/View/Navigation/AddRemoveTests.cs b/UnitTests/View/Navigation/AddRemoveTests.cs
index ec26e3a2d..7fbfddabe 100644
--- a/UnitTests/View/Navigation/AddRemoveTests.cs
+++ b/UnitTests/View/Navigation/AddRemoveTests.cs
@@ -22,7 +22,7 @@ public class AddRemoveNavigationTests (ITestOutputHelper _output) : TestsAllView
Id = "subView",
CanFocus = true
};
- subView.Enter += (s, e) => nEnter++;
+ subView.HasFocusChanging += (s, e) => nEnter++;
top.Add (subView);
@@ -82,7 +82,7 @@ public class AddRemoveNavigationTests (ITestOutputHelper _output) : TestsAllView
Id = "subView",
CanFocus = true
};
- subView.Leave += (s, e) => nLeave++;
+ subView.HasFocusChanged += (s, e) => nLeave++;
top.Add (subView);
@@ -114,7 +114,7 @@ public class AddRemoveNavigationTests (ITestOutputHelper _output) : TestsAllView
Id = "subView1",
CanFocus = true
};
- subView1.Leave += (s, e) => nLeave1++;
+ subView1.HasFocusChanged += (s, e) => nLeave1++;
View subView2 = new View ()
{
diff --git a/UnitTests/View/Navigation/EnterLeaveTests.cs b/UnitTests/View/Navigation/EnterLeaveTests.cs
deleted file mode 100644
index 2be317b8e..000000000
--- a/UnitTests/View/Navigation/EnterLeaveTests.cs
+++ /dev/null
@@ -1,451 +0,0 @@
-using Xunit.Abstractions;
-
-namespace Terminal.Gui.ViewTests;
-
-public class EnterLeaveTests (ITestOutputHelper _output) : TestsAllViews
-{
- [Fact]
- public void SetFocus_FiresEnter ()
- {
- int nEnter = 0;
- int nLeave = 0;
- var view = new View ()
- {
- Id = "view",
- CanFocus = true
- };
- view.Enter += (s, e) => nEnter++;
- view.Leave += (s, e) => nLeave++;
-
- Assert.True (view.CanFocus);
- Assert.False (view.HasFocus);
-
- view.SetFocus ();
- Assert.True (view.HasFocus);
- Assert.Equal (1, nEnter);
- Assert.Equal (0, nLeave);
- }
-
- [Fact]
- public void RemoveFocus_FiresLeave ()
- {
- int nEnter = 0;
- int nLeave = 0;
- var view = new View ()
- {
- Id = "view",
- CanFocus = true
- };
- view.Enter += (s, e) => nEnter++;
- view.Leave += (s, e) => nLeave++;
-
- Assert.True (view.CanFocus);
- Assert.False (view.HasFocus);
-
- view.SetFocus ();
- Assert.True (view.HasFocus);
- Assert.Equal (1, nEnter);
- Assert.Equal (0, nLeave);
-
- view.HasFocus = false;
- Assert.Equal (1, nEnter);
- Assert.Equal (1, nLeave);
- }
-
- [Fact]
- public void SetFocus_SubView_SetFocus_FiresEnter ()
- {
- int viewEnterCount = 0;
- int viewLeaveCount = 0;
- var view = new View ()
- {
- Id = "view",
- CanFocus = true
- };
- view.Enter += (s, e) => viewEnterCount++;
- view.Leave += (s, e) => viewLeaveCount++;
-
- int subviewEnterCount = 0;
- int subviewLeaveCount = 0;
- var subview = new View ()
- {
- Id = "subview",
- CanFocus = true
- };
- subview.Enter += (s, e) => subviewEnterCount++;
- subview.Leave += (s, e) => subviewLeaveCount++;
-
- view.Add (subview);
-
- view.SetFocus ();
-
- Assert.Equal (1, viewEnterCount);
- Assert.Equal (0, viewLeaveCount);
-
- Assert.Equal (1, subviewEnterCount);
- Assert.Equal (0, subviewLeaveCount);
- }
-
- [Fact]
- public void RemoveFocus_SubView_FiresLeave ()
- {
- int viewEnterCount = 0;
- int viewLeaveCount = 0;
- var view = new View ()
- {
- Id = "view",
- CanFocus = true
- };
- view.Enter += (s, e) => viewEnterCount++;
- view.Leave += (s, e) => viewLeaveCount++;
-
- int subviewEnterCount = 0;
- int subviewLeaveCount = 0;
- var subview = new View ()
- {
- Id = "subview",
- CanFocus = true
- };
- subview.Enter += (s, e) => subviewEnterCount++;
- subview.Leave += (s, e) => subviewLeaveCount++;
-
- view.Add (subview);
-
- view.SetFocus ();
-
- view.HasFocus = false;
-
- Assert.Equal (1, viewEnterCount);
- Assert.Equal (1, viewLeaveCount);
-
- Assert.Equal (1, subviewEnterCount);
- Assert.Equal (1, subviewLeaveCount);
-
- view.SetFocus ();
-
- Assert.Equal (2, viewEnterCount);
- Assert.Equal (1, viewLeaveCount);
-
- Assert.Equal (2, subviewEnterCount);
- Assert.Equal (1, subviewLeaveCount);
-
- subview.HasFocus = false;
-
- Assert.Equal (2, viewEnterCount);
- Assert.Equal (2, viewLeaveCount);
-
- Assert.Equal (2, subviewEnterCount);
- Assert.Equal (2, subviewLeaveCount);
- }
-
- [Fact]
- public void SetFocus_CompoundSubView_FiresEnter ()
- {
- int viewEnterCount = 0;
- int viewLeaveCount = 0;
- var view = new View ()
- {
- Id = "view",
- CanFocus = true
- };
- view.Enter += (s, e) => viewEnterCount++;
- view.Leave += (s, e) => viewLeaveCount++;
-
- int subViewEnterCount = 0;
- int subViewLeaveCount = 0;
- var subView = new View ()
- {
- Id = "subView",
- CanFocus = true
- };
- subView.Enter += (s, e) => subViewEnterCount++;
- subView.Leave += (s, e) => subViewLeaveCount++;
-
- int subviewSubView1EnterCount = 0;
- int subviewSubView1LeaveCount = 0;
- var subViewSubView1 = new View ()
- {
- Id = "subViewSubView1",
- CanFocus = false
- };
- subViewSubView1.Enter += (s, e) => subviewSubView1EnterCount++;
- subViewSubView1.Leave += (s, e) => subviewSubView1LeaveCount++;
-
- int subviewSubView2EnterCount = 0;
- int subviewSubView2LeaveCount = 0;
- var subViewSubView2 = new View ()
- {
- Id = "subViewSubView2",
- CanFocus = true
- };
- subViewSubView2.Enter += (s, e) => subviewSubView2EnterCount++;
- subViewSubView2.Leave += (s, e) => subviewSubView2LeaveCount++;
-
- int subviewSubView3EnterCount = 0;
- int subviewSubView3LeaveCount = 0;
- var subViewSubView3 = new View ()
- {
- Id = "subViewSubView3",
- CanFocus = false
- };
- subViewSubView3.Enter += (s, e) => subviewSubView3EnterCount++;
- subViewSubView3.Leave += (s, e) => subviewSubView3LeaveCount++;
-
- subView.Add (subViewSubView1, subViewSubView2, subViewSubView3);
-
- view.Add (subView);
-
- view.SetFocus ();
- Assert.True(view.HasFocus);
- Assert.True (subView.HasFocus);
- Assert.False (subViewSubView1.HasFocus);
- Assert.True (subViewSubView2.HasFocus);
- Assert.False (subViewSubView3.HasFocus);
-
- Assert.Equal (1, viewEnterCount);
- Assert.Equal (0, viewLeaveCount);
-
- Assert.Equal (1, subViewEnterCount);
- Assert.Equal (0, subViewLeaveCount);
-
- Assert.Equal (0, subviewSubView1EnterCount);
- Assert.Equal (0, subviewSubView1LeaveCount);
-
- Assert.Equal (1, subviewSubView2EnterCount);
- Assert.Equal (0, subviewSubView2LeaveCount);
-
- Assert.Equal (0, subviewSubView3EnterCount);
- Assert.Equal (0, subviewSubView3LeaveCount);
- }
-
-
- [Fact]
- public void RemoveFocus_CompoundSubView_FiresLeave ()
- {
- int viewEnterCount = 0;
- int viewLeaveCount = 0;
- var view = new View ()
- {
- Id = "view",
- CanFocus = true
- };
- view.Enter += (s, e) => viewEnterCount++;
- view.Leave += (s, e) => viewLeaveCount++;
-
- int subViewEnterCount = 0;
- int subViewLeaveCount = 0;
- var subView = new View ()
- {
- Id = "subView",
- CanFocus = true
- };
- subView.Enter += (s, e) => subViewEnterCount++;
- subView.Leave += (s, e) => subViewLeaveCount++;
-
- int subviewSubView1EnterCount = 0;
- int subviewSubView1LeaveCount = 0;
- var subViewSubView1 = new View ()
- {
- Id = "subViewSubView1",
- CanFocus = false
- };
- subViewSubView1.Enter += (s, e) => subviewSubView1EnterCount++;
- subViewSubView1.Leave += (s, e) => subviewSubView1LeaveCount++;
-
- int subviewSubView2EnterCount = 0;
- int subviewSubView2LeaveCount = 0;
- var subViewSubView2 = new View ()
- {
- Id = "subViewSubView2",
- CanFocus = true
- };
- subViewSubView2.Enter += (s, e) => subviewSubView2EnterCount++;
- subViewSubView2.Leave += (s, e) => subviewSubView2LeaveCount++;
-
- int subviewSubView3EnterCount = 0;
- int subviewSubView3LeaveCount = 0;
- var subViewSubView3 = new View ()
- {
- Id = "subViewSubView3",
- CanFocus = false
- };
- subViewSubView3.Enter += (s, e) => subviewSubView3EnterCount++;
- subViewSubView3.Leave += (s, e) => subviewSubView3LeaveCount++;
-
- subView.Add (subViewSubView1, subViewSubView2, subViewSubView3);
-
- view.Add (subView);
-
- view.SetFocus ();
- Assert.True (view.HasFocus);
- Assert.True (subView.HasFocus);
- Assert.False (subViewSubView1.HasFocus);
- Assert.True (subViewSubView2.HasFocus);
- Assert.False (subViewSubView3.HasFocus);
-
- view.HasFocus = false;
- Assert.False (view.HasFocus);
- Assert.False (subView.HasFocus);
- Assert.False (subViewSubView1.HasFocus);
- Assert.False (subViewSubView2.HasFocus);
- Assert.False (subViewSubView3.HasFocus);
-
- Assert.Equal (1, viewEnterCount);
- Assert.Equal (1, viewLeaveCount);
-
- Assert.Equal (1, subViewEnterCount);
- Assert.Equal (1, subViewLeaveCount);
-
- Assert.Equal (0, subviewSubView1EnterCount);
- Assert.Equal (0, subviewSubView1LeaveCount);
-
- Assert.Equal (1, subviewSubView2EnterCount);
- Assert.Equal (1, subviewSubView2LeaveCount);
-
- Assert.Equal (0, subviewSubView3EnterCount);
- Assert.Equal (0, subviewSubView3LeaveCount);
- }
-
-
- [Fact]
- public void SetFocus_Peer_LeavesOther ()
- {
- var view = new View ()
- {
- Id = "view",
- CanFocus = true
- };
-
- var subview1 = new View ()
- {
- Id = "subview1",
- CanFocus = true
- };
-
- var subview2 = new View ()
- {
- Id = "subview2",
- CanFocus = true
- };
- view.Add (subview1, subview2);
-
- view.SetFocus ();
- Assert.Equal (subview1, view.Focused);
- Assert.True (subview1.HasFocus);
- Assert.False (subview2.HasFocus);
-
- subview2.SetFocus ();
- Assert.Equal (subview2, view.Focused);
- Assert.True (subview2.HasFocus);
- Assert.False (subview1.HasFocus);
- }
-
- [Fact]
- public void SetFocus_Peer_LeavesOthers_Subviews ()
- {
- var top = new View
- {
- Id = "top",
- CanFocus = true
- };
- var view1 = new View
- {
- Id = "view1",
- CanFocus = true
- };
-
- var subView1 = new View
- {
- Id = "subView1",
- CanFocus = true
- };
-
- view1.Add (subView1);
-
- var subView1SubView1 = new View
- {
- Id = "subView1subView1",
- CanFocus = true
- };
-
- subView1.Add (subView1SubView1);
-
- var view2 = new View
- {
- Id = "view2",
- CanFocus = true
- };
-
- top.Add (view1, view2);
- Assert.False (view1.HasFocus);
- Assert.False (view2.HasFocus);
-
- view1.SetFocus ();
- Assert.True (view1.HasFocus);
- Assert.True (subView1.HasFocus);
- Assert.True (subView1SubView1.HasFocus);
- Assert.Equal (subView1, view1.Focused);
- Assert.Equal (subView1SubView1, subView1.Focused);
-
- view2.SetFocus ();
- Assert.False (view1.HasFocus);
- Assert.True (view2.HasFocus);
- }
-
-
- [Fact]
- public void HasFocus_False_Leave_Invoked ()
- {
- var view = new View ()
- {
- Id = "view",
- CanFocus = true
- };
- Assert.True (view.CanFocus);
- Assert.False (view.HasFocus);
-
- int leaveInvoked = 0;
-
- view.Leave += (s, e) => leaveInvoked++;
-
- view.SetFocus ();
- Assert.True (view.HasFocus);
- Assert.Equal (0, leaveInvoked);
-
- view.HasFocus = false;
- Assert.False (view.HasFocus);
- Assert.Equal (1, leaveInvoked);
- }
-
- [Fact]
- public void HasFocus_False_Leave_Invoked_ForAllSubViews ()
- {
- var view = new View ()
- {
- Id = "view",
- CanFocus = true
- };
-
- var subview = new View ()
- {
- Id = "subview",
- CanFocus = true
- };
- view.Add (subview);
-
- int leaveInvoked = 0;
-
- view.Leave += (s, e) => leaveInvoked++;
- subview.Leave += (s, e) => leaveInvoked++;
-
- view.SetFocus ();
- Assert.True (view.HasFocus);
- Assert.Equal (0, leaveInvoked);
-
- view.HasFocus = false;
- Assert.False (view.HasFocus);
- Assert.False (subview.HasFocus);
- Assert.Equal (2, leaveInvoked);
- }
-
-}
diff --git a/UnitTests/View/Navigation/HasFocusEventTests.cs b/UnitTests/View/Navigation/HasFocusEventTests.cs
new file mode 100644
index 000000000..35a1e23f0
--- /dev/null
+++ b/UnitTests/View/Navigation/HasFocusEventTests.cs
@@ -0,0 +1,378 @@
+using Xunit.Abstractions;
+
+namespace Terminal.Gui.ViewTests;
+
+public class HasFocusEventTests (ITestOutputHelper _output) : TestsAllViews
+{
+ [Fact]
+ public void SetFocus_Raises_HasFocusChanging ()
+ {
+ var nEnter = 0;
+ var nLeave = 0;
+
+ var view = new View
+ {
+ Id = "view",
+ CanFocus = true
+ };
+ view.HasFocusChanging += (s, e) => nEnter++;
+ view.HasFocusChanged += (s, e) => nLeave++;
+
+ Assert.True (view.CanFocus);
+ Assert.False (view.HasFocus);
+
+ view.SetFocus ();
+ Assert.True (view.HasFocus);
+ Assert.Equal (1, nEnter);
+ Assert.Equal (0, nLeave);
+ }
+
+ [Fact]
+ public void RemoveFocus_Raises_HasFocusChanged ()
+ {
+ var nEnter = 0;
+ var nLeave = 0;
+
+ var view = new View
+ {
+ Id = "view",
+ CanFocus = true
+ };
+ view.HasFocusChanging += (s, e) => nEnter++;
+ view.HasFocusChanged += (s, e) => nLeave++;
+
+ Assert.True (view.CanFocus);
+ Assert.False (view.HasFocus);
+
+ view.SetFocus ();
+ Assert.True (view.HasFocus);
+ Assert.Equal (1, nEnter);
+ Assert.Equal (0, nLeave);
+
+ view.HasFocus = false;
+ Assert.Equal (1, nEnter);
+ Assert.Equal (1, nLeave);
+ }
+
+ [Fact]
+ public void SetFocus_SubView_SetFocus_Raises_HasFocusChanging ()
+ {
+ var viewEnterCount = 0;
+ var viewLeaveCount = 0;
+
+ var view = new View
+ {
+ Id = "view",
+ CanFocus = true
+ };
+ view.HasFocusChanging += (s, e) => viewEnterCount++;
+ view.HasFocusChanged += (s, e) => viewLeaveCount++;
+
+ var subviewEnterCount = 0;
+ var subviewLeaveCount = 0;
+
+ var subview = new View
+ {
+ Id = "subview",
+ CanFocus = true
+ };
+ subview.HasFocusChanging += (s, e) => subviewEnterCount++;
+ subview.HasFocusChanged += (s, e) => subviewLeaveCount++;
+
+ view.Add (subview);
+
+ view.SetFocus ();
+
+ Assert.Equal (1, viewEnterCount);
+ Assert.Equal (0, viewLeaveCount);
+
+ Assert.Equal (1, subviewEnterCount);
+ Assert.Equal (0, subviewLeaveCount);
+ }
+
+ [Fact]
+ public void RemoveFocus_SubView_Raises_HasFocusChanged ()
+ {
+ var viewEnterCount = 0;
+ var viewLeaveCount = 0;
+
+ var view = new View
+ {
+ Id = "view",
+ CanFocus = true
+ };
+ view.HasFocusChanging += (s, e) => viewEnterCount++;
+ view.HasFocusChanged += (s, e) => viewLeaveCount++;
+
+ var subviewEnterCount = 0;
+ var subviewLeaveCount = 0;
+
+ var subview = new View
+ {
+ Id = "subview",
+ CanFocus = true
+ };
+ subview.HasFocusChanging += (s, e) => subviewEnterCount++;
+ subview.HasFocusChanged += (s, e) => subviewLeaveCount++;
+
+ view.Add (subview);
+
+ view.SetFocus ();
+
+ view.HasFocus = false;
+
+ Assert.Equal (1, viewEnterCount);
+ Assert.Equal (1, viewLeaveCount);
+
+ Assert.Equal (1, subviewEnterCount);
+ Assert.Equal (1, subviewLeaveCount);
+
+ view.SetFocus ();
+
+ Assert.Equal (2, viewEnterCount);
+ Assert.Equal (1, viewLeaveCount);
+
+ Assert.Equal (2, subviewEnterCount);
+ Assert.Equal (1, subviewLeaveCount);
+
+ subview.HasFocus = false;
+
+ Assert.Equal (2, viewEnterCount);
+ Assert.Equal (2, viewLeaveCount);
+
+ Assert.Equal (2, subviewEnterCount);
+ Assert.Equal (2, subviewLeaveCount);
+ }
+
+ [Fact]
+ public void SetFocus_CompoundSubView_Raises_HasFocusChanging ()
+ {
+ var viewEnterCount = 0;
+ var viewLeaveCount = 0;
+
+ var view = new View
+ {
+ Id = "view",
+ CanFocus = true
+ };
+ view.HasFocusChanging += (s, e) => viewEnterCount++;
+ view.HasFocusChanged += (s, e) => viewLeaveCount++;
+
+ var subViewEnterCount = 0;
+ var subViewLeaveCount = 0;
+
+ var subView = new View
+ {
+ Id = "subView",
+ CanFocus = true
+ };
+ subView.HasFocusChanging += (s, e) => subViewEnterCount++;
+ subView.HasFocusChanged += (s, e) => subViewLeaveCount++;
+
+ var subviewSubView1EnterCount = 0;
+ var subviewSubView1LeaveCount = 0;
+
+ var subViewSubView1 = new View
+ {
+ Id = "subViewSubView1",
+ CanFocus = false
+ };
+ subViewSubView1.HasFocusChanging += (s, e) => subviewSubView1EnterCount++;
+ subViewSubView1.HasFocusChanged += (s, e) => subviewSubView1LeaveCount++;
+
+ var subviewSubView2EnterCount = 0;
+ var subviewSubView2LeaveCount = 0;
+
+ var subViewSubView2 = new View
+ {
+ Id = "subViewSubView2",
+ CanFocus = true
+ };
+ subViewSubView2.HasFocusChanging += (s, e) => subviewSubView2EnterCount++;
+ subViewSubView2.HasFocusChanged += (s, e) => subviewSubView2LeaveCount++;
+
+ var subviewSubView3EnterCount = 0;
+ var subviewSubView3LeaveCount = 0;
+
+ var subViewSubView3 = new View
+ {
+ Id = "subViewSubView3",
+ CanFocus = false
+ };
+ subViewSubView3.HasFocusChanging += (s, e) => subviewSubView3EnterCount++;
+ subViewSubView3.HasFocusChanged += (s, e) => subviewSubView3LeaveCount++;
+
+ subView.Add (subViewSubView1, subViewSubView2, subViewSubView3);
+
+ view.Add (subView);
+
+ view.SetFocus ();
+ Assert.True (view.HasFocus);
+ Assert.True (subView.HasFocus);
+ Assert.False (subViewSubView1.HasFocus);
+ Assert.True (subViewSubView2.HasFocus);
+ Assert.False (subViewSubView3.HasFocus);
+
+ Assert.Equal (1, viewEnterCount);
+ Assert.Equal (0, viewLeaveCount);
+
+ Assert.Equal (1, subViewEnterCount);
+ Assert.Equal (0, subViewLeaveCount);
+
+ Assert.Equal (0, subviewSubView1EnterCount);
+ Assert.Equal (0, subviewSubView1LeaveCount);
+
+ Assert.Equal (1, subviewSubView2EnterCount);
+ Assert.Equal (0, subviewSubView2LeaveCount);
+
+ Assert.Equal (0, subviewSubView3EnterCount);
+ Assert.Equal (0, subviewSubView3LeaveCount);
+ }
+
+ [Fact]
+ public void RemoveFocus_CompoundSubView_Raises_HasFocusChanged ()
+ {
+ var viewEnterCount = 0;
+ var viewLeaveCount = 0;
+
+ var view = new View
+ {
+ Id = "view",
+ CanFocus = true
+ };
+ view.HasFocusChanging += (s, e) => viewEnterCount++;
+ view.HasFocusChanged += (s, e) => viewLeaveCount++;
+
+ var subViewEnterCount = 0;
+ var subViewLeaveCount = 0;
+
+ var subView = new View
+ {
+ Id = "subView",
+ CanFocus = true
+ };
+ subView.HasFocusChanging += (s, e) => subViewEnterCount++;
+ subView.HasFocusChanged += (s, e) => subViewLeaveCount++;
+
+ var subviewSubView1EnterCount = 0;
+ var subviewSubView1LeaveCount = 0;
+
+ var subViewSubView1 = new View
+ {
+ Id = "subViewSubView1",
+ CanFocus = false
+ };
+ subViewSubView1.HasFocusChanging += (s, e) => subviewSubView1EnterCount++;
+ subViewSubView1.HasFocusChanged += (s, e) => subviewSubView1LeaveCount++;
+
+ var subviewSubView2EnterCount = 0;
+ var subviewSubView2LeaveCount = 0;
+
+ var subViewSubView2 = new View
+ {
+ Id = "subViewSubView2",
+ CanFocus = true
+ };
+ subViewSubView2.HasFocusChanging += (s, e) => subviewSubView2EnterCount++;
+ subViewSubView2.HasFocusChanged += (s, e) => subviewSubView2LeaveCount++;
+
+ var subviewSubView3EnterCount = 0;
+ var subviewSubView3LeaveCount = 0;
+
+ var subViewSubView3 = new View
+ {
+ Id = "subViewSubView3",
+ CanFocus = false
+ };
+ subViewSubView3.HasFocusChanging += (s, e) => subviewSubView3EnterCount++;
+ subViewSubView3.HasFocusChanged += (s, e) => subviewSubView3LeaveCount++;
+
+ subView.Add (subViewSubView1, subViewSubView2, subViewSubView3);
+
+ view.Add (subView);
+
+ view.SetFocus ();
+ Assert.True (view.HasFocus);
+ Assert.True (subView.HasFocus);
+ Assert.False (subViewSubView1.HasFocus);
+ Assert.True (subViewSubView2.HasFocus);
+ Assert.False (subViewSubView3.HasFocus);
+
+ view.HasFocus = false;
+ Assert.False (view.HasFocus);
+ Assert.False (subView.HasFocus);
+ Assert.False (subViewSubView1.HasFocus);
+ Assert.False (subViewSubView2.HasFocus);
+ Assert.False (subViewSubView3.HasFocus);
+
+ Assert.Equal (1, viewEnterCount);
+ Assert.Equal (1, viewLeaveCount);
+
+ Assert.Equal (1, subViewEnterCount);
+ Assert.Equal (1, subViewLeaveCount);
+
+ Assert.Equal (0, subviewSubView1EnterCount);
+ Assert.Equal (0, subviewSubView1LeaveCount);
+
+ Assert.Equal (1, subviewSubView2EnterCount);
+ Assert.Equal (1, subviewSubView2LeaveCount);
+
+ Assert.Equal (0, subviewSubView3EnterCount);
+ Assert.Equal (0, subviewSubView3LeaveCount);
+ }
+
+ [Fact]
+ public void HasFocus_False_Leave_Raised ()
+ {
+ var view = new View
+ {
+ Id = "view",
+ CanFocus = true
+ };
+ Assert.True (view.CanFocus);
+ Assert.False (view.HasFocus);
+
+ var leaveInvoked = 0;
+
+ view.HasFocusChanged += (s, e) => leaveInvoked++;
+
+ view.SetFocus ();
+ Assert.True (view.HasFocus);
+ Assert.Equal (0, leaveInvoked);
+
+ view.HasFocus = false;
+ Assert.False (view.HasFocus);
+ Assert.Equal (1, leaveInvoked);
+ }
+
+ [Fact]
+ public void HasFocus_False_Leave_Raised_ForAllSubViews ()
+ {
+ var view = new View
+ {
+ Id = "view",
+ CanFocus = true
+ };
+
+ var subview = new View
+ {
+ Id = "subview",
+ CanFocus = true
+ };
+ view.Add (subview);
+
+ var leaveInvoked = 0;
+
+ view.HasFocusChanged += (s, e) => leaveInvoked++;
+ subview.HasFocusChanged += (s, e) => leaveInvoked++;
+
+ view.SetFocus ();
+ Assert.True (view.HasFocus);
+ Assert.Equal (0, leaveInvoked);
+
+ view.HasFocus = false;
+ Assert.False (view.HasFocus);
+ Assert.False (subview.HasFocus);
+ Assert.Equal (2, leaveInvoked);
+ }
+}
diff --git a/UnitTests/View/Navigation/NavigationTests.cs b/UnitTests/View/Navigation/NavigationTests.cs
index f96712ba7..297de677c 100644
--- a/UnitTests/View/Navigation/NavigationTests.cs
+++ b/UnitTests/View/Navigation/NavigationTests.cs
@@ -138,8 +138,8 @@ public class NavigationTests (ITestOutputHelper _output) : TestsAllViews
var nEnter = 0;
var nLeave = 0;
- view.Enter += (s, e) => nEnter++;
- view.Leave += (s, e) => nLeave++;
+ view.HasFocusChanging += (s, e) => nEnter++;
+ view.HasFocusChanged += (s, e) => nLeave++;
top.Add (view, otherView);
Assert.False (view.HasFocus);
@@ -294,8 +294,8 @@ public class NavigationTests (ITestOutputHelper _output) : TestsAllViews
var nEnter = 0;
var nLeave = 0;
- view.Enter += (s, e) => nEnter++;
- view.Leave += (s, e) => nLeave++;
+ view.HasFocusChanging += (s, e) => nEnter++;
+ view.HasFocusChanged += (s, e) => nLeave++;
top.Add (view, otherView);
Application.Begin (top);
@@ -409,25 +409,25 @@ public class NavigationTests (ITestOutputHelper _output) : TestsAllViews
Application.Current.Add (frm);
Application.Current.SetFocus ();
- Assert.Equal (winSubview, Application.Current.GetMostFocused ());
+ Assert.Equal (winSubview, Application.Current.MostFocused);
Application.OnKeyDown (Key.Tab); // Move to the next TabStop. There is none. So we should stay.
- Assert.Equal (winSubview, Application.Current.GetMostFocused ());
+ Assert.Equal (winSubview, Application.Current.MostFocused);
Application.OnKeyDown (Key.F6);
- Assert.Equal (frmSubview, Application.Current.GetMostFocused ());
+ Assert.Equal (frmSubview, Application.Current.MostFocused);
Application.OnKeyDown (Key.Tab);
- Assert.Equal (frmSubview, Application.Current.GetMostFocused ());
+ Assert.Equal (frmSubview, Application.Current.MostFocused);
Application.OnKeyDown (Key.F6);
- Assert.Equal (winSubview, Application.Current.GetMostFocused ());
+ Assert.Equal (winSubview, Application.Current.MostFocused);
Application.OnKeyDown (Key.F6.WithShift);
- Assert.Equal (frmSubview, Application.Current.GetMostFocused ());
+ Assert.Equal (frmSubview, Application.Current.MostFocused);
Application.OnKeyDown (Key.F6.WithShift);
- Assert.Equal (winSubview, Application.Current.GetMostFocused ());
+ Assert.Equal (winSubview, Application.Current.MostFocused);
Application.Current.Dispose ();
}
@@ -451,7 +451,7 @@ public class NavigationTests (ITestOutputHelper _output) : TestsAllViews
View view3 = null;
var removed = false;
- view2.Enter += (s, e) =>
+ view2.HasFocusChanging += (s, e) =>
{
if (!removed)
{
@@ -463,7 +463,7 @@ public class NavigationTests (ITestOutputHelper _output) : TestsAllViews
}
};
- view2.Leave += (s, e) =>
+ view2.HasFocusChanged += (s, e) =>
{
Application.Current.Remove (view3);
view3.Dispose ();
@@ -503,7 +503,7 @@ public class NavigationTests (ITestOutputHelper _output) : TestsAllViews
Assert.False (view.HasFocus);
view.SetFocus ();
Assert.True (view.HasFocus);
- Assert.Null (view.GetMostFocused ());
+ Assert.Null (view.MostFocused);
}
[Fact]
@@ -526,7 +526,7 @@ public class NavigationTests (ITestOutputHelper _output) : TestsAllViews
view.SetFocus ();
Assert.True (view.HasFocus);
Assert.True (subview.HasFocus);
- Assert.Equal (subview, view.GetMostFocused ());
+ Assert.Equal (subview, view.MostFocused);
var subview2 = new View ()
{
@@ -535,7 +535,7 @@ public class NavigationTests (ITestOutputHelper _output) : TestsAllViews
};
view.Add (subview2);
- Assert.Equal (subview2, view.GetMostFocused ());
+ Assert.Equal (subview2, view.MostFocused);
}
// [Fact]
diff --git a/UnitTests/View/ViewTests.cs b/UnitTests/View/ViewTests.cs
index 08799d0e2..a2b4af816 100644
--- a/UnitTests/View/ViewTests.cs
+++ b/UnitTests/View/ViewTests.cs
@@ -777,7 +777,7 @@ At 0,0
Assert.False (r.WantContinuousButtonPressed);
Assert.False (r.WantMousePositionReports);
Assert.Null (r.SuperView);
- Assert.Null (r.GetMostFocused ());
+ Assert.Null (r.MostFocused);
Assert.Equal (TextDirection.LeftRight_TopBottom, r.TextDirection);
r.Dispose ();
@@ -801,7 +801,7 @@ At 0,0
Assert.False (r.WantContinuousButtonPressed);
Assert.False (r.WantMousePositionReports);
Assert.Null (r.SuperView);
- Assert.Null (r.GetMostFocused ());
+ Assert.Null (r.MostFocused);
Assert.Equal (TextDirection.LeftRight_TopBottom, r.TextDirection);
r.Dispose ();
@@ -825,7 +825,7 @@ At 0,0
Assert.False (r.WantContinuousButtonPressed);
Assert.False (r.WantMousePositionReports);
Assert.Null (r.SuperView);
- Assert.Null (r.GetMostFocused ());
+ Assert.Null (r.MostFocused);
Assert.Equal (TextDirection.LeftRight_TopBottom, r.TextDirection);
r.Dispose ();
@@ -858,7 +858,7 @@ At 0,0
Assert.False (r.WantContinuousButtonPressed);
Assert.False (r.WantMousePositionReports);
Assert.Null (r.SuperView);
- Assert.Null (r.GetMostFocused ());
+ Assert.Null (r.MostFocused);
Assert.Equal (TextDirection.TopBottom_LeftRight, r.TextDirection);
r.Dispose ();
}
@@ -1083,7 +1083,7 @@ At 0,0
Assert.True (RunesCount () == 0);
win.Visible = true;
- win.FocusDeepest (null, NavigationDirection.Forward);
+ win.FocusDeepest (NavigationDirection.Forward, null);
Assert.True (button.HasFocus);
Assert.True (win.HasFocus);
top.Draw ();
diff --git a/UnitTests/Views/OverlappedTests.cs b/UnitTests/Views/OverlappedTests.cs
index 557106d26..c0f118fa1 100644
--- a/UnitTests/Views/OverlappedTests.cs
+++ b/UnitTests/Views/OverlappedTests.cs
@@ -1072,8 +1072,8 @@ public class OverlappedTests
Assert.True (win1.IsCurrentTop);
Assert.True (ApplicationOverlapped.IsOverlapped(win1));
Assert.Null (top.Focused);
- Assert.Null (top.GetMostFocused ());
- Assert.Equal (tf1W1, win1.GetMostFocused ());
+ Assert.Null (top.MostFocused);
+ Assert.Equal (tf1W1, win1.MostFocused);
Assert.True (ApplicationOverlapped.IsOverlapped(win1));
Assert.Single (ApplicationOverlapped.OverlappedChildren!);
@@ -1086,8 +1086,8 @@ public class OverlappedTests
Assert.True (win2.IsCurrentTop);
Assert.True (ApplicationOverlapped.IsOverlapped(win2));
Assert.Null (top.Focused);
- Assert.Null (top.GetMostFocused ());
- Assert.Equal (tf1W2, win2.GetMostFocused ());
+ Assert.Null (top.MostFocused);
+ Assert.Equal (tf1W2, win2.MostFocused);
Assert.Equal (2, ApplicationOverlapped.OverlappedChildren!.Count);
ApplicationOverlapped.MoveToOverlappedChild (win1);
@@ -1109,7 +1109,7 @@ public class OverlappedTests
Assert.True (Application.OnKeyDown (Key.F5)); // refresh
Assert.True (win1.IsCurrentTop);
- Assert.Equal (tvW1, win1.GetMostFocused ());
+ Assert.Equal (tvW1, win1.MostFocused);
Assert.True (Application.OnKeyDown (Key.Tab));
Assert.Equal ($"\tFirst line Win1{Environment.NewLine}Second line Win1", tvW1.Text);
@@ -1122,22 +1122,22 @@ public class OverlappedTests
Assert.True (Application.OnKeyDown (Key.F6.WithShift)); // move back to win1
Assert.Equal (win1, ApplicationOverlapped.OverlappedChildren [0]);
- Assert.Equal (tvW1, win1.GetMostFocused ());
+ Assert.Equal (tvW1, win1.MostFocused);
Assert.True (Application.OnKeyDown (Key.Tab)); // text view eats tab
Assert.Equal (win1, ApplicationOverlapped.OverlappedChildren [0]);
- Assert.Equal (tvW1, win1.GetMostFocused ());
+ Assert.Equal (tvW1, win1.MostFocused);
tvW1.AllowsTab = false;
Assert.True (Application.OnKeyDown (Key.Tab)); // text view eats tab
Assert.Equal (win1, ApplicationOverlapped.OverlappedChildren [0]);
- Assert.Equal (tf2W1, win1.GetMostFocused ());
+ Assert.Equal (tf2W1, win1.MostFocused);
Assert.True (Application.OnKeyDown (Key.CursorRight));
Assert.Equal (win1, ApplicationOverlapped.OverlappedChildren [0]);
- Assert.Equal (tf2W1, win1.GetMostFocused ());
+ Assert.Equal (tf2W1, win1.MostFocused);
Assert.True (Application.OnKeyDown (Key.CursorDown));
Assert.Equal (win1, ApplicationOverlapped.OverlappedChildren [0]);
- Assert.Equal (tf1W1, win1.GetMostFocused ());
+ Assert.Equal (tf1W1, win1.MostFocused);
#if UNIX_KEY_BINDINGS
Assert.True (ApplicationOverlapped.OverlappedChildren [0].ProcessKeyDown (new (Key.I.WithCtrl)));
Assert.Equal (win1, ApplicationOverlapped.OverlappedChildren [0]);
@@ -1145,50 +1145,50 @@ public class OverlappedTests
#endif
Assert.True (Application.OnKeyDown (Key.Tab));
Assert.Equal (win1, ApplicationOverlapped.OverlappedChildren [0]);
- Assert.Equal (tvW1, win1.GetMostFocused ());
+ Assert.Equal (tvW1, win1.MostFocused);
Assert.True (Application.OnKeyDown (Key.CursorLeft)); // The view to the left of tvW1 is tf2W1, but tvW1 is still focused and eats cursor keys
Assert.Equal (win1, ApplicationOverlapped.OverlappedChildren [0]);
- Assert.Equal (tvW1, win1.GetMostFocused ());
+ Assert.Equal (tvW1, win1.MostFocused);
Assert.True (Application.OnKeyDown (Key.CursorUp));
Assert.Equal (win1, ApplicationOverlapped.OverlappedChildren [0]);
- Assert.Equal (tvW1, win1.GetMostFocused ());
+ Assert.Equal (tvW1, win1.MostFocused);
Assert.True (Application.OnKeyDown (Key.Tab));
Assert.Equal (win1, ApplicationOverlapped.OverlappedChildren [0]);
- Assert.Equal (tf2W1, win1.GetMostFocused ());
+ Assert.Equal (tf2W1, win1.MostFocused);
Assert.True (Application.OnKeyDown (Key.F6)); // Move to win2
Assert.Equal (win2, ApplicationOverlapped.OverlappedChildren [0]);
- Assert.Equal (tf1W2, win2.GetMostFocused ());
+ Assert.Equal (tf1W2, win2.MostFocused);
tf2W2.SetFocus ();
Assert.True (tf2W2.HasFocus);
Assert.True (Application.OnKeyDown (Key.F6.WithShift));
Assert.Equal (win1, ApplicationOverlapped.OverlappedChildren [0]);
- Assert.Equal (tf2W1, win1.GetMostFocused ());
+ Assert.Equal (tf2W1, win1.MostFocused);
Assert.True (Application.OnKeyDown (Application.NextTabGroupKey));
Assert.Equal (win2, ApplicationOverlapped.OverlappedChildren [0]);
- Assert.Equal (tf2W2, win2.GetMostFocused ());
+ Assert.Equal (tf2W2, win2.MostFocused);
Assert.True (Application.OnKeyDown (Application.PrevTabGroupKey));
Assert.Equal (win1, ApplicationOverlapped.OverlappedChildren [0]);
- Assert.Equal (tf2W1, win1.GetMostFocused ());
+ Assert.Equal (tf2W1, win1.MostFocused);
Assert.True (Application.OnKeyDown (Key.CursorDown));
Assert.Equal (win1, ApplicationOverlapped.OverlappedChildren [0]);
- Assert.Equal (tf1W1, win1.GetMostFocused ());
+ Assert.Equal (tf1W1, win1.MostFocused);
#if UNIX_KEY_BINDINGS
Assert.True (Application.OnKeyDown (new (Key.B.WithCtrl)));
#else
Assert.True (Application.OnKeyDown (Key.CursorLeft));
#endif
Assert.Equal (win1, ApplicationOverlapped.OverlappedChildren [0]);
- Assert.Equal (tf1W1, win1.GetMostFocused ());
+ Assert.Equal (tf1W1, win1.MostFocused);
Assert.True (Application.OnKeyDown (Key.CursorDown));
Assert.Equal (win1, ApplicationOverlapped.OverlappedChildren [0]);
- Assert.Equal (tvW1, win1.GetMostFocused ());
+ Assert.Equal (tvW1, win1.MostFocused);
Assert.Equal (Point.Empty, tvW1.CursorPosition);
Assert.True (Application.OnKeyDown (Key.End.WithCtrl));
Assert.Equal (win1, ApplicationOverlapped.OverlappedChildren [0]);
- Assert.Equal (tvW1, win1.GetMostFocused ());
+ Assert.Equal (tvW1, win1.MostFocused);
Assert.Equal (new (16, 1), tvW1.CursorPosition); // Last position of the text
#if UNIX_KEY_BINDINGS
Assert.True (Application.OnKeyDown (new (Key.F.WithCtrl)));
@@ -1196,7 +1196,7 @@ public class OverlappedTests
Assert.True (Application.OnKeyDown (Key.CursorRight)); // should move to next view w/ in Group (tf2W1)
#endif
Assert.Equal (win1, ApplicationOverlapped.OverlappedChildren [0]);
- Assert.Equal (tf2W1, win1.GetMostFocused ());
+ Assert.Equal (tf2W1, win1.MostFocused);
#if UNIX_KEY_BINDINGS
Assert.True (ApplicationOverlapped.OverlappedChildren [0].ProcessKeyDown (new (Key.L.WithCtrl)));
@@ -1228,7 +1228,7 @@ public class OverlappedTests
Application.Current = current;
Assert.True (current.HasFocus);
Assert.Equal (superView.Focused, current);
- Assert.Equal (superView.GetMostFocused (), current);
+ Assert.Equal (superView.MostFocused, current);
// Act
ApplicationOverlapped.SetFocusToNextViewWithWrap (Application.Current.SuperView.TabIndexes, NavigationDirection.Forward);
@@ -1277,14 +1277,14 @@ public class OverlappedTests
{
public bool IsFocused { get; private set; }
- protected override bool OnEnter (View view)
+ protected override bool OnHasFocusChanging (View view)
{
IsFocused = true;
return false;
}
- protected override void OnLeave (View view) { IsFocused = false; }
+ protected override void OnHasFocusChanged (View view) { IsFocused = false; }
}
private class TestView : View
@@ -1295,14 +1295,14 @@ public class OverlappedTests
}
public bool IsFocused { get; private set; }
- protected override bool OnEnter (View view)
+ protected override bool OnHasFocusChanging (View view)
{
IsFocused = true;
return false; // don't cancel
}
- protected override void OnLeave (View view)
+ protected override void OnHasFocusChanged (View view)
{
IsFocused = false;
}
diff --git a/UnitTests/Views/ScrollViewTests.cs b/UnitTests/Views/ScrollViewTests.cs
index 7ec4efed8..41e9def18 100644
--- a/UnitTests/Views/ScrollViewTests.cs
+++ b/UnitTests/Views/ScrollViewTests.cs
@@ -1119,7 +1119,7 @@ public class ScrollViewTests (ITestOutputHelper output)
CanFocus = true;
}
- protected override bool OnEnter (View view)
+ protected override bool OnHasFocusChanging (View view)
{
Border.LineStyle = LineStyle.None;
Border.Thickness = new (0);
@@ -1129,7 +1129,7 @@ public class ScrollViewTests (ITestOutputHelper output)
return false; // don't cancel
}
- protected override void OnLeave (View view)
+ protected override void OnHasFocusChanged (View view)
{
Border.LineStyle = LineStyle.Single;
Border.Thickness = new (1);
diff --git a/UnitTests/Views/TabViewTests.cs b/UnitTests/Views/TabViewTests.cs
index d84372f95..f8f255434 100644
--- a/UnitTests/Views/TabViewTests.cs
+++ b/UnitTests/Views/TabViewTests.cs
@@ -394,8 +394,8 @@ public class TabViewTests (ITestOutputHelper output)
// Is the selected tab view hosting focused
Assert.Equal (tab1, tv.SelectedTab);
Assert.Equal (tv, top.Focused);
- Assert.Equal (tv.GetMostFocused (), top.Focused.GetMostFocused ());
- Assert.Equal (tv.SelectedTab.View, top.Focused.GetMostFocused ());
+ Assert.Equal (tv.MostFocused, top.Focused.MostFocused);
+ Assert.Equal (tv.SelectedTab.View, top.Focused.MostFocused);
// Press the cursor up key to focus the selected tab
Application.OnKeyDown (Key.CursorUp);
@@ -404,7 +404,7 @@ public class TabViewTests (ITestOutputHelper output)
// Is the selected tab focused
Assert.Equal (tab1, tv.SelectedTab);
Assert.Equal (tv, top.Focused);
- Assert.Equal (tv.GetMostFocused (), top.Focused.GetMostFocused ());
+ Assert.Equal (tv.MostFocused, top.Focused.MostFocused);
Tab oldChanged = null;
Tab newChanged = null;
@@ -422,12 +422,12 @@ public class TabViewTests (ITestOutputHelper output)
Assert.Equal (tab2, newChanged);
Assert.Equal (tab2, tv.SelectedTab);
Assert.Equal (tv, top.Focused);
- Assert.Equal (tv.GetMostFocused (), top.Focused.GetMostFocused ());
+ Assert.Equal (tv.MostFocused, top.Focused.MostFocused);
// Press the cursor down key. Since the selected tab has no focusable views, the focus should move to the next view in the toplevel
Application.OnKeyDown (Key.CursorDown);
Assert.Equal (tab2, tv.SelectedTab);
- Assert.Equal (btn, top.GetMostFocused ());
+ Assert.Equal (btn, top.MostFocused);
// Add a focusable subview to Selected Tab
var btnSubView = new View ()
@@ -441,26 +441,26 @@ public class TabViewTests (ITestOutputHelper output)
// Press cursor up. Should focus the subview in the selected tab.
Application.OnKeyDown (Key.CursorUp);
Assert.Equal (tab2, tv.SelectedTab);
- Assert.Equal (btnSubView, top.GetMostFocused ());
+ Assert.Equal (btnSubView, top.MostFocused);
Application.OnKeyDown (Key.CursorUp);
- Assert.Equal (tab2, top.GetMostFocused ());
+ Assert.Equal (tab2, top.MostFocused);
// Press the cursor down key twice.
Application.OnKeyDown (Key.CursorDown);
Application.OnKeyDown (Key.CursorDown);
- Assert.Equal (btn, top.GetMostFocused ());
+ Assert.Equal (btn, top.MostFocused);
// Press the cursor down key again will focus next view in the toplevel, whic is the TabView
Application.OnKeyDown (Key.CursorDown);
Assert.Equal (tab2, tv.SelectedTab);
Assert.Equal (tv, top.Focused);
- Assert.Equal (tab1, tv.GetMostFocused ());
+ Assert.Equal (tab1, tv.MostFocused);
// Press the cursor down key to focus the selected tab view hosting again
Application.OnKeyDown (Key.CursorDown);
Assert.Equal (tab2, tv.SelectedTab);
- Assert.Equal (btnSubView, top.GetMostFocused ());
+ Assert.Equal (btnSubView, top.MostFocused);
// Press the cursor up key to focus the selected tab
Application.OnKeyDown (Key.CursorUp);
@@ -469,7 +469,7 @@ public class TabViewTests (ITestOutputHelper output)
// Is the selected tab focused
Assert.Equal (tab2, tv.SelectedTab);
Assert.Equal (tv, top.Focused);
- Assert.Equal (tv.GetMostFocused (), top.Focused.GetMostFocused ());
+ Assert.Equal (tv.MostFocused, top.Focused.MostFocused);
// Press the cursor left key to select the previous tab
Application.OnKeyDown (Key.CursorLeft);
@@ -478,7 +478,7 @@ public class TabViewTests (ITestOutputHelper output)
Assert.Equal (tab1, newChanged);
Assert.Equal (tab1, tv.SelectedTab);
Assert.Equal (tv, top.Focused);
- Assert.Equal (tv.GetMostFocused (), top.Focused.GetMostFocused ());
+ Assert.Equal (tv.MostFocused, top.Focused.MostFocused);
// Press the end key to select the last tab
Application.OnKeyDown (Key.End);
@@ -487,7 +487,7 @@ public class TabViewTests (ITestOutputHelper output)
Assert.Equal (tab2, newChanged);
Assert.Equal (tab2, tv.SelectedTab);
Assert.Equal (tv, top.Focused);
- Assert.Equal (tv.GetMostFocused (), top.Focused.GetMostFocused ());
+ Assert.Equal (tv.MostFocused, top.Focused.MostFocused);
// Press the home key to select the first tab
Application.OnKeyDown (Key.Home);
@@ -496,7 +496,7 @@ public class TabViewTests (ITestOutputHelper output)
Assert.Equal (tab1, newChanged);
Assert.Equal (tab1, tv.SelectedTab);
Assert.Equal (tv, top.Focused);
- Assert.Equal (tv.GetMostFocused (), top.Focused.GetMostFocused ());
+ Assert.Equal (tv.MostFocused, top.Focused.MostFocused);
// Press the page down key to select the next set of tabs
Application.OnKeyDown (Key.PageDown);
@@ -505,7 +505,7 @@ public class TabViewTests (ITestOutputHelper output)
Assert.Equal (tab2, newChanged);
Assert.Equal (tab2, tv.SelectedTab);
Assert.Equal (tv, top.Focused);
- Assert.Equal (tv.GetMostFocused (), top.Focused.GetMostFocused ());
+ Assert.Equal (tv.MostFocused, top.Focused.MostFocused);
// Press the page up key to select the previous set of tabs
Application.OnKeyDown (Key.PageUp);
@@ -514,7 +514,7 @@ public class TabViewTests (ITestOutputHelper output)
Assert.Equal (tab1, newChanged);
Assert.Equal (tab1, tv.SelectedTab);
Assert.Equal (tv, top.Focused);
- Assert.Equal (tv.GetMostFocused (), top.Focused.GetMostFocused ());
+ Assert.Equal (tv.MostFocused, top.Focused.MostFocused);
top.Dispose ();
}
diff --git a/UnitTests/Views/ToplevelTests.cs b/UnitTests/Views/ToplevelTests.cs
index ba40cd6eb..98c0aa150 100644
--- a/UnitTests/Views/ToplevelTests.cs
+++ b/UnitTests/Views/ToplevelTests.cs
@@ -467,7 +467,7 @@ public partial class ToplevelTests (ITestOutputHelper output)
Assert.Equal (new (0, 0, 40, 25), win1.Frame);
Assert.Equal (new (41, 0, 40, 25), win2.Frame);
Assert.Equal (win1, top.Focused);
- Assert.Equal (tf1W1, top.GetMostFocused ());
+ Assert.Equal (tf1W1, top.MostFocused);
Assert.True (isRunning);
Assert.True (Application.OnKeyDown (Application.QuitKey));
@@ -478,35 +478,35 @@ public partial class ToplevelTests (ITestOutputHelper output)
Assert.True (Application.OnKeyDown (Key.Tab));
Assert.Equal (win1, top.Focused);
- Assert.Equal (tvW1, top.GetMostFocused ());
+ Assert.Equal (tvW1, top.MostFocused);
Assert.True (Application.OnKeyDown (Key.Tab));
Assert.Equal ($"\tFirst line Win1{Environment.NewLine}Second line Win1", tvW1.Text);
Assert.True (Application.OnKeyDown (Key.Tab.WithShift));
Assert.Equal ($"First line Win1{Environment.NewLine}Second line Win1", tvW1.Text);
- var prevMostFocusedSubview = top.GetMostFocused ();
+ var prevMostFocusedSubview = top.MostFocused;
Assert.True (Application.OnKeyDown (Key.F6)); // move to next TabGroup (win2)
Assert.Equal (win2, top.Focused);
Assert.True (Application.OnKeyDown (Key.F6.WithShift)); // move to prev TabGroup (win1)
Assert.Equal (win1, top.Focused);
- Assert.Equal (tf2W1, top.GetMostFocused ()); // BUGBUG: Should be prevMostFocusedSubview - We need to cache the last focused view in the TabGroup somehow
+ Assert.Equal (tf2W1, top.MostFocused); // BUGBUG: Should be prevMostFocusedSubview - We need to cache the last focused view in the TabGroup somehow
prevMostFocusedSubview.SetFocus ();
- Assert.Equal (tvW1, top.GetMostFocused ());
+ Assert.Equal (tvW1, top.MostFocused);
tf2W1.SetFocus ();
Assert.True (Application.OnKeyDown (Key.Tab)); // tf2W1 is last subview in win1 - tabbing should take us to first subview of win1
Assert.Equal (win1, top.Focused);
- Assert.Equal (tf1W1, top.GetMostFocused ());
+ Assert.Equal (tf1W1, top.MostFocused);
Assert.True (Application.OnKeyDown (Key.CursorRight)); // move char to right in tf1W1. We're at last char so nav to next view
Assert.Equal (win1, top.Focused);
- Assert.Equal (tvW1, top.GetMostFocused ());
+ Assert.Equal (tvW1, top.MostFocused);
Assert.True (Application.OnKeyDown (Key.CursorDown)); // move down to next view (tvW1)
Assert.Equal (win1, top.Focused);
- Assert.Equal (tvW1, top.GetMostFocused ());
+ Assert.Equal (tvW1, top.MostFocused);
#if UNIX_KEY_BINDINGS
Assert.True (Application.OnKeyDown (new (Key.I.WithCtrl)));
Assert.Equal (win1, top.GetFocused ());
@@ -514,34 +514,34 @@ public partial class ToplevelTests (ITestOutputHelper output)
#endif
Assert.True (Application.OnKeyDown (Key.Tab.WithShift)); // Ignored. TextView eats shift-tab by default
Assert.Equal (win1, top.Focused);
- Assert.Equal (tvW1, top.GetMostFocused ());
+ Assert.Equal (tvW1, top.MostFocused);
tvW1.AllowsTab = false;
Assert.True (Application.OnKeyDown (Key.Tab.WithShift));
Assert.Equal (win1, top.Focused);
- Assert.Equal (tf1W1, top.GetMostFocused ());
+ Assert.Equal (tf1W1, top.MostFocused);
Assert.True (Application.OnKeyDown (Key.CursorLeft));
Assert.Equal (win1, top.Focused);
- Assert.Equal (tf2W1, top.GetMostFocused ());
+ Assert.Equal (tf2W1, top.MostFocused);
Assert.True (Application.OnKeyDown (Key.CursorUp));
Assert.Equal (win1, top.Focused);
- Assert.Equal (tvW1, top.GetMostFocused ());
+ Assert.Equal (tvW1, top.MostFocused);
// nav to win2
Assert.True (Application.OnKeyDown (Key.F6));
Assert.Equal (win2, top.Focused);
- Assert.Equal (tf1W2, top.GetMostFocused ());
+ Assert.Equal (tf1W2, top.MostFocused);
Assert.True (Application.OnKeyDown (Key.F6.WithShift));
Assert.Equal (win1, top.Focused);
- Assert.Equal (tf2W1, top.GetMostFocused ());
+ Assert.Equal (tf2W1, top.MostFocused);
Assert.True (Application.OnKeyDown (Application.NextTabGroupKey));
Assert.Equal (win2, top.Focused);
- Assert.Equal (tf1W2, top.GetMostFocused ());
+ Assert.Equal (tf1W2, top.MostFocused);
Assert.True (Application.OnKeyDown (Application.PrevTabGroupKey));
Assert.Equal (win1, top.Focused);
- Assert.Equal (tf2W1, top.GetMostFocused ());
+ Assert.Equal (tf2W1, top.MostFocused);
Assert.True (Application.OnKeyDown (Key.CursorUp));
Assert.Equal (win1, top.Focused);
- Assert.Equal (tvW1, top.GetMostFocused ());
+ Assert.Equal (tvW1, top.MostFocused);
top.Dispose ();
}
diff --git a/UnitTests/Views/TreeTableSourceTests.cs b/UnitTests/Views/TreeTableSourceTests.cs
index 516187206..4e4ba260e 100644
--- a/UnitTests/Views/TreeTableSourceTests.cs
+++ b/UnitTests/Views/TreeTableSourceTests.cs
@@ -290,7 +290,7 @@ public class TreeTableSourceTests : IDisposable
var top = new Toplevel ();
top.Add (tableView);
top.RestoreFocus (null);
- Assert.Equal (tableView, top.GetMostFocused ());
+ Assert.Equal (tableView, top.MostFocused);
return tableView;
}
diff --git a/UnitTests/Views/WindowTests.cs b/UnitTests/Views/WindowTests.cs
index 539c92431..a010227f7 100644
--- a/UnitTests/Views/WindowTests.cs
+++ b/UnitTests/Views/WindowTests.cs
@@ -143,7 +143,7 @@ public class WindowTests
Assert.False (defaultWindow.WantContinuousButtonPressed);
Assert.False (defaultWindow.WantMousePositionReports);
Assert.Null (defaultWindow.SuperView);
- Assert.Null (defaultWindow.GetMostFocused ());
+ Assert.Null (defaultWindow.MostFocused);
Assert.Equal (TextDirection.LeftRight_TopBottom, defaultWindow.TextDirection);
// Empty Rect
@@ -167,7 +167,7 @@ public class WindowTests
Assert.False (windowWithFrameRectEmpty.WantContinuousButtonPressed);
Assert.False (windowWithFrameRectEmpty.WantMousePositionReports);
Assert.Null (windowWithFrameRectEmpty.SuperView);
- Assert.Null (windowWithFrameRectEmpty.GetMostFocused ());
+ Assert.Null (windowWithFrameRectEmpty.MostFocused);
Assert.Equal (TextDirection.LeftRight_TopBottom, windowWithFrameRectEmpty.TextDirection);
// Rect with values
@@ -198,7 +198,7 @@ public class WindowTests
Assert.False (windowWithFrame1234.WantContinuousButtonPressed);
Assert.False (windowWithFrame1234.WantMousePositionReports);
Assert.Null (windowWithFrame1234.SuperView);
- Assert.Null (windowWithFrame1234.GetMostFocused ());
+ Assert.Null (windowWithFrame1234.MostFocused);
Assert.Equal (TextDirection.LeftRight_TopBottom, windowWithFrame1234.TextDirection);
}
diff --git a/docfx/docs/View.md b/docfx/docs/View.md
index ca1c733a2..9677ad2cc 100644
--- a/docfx/docs/View.md
+++ b/docfx/docs/View.md
@@ -132,7 +132,7 @@ This covers my thinking on how we will refactor `View` and the classes in the `V
## Design
* `Responder`("Responder base class implemented by objects that want to participate on keyboard and mouse input.") remains mostly unchanged, with minor changes:
- * Methods that take `View` parameters (e.g. `OnEnter`) change to take `Responder` (bad OO design).
+ * Methods that take `View` parameters change to take `Responder` (bad OO design).
* Nuke `IsOverriden` (bad OO design)
* Move `View.Data` to `Responder` (primitive)
* Move `Command` and `KeyBinding` stuff from `View`.
diff --git a/docfx/docs/index.md b/docfx/docs/index.md
index 05e6dd9ea..565dc5408 100644
--- a/docfx/docs/index.md
+++ b/docfx/docs/index.md
@@ -2,6 +2,8 @@
A toolkit for building rich Terminal User Interface (TUI) apps with .NET that run on Windows, the Mac, and Linux/Unix.
+ (This is the v2 API documentation. For v1 go here: https://gui-cs.github.io/Terminal.Gui/api/Terminal.Gui.html)
+
## Features
* **[Cross Platform](drivers.md)** - Windows, Mac, and Linux. Terminal drivers for Curses, Windows, and the .NET Console mean apps will work well on both color and monochrome terminals. Apps also work over SSH.
diff --git a/docfx/docs/migratingfromv1.md b/docfx/docs/migratingfromv1.md
index 8f3551a40..5194bb4b5 100644
--- a/docfx/docs/migratingfromv1.md
+++ b/docfx/docs/migratingfromv1.md
@@ -225,12 +225,18 @@ In v2, the API is (NOT YET IMPLEMENTED) simplified. A view simply reports the st
See [navigation.md](navigation.md) for more details.
See also [Keyboard](keyboard.md) where HotKey is covered more deeply...
+* In v1 it was not possible to remove focus from a view. `HasFocus` as a get-only property. In v2, `view.HasFocus` can be set as well. Setting to `true` is equivalent to calling `view.SetFocus`. Setting to `false` is equivalent to calling `view.SuperView.AdvanceFocus` (which might not actually cause `view` to stop having focus).
* In v1, calling `super.Add (view)` where `view.CanFocus == true` caused all views up the hierarchy (all SuperViews) to get `CanFocus` set to `true` as well. In v2, developers need to explicitly set `CanFocus` for any view in the view-hierarchy where focus is desired. This simplifies the implementation and removes confusing automatic behavior.
* In v1, if `view.CanFocus == true`, `Add` would automatically set `TabStop`. In v2, the automatic setting of `TabStop` in `Add` is retained because it is not overly complex to do so and is a nice convenience for developers to not have to set both `Tabstop` and `CanFocus`. Note v2 does NOT automatically change `CanFocus` if `TabStop` is changed.
* `view.TabStop` now describes the behavior of a view in the focus-chain. the `TabBehavior` enum includes `NoStop` (the view may be focusable, but not via next/prev keyboard nav), `TabStop` (the view may be focusable, and `NextTabStop`/`PrevTabStop` keyboard nav will stop), `TabGroup` (the view may be focusable, and `NextTabGroup`/`PrevTabGroup` keyboard nav will stop).
* In v1, the `View.Focused` property was a cache of which view in `SubViews/TabIndexes` had `HasFocus == true`. There was a lot of logic for keeping this property in sync. In v2, `View.Focused` is a get-only, computed property.
-* In v1, the `View.OnEnter/Enter` and `View.OnLeave/Leave` virtual methods/events could be used to notify that a view had gained or lost focus, but had confusing semantics around what it mean to override (requiring calling `base`) and bug-ridden behavior on what the return values signified. The "Enter" and "Leave" terminology was confusing. In v2, the terminology is "Focus" and "Blur", matching modern web frameworks and the `View.OnFocus/Focus` and `View.OnBlur/Blur` virtual methods/events follow standard dotnet event patterns. The `OnFocus/Focus` event supports being cancelled.
+* In v1, the `View.MostFocused` property recursed down the subview-hierarchy on each get. In addition, because only one View in an application can be the "most focused", it doesn't make sense for this property to be on every View. In v2, this API is removed. Use `Application.Navigation.GetFocused()` instead.
+* The v1 APIs `View.EnsureFocus`/`FocusNext`/`FocusPrev`/`FocusFirst`/`FocusLast` are replaced in v2 with these APIs that accomplish the same thing, more simply.
+ - `public bool AdvanceFocus (NavigationDirection direction, TabBehavior? behavior)`
+ - `public bool FocusDeepest (NavigationDirection direction, TabBehavior? behavior)`
+* In v1, the `View.OnEnter/Enter` and `View.OnLeave/Leave` virtual methods/events could be used to notify that a view had gained or lost focus, but had confusing semantics around what it mean to override (requiring calling `base`) and bug-ridden behavior on what the return values signified. The "Enter" and "Leave" terminology was confusing. In v2, `View.OnHasFocusChanging/HasFocusChanging` and `View.OnHasFocusChanged/HasFocusChanged` replace `View.OnEnter/Enter` and `View.OnLeave/Leave`. These virtual methods/events follow standard Terminal.Gui event patterns. The `View.OnHasFocusChanging/HasFocusChanging` event supports being cancelled.
* In v1, the concept of `Mdi` views included a large amount of complex code (in `Toplevel` and `Application`) for dealing with navigation across overlapped Views. This has all been radically simplified in v2. Any View can work in an "overlapped" or "tiled" way. See [navigation.md](navigation.md) for more details.
+* The `View.TabIndex` and `View.TabIndexes` have been removed. Change the order of the views in `View.Subviews` to change the navigation order.
### How to Fix (Focus API)
diff --git a/docfx/docs/navigation.md b/docfx/docs/navigation.md
index 5f84b7a83..c54fd009a 100644
--- a/docfx/docs/navigation.md
+++ b/docfx/docs/navigation.md
@@ -18,8 +18,8 @@
- **Tab** - Describes the `Tab` key found on all keyboards, a break in text that is wider than a space, or a UI element that is a stop-point for keyboard navigation. The use of the word "Tab" for this comes from the typewriter, and is re-enforced by the existence of a `Tab` key on all keyboards.
- **TabStop** - A `View` that is an ultimate stop-point for keyboard navigation. In this usage, ultimate means the `View` has no focusable subviews. The `Application.NextTabStopKey` and `Application.PrevTabStopKey` are `Key.Tab` and `Key.Tab.WithShift` respectively. These keys navigate only between peer-views.
- **TabGroup** - A `View` that is a container for other focusable views. The `Application.NextTabGroupKey` and `Application.PrevTabGroupKey` are `Key.PageDown.WithCtrl` and `Key.PageUp.WithCtrl` respectively. These keys enable the user to use the keyboard to navigate up and down the view-hierarchy.
-- **Enter** / **Gain** - Means a View that previously was not focused is now becoming focused. "The View is entering focus" is the same as "The View is gaining focus".
-- **Leave** / **Lose** - Means a View that previously was focused is now becoming un-focused. "The View is leaving focus" is the same as "The View is losing focus".
+- **Enter** / **Gain** - Means a View that previously was not focused is now becoming focused. "The View is entering focus" is the same as "The View is gaining focus". These terms are legacy terms from v1.
+- **Leave** / **Lose** - Means a View that previously was focused is now becoming un-focused. "The View is leaving focus" is the same as "The View is losing focus". These terms are legacy terms from v1.
## Tenets for Terminal.Gui UI Navigation (Unless you know better ones...)