ToplevelTransitionManager.cs 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #nullable enable
  2. namespace Terminal.Gui.Drivers;
  3. /// <summary>
  4. /// Handles bespoke behaviours that occur when application top level changes.
  5. /// </summary>
  6. public class ToplevelTransitionManager : IToplevelTransitionManager
  7. {
  8. private readonly HashSet<Toplevel> _readiedTopLevels = new ();
  9. private View? _lastTop;
  10. /// <inheritdoc/>
  11. public void RaiseReadyEventIfNeeded ()
  12. {
  13. Toplevel? top = Application.Top;
  14. if (top != null && !_readiedTopLevels.Contains (top))
  15. {
  16. top.OnReady ();
  17. _readiedTopLevels.Add (top);
  18. // Views can be closed and opened and run again multiple times, see End_Does_Not_Dispose
  19. top.Closed += (s, e) => _readiedTopLevels.Remove (top);
  20. }
  21. }
  22. /// <inheritdoc/>
  23. public void HandleTopMaybeChanging ()
  24. {
  25. Toplevel? newTop = Application.Top;
  26. if (_lastTop != null && _lastTop != newTop && newTop != null)
  27. {
  28. newTop.SetNeedsDraw ();
  29. }
  30. _lastTop = Application.Top;
  31. }
  32. }