#nullable enable
namespace Terminal.Gui;
///
/// Helper class for navigation. Held by
///
public class ApplicationNavigation
{
///
/// Initializes a new instance of the class.
///
public ApplicationNavigation ()
{
// TODO: Move navigation key bindings here from AddApplicationKeyBindings
}
private View? _focused = null;
///
/// Gets the most focused in the application, if there is one.
///
public View? GetFocused () { return _focused; }
///
/// INTERNAL method to record the most focused in the application.
///
///
/// Raises .
///
internal void SetFocused (View? value)
{
if (_focused == value)
{
return;
}
_focused = value;
FocusedChanged?.Invoke (null, EventArgs.Empty);
return;
}
///
/// Raised when the most focused in the application has changed.
///
public event EventHandler? FocusedChanged;
///
/// Gets whether is in the Subview hierarchy of .
///
///
///
///
public static bool IsInHierarchy (View? start, View? view)
{
if (view is null)
{
return false;
}
if (view == start || start is null)
{
return true;
}
foreach (View subView in start.Subviews)
{
if (view == subView)
{
return true;
}
var found = IsInHierarchy (subView, view);
if (found)
{
return found;
}
}
return false;
}
///
/// Gets the deepest focused subview of the specified .
///
///
///
internal static View? GetDeepestFocusedSubview (View? view)
{
if (view is null)
{
return null;
}
foreach (View v in view.Subviews)
{
if (v.HasFocus)
{
return GetDeepestFocusedSubview (v);
}
}
return view;
}
}