Application.Toplevel.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #nullable enable
  2. namespace Terminal.Gui;
  3. public static partial class Application // Toplevel handling
  4. {
  5. // BUGBUG: Technically, this is not the full lst of TopLevels. There be dragons here, e.g. see how Toplevel.Id is used. What
  6. /// <summary>Holds the stack of TopLevel views.</summary>
  7. internal static Stack<Toplevel> TopLevels { get; } = new ();
  8. /// <summary>The <see cref="Toplevel"/> object used for the application on startup (<seealso cref="Top"/>)</summary>
  9. /// <value>The top.</value>
  10. public static Toplevel? Top { get; internal set; }
  11. // TODO: Determine why this can't just return _topLevels.Peek()?
  12. /// <summary>
  13. /// The current <see cref="Toplevel"/> object. This is updated in <see cref="Application.Begin"/> enters and leaves to
  14. /// point to the current
  15. /// <see cref="Toplevel"/> .
  16. /// </summary>
  17. /// <remarks>
  18. /// This will only be distinct from <see cref="Application.Top"/> in scenarios where <see cref="Toplevel.IsOverlappedContainer"/> is <see langword="true"/>.
  19. /// </remarks>
  20. /// <value>The current.</value>
  21. public static Toplevel? Current { get; internal set; }
  22. /// <summary>
  23. /// If <paramref name="topLevel"/> is not already Current and visible, finds the last Modal Toplevel in the stack and makes it Current.
  24. /// </summary>
  25. private static void EnsureModalOrVisibleAlwaysOnTop (Toplevel topLevel)
  26. {
  27. if (!topLevel.Running
  28. || (topLevel == Current && topLevel.Visible)
  29. || ApplicationOverlapped.OverlappedTop == null
  30. || TopLevels.Peek ().Modal)
  31. {
  32. return;
  33. }
  34. foreach (Toplevel top in TopLevels.Reverse ())
  35. {
  36. if (top.Modal && top != Current)
  37. {
  38. ApplicationOverlapped.MoveCurrent (top);
  39. return;
  40. }
  41. }
  42. if (!topLevel.Visible && topLevel == Current)
  43. {
  44. ApplicationOverlapped.OverlappedMoveNext ();
  45. }
  46. }
  47. }