#nullable enable namespace Terminal.Gui; public static partial class Application // Toplevel handling { // BUGBUG: Technically, this is not the full lst of TopLevels. There be dragons here, e.g. see how Toplevel.Id is used. What /// Holds the stack of TopLevel views. internal static Stack TopLevels { get; } = new (); /// The object used for the application on startup () /// The top. public static Toplevel? Top { get; internal set; } // TODO: Determine why this can't just return _topLevels.Peek()? /// /// The current object. This is updated in enters and leaves to /// point to the current /// . /// /// /// This will only be distinct from in scenarios where is . /// /// The current. public static Toplevel? Current { get; internal set; } /// /// If is not already Current and visible, finds the last Modal Toplevel in the stack and makes it Current. /// private static void EnsureModalOrVisibleAlwaysOnTop (Toplevel topLevel) { if (!topLevel.Running || (topLevel == Current && topLevel.Visible) || ApplicationOverlapped.OverlappedTop == null || TopLevels.Peek ().Modal) { return; } foreach (Toplevel top in TopLevels.Reverse ()) { if (top.Modal && top != Current) { ApplicationOverlapped.MoveCurrent (top); return; } } if (!topLevel.Visible && topLevel == Current) { ApplicationOverlapped.OverlappedMoveNext (); } } }