namespace Terminal.Gui.App;
///
/// Handles bespoke behaviours that occur when application top level changes.
///
public class ToplevelTransitionManager : IToplevelTransitionManager
{
private readonly HashSet _readiedTopLevels = new ();
private View? _lastTop;
///
///
public void RaiseReadyEventIfNeeded (IApplication? app)
{
Toplevel? top = app?.Current;
if (top != null && !_readiedTopLevels.Contains (top))
{
top.OnReady ();
_readiedTopLevels.Add (top);
// Views can be closed and opened and run again multiple times, see End_Does_Not_Dispose
top.Closed += (s, e) => _readiedTopLevels.Remove (top);
}
}
///
///
public void HandleTopMaybeChanging (IApplication? app)
{
Toplevel? newTop = app?.Current;
if (_lastTop != null && _lastTop != newTop && newTop != null)
{
newTop.SetNeedsDraw ();
}
_lastTop = app?.Current;
}
}