1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- #nullable enable
- namespace Terminal.Gui;
- /// <summary>
- /// Helper class for <see cref="Application"/> navigation. Held by <see cref="Application.Navigation"/>
- /// </summary>
- public class ApplicationNavigation
- {
- /// <summary>
- /// Initializes a new instance of the <see cref="ApplicationNavigation"/> class.
- /// </summary>
- public ApplicationNavigation ()
- {
- // TODO: Move navigation key bindings here from AddApplicationKeyBindings
- }
- private View? _focused;
- /// <summary>
- /// Raised when the most focused <see cref="View"/> in the application has changed.
- /// </summary>
- public event EventHandler<EventArgs>? FocusedChanged;
- /// <summary>
- /// Gets the most focused <see cref="View"/> in the application, if there is one.
- /// </summary>
- public View? GetFocused () { return _focused; }
- /// <summary>
- /// Gets whether <paramref name="view"/> is in the Subview hierarchy of <paramref name="start"/>.
- /// </summary>
- /// <param name="start"></param>
- /// <param name="view"></param>
- /// <returns></returns>
- 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;
- }
- bool found = IsInHierarchy (subView, view);
- if (found)
- {
- return found;
- }
- }
- return false;
- }
- /// <summary>
- /// INTERNAL method to record the most focused <see cref="View"/> in the application.
- /// </summary>
- /// <remarks>
- /// Raises <see cref="FocusedChanged"/>.
- /// </remarks>
- internal void SetFocused (View? value)
- {
- if (_focused == value)
- {
- return;
- }
- _focused = value;
- FocusedChanged?.Invoke (null, EventArgs.Empty);
- }
- }
|