Browse Source

More Toplevel.cs organization & docs

Tig 1 year ago
parent
commit
f8e8aff29f

+ 3 - 0
Terminal.Gui/Application/Application.Initialization.cs

@@ -1,3 +1,4 @@
+#nullable enable
 using System.Diagnostics.CodeAnalysis;
 using System.Reflection;
 
@@ -88,6 +89,8 @@ public static partial class Application // Initialization (Init/Shutdown)
         Load ();
         Apply ();
 
+        AddToplevelKeyBindings ();
+
         // Ignore Configuration for ForceDriver if driverName is specified
         if (!string.IsNullOrEmpty (driverName))
         {

+ 35 - 11
Terminal.Gui/Application/Application.Keyboard.cs

@@ -1,4 +1,5 @@
-using System.Text.Json.Serialization;
+#nullable enable
+using System.Text.Json.Serialization;
 
 namespace Terminal.Gui;
 
@@ -140,7 +141,7 @@ public static partial class Application // Keyboard handling
 
         // Invoke any global (Application-scoped) KeyBindings.
         // The first view that handles the key will stop the loop.
-        foreach (KeyValuePair<Key, List<View>> binding in _keyBindings.Where (b => b.Key == keyEvent.KeyCode))
+        foreach (KeyValuePair<Key, List<View?>> binding in _keyBindings.Where (b => b.Key == keyEvent.KeyCode))
         {
             foreach (View view in binding.Value)
             {
@@ -154,7 +155,6 @@ public static partial class Application // Keyboard handling
                     {
                         return true;
                     }
-
                 }
             }
         }
@@ -216,12 +216,12 @@ public static partial class Application // Keyboard handling
     /// <summary>
     ///     The <see cref="KeyBindingScope.Application"/> key bindings.
     /// </summary>
-    private static readonly Dictionary<Key, List<View>> _keyBindings = new ();
+    private static readonly Dictionary<Key, List<View?>> _keyBindings = new ();
 
     /// <summary>
     /// Gets the list of <see cref="KeyBindingScope.Application"/> key bindings.
     /// </summary>
-    public static Dictionary<Key, List<View>> GetKeyBindings () { return _keyBindings; }
+    public static Dictionary<Key, List<View?>> GetKeyBindings () { return _keyBindings; }
 
     /// <summary>
     ///     Adds an  <see cref="KeyBindingScope.Application"/> scoped key binding.
@@ -231,13 +231,8 @@ public static partial class Application // Keyboard handling
     /// </remarks>
     /// <param name="key">The key being bound.</param>
     /// <param name="view">The view that is bound to the key. If <see langword="null"/>, <see cref="Application.Current"/> will be used.</param>
-    internal static void AddKeyBinding (Key key, [CanBeNull] View view)
+    internal static void AddKeyBinding (Key key, View? view)
     {
-        if (view is null)
-        {
-            view = Current;
-        }
-
         if (!_keyBindings.ContainsKey (key))
         {
             _keyBindings [key] = [];
@@ -246,6 +241,35 @@ public static partial class Application // Keyboard handling
         _keyBindings [key].Add (view);
     }
 
+    internal static void AddToplevelKeyBindings ()
+    {
+//        // Default keybindings for this view
+//        AddKeyBinding (Application.QuitKey, null);
+//        AddKeyBinding (Key.CursorRight, null);
+//        AddKeyBinding (Key.CursorDown, null);
+//        AddKeyBinding (Key.CursorLeft, null);
+//        AddKeyBinding (Key.CursorUp, null);
+//        AddKeyBinding (Key.Tab, null);
+//        AddKeyBinding (Key.Tab.WithShift, null);
+//        AddKeyBinding (Key.Tab.WithCtrl, null);
+//        AddKeyBinding (Key.Tab.WithShift.WithCtrl, null);
+//        AddKeyBinding (Key.F5, null);
+//        AddKeyBinding (Application.AlternateForwardKey, null); // Needed on Unix
+//        AddKeyBinding (Application.AlternateBackwardKey, null); // Needed on Unix
+
+//        if (Environment.OSVersion.Platform == PlatformID.Unix)
+//        {
+//            AddKeyBinding (Key.Z.WithCtrl, null);
+//        }
+
+//#if UNIX_KEY_BINDINGS
+//        KeyBindings.Add (Key.L.WithCtrl, Command.Refresh); // Unix
+//        KeyBindings.Add (Key.F.WithCtrl, Command.NextView); // Unix
+//        KeyBindings.Add (Key.I.WithCtrl, Command.NextView); // Unix
+//        KeyBindings.Add (Key.B.WithCtrl, Command.PreviousView); // Unix
+//#endif
+    }
+
     /// <summary>
     ///     Gets the list of Views that have <see cref="KeyBindingScope.Application"/> key bindings.
     /// </summary>

+ 2 - 2
Terminal.Gui/Application/Application.Mouse.cs

@@ -1,5 +1,5 @@
-namespace Terminal.Gui;
-
+#nullable enable
+namespace Terminal.Gui;
 public static partial class Application // Mouse handling
 {
     #region Mouse handling

+ 211 - 0
Terminal.Gui/Application/Application.Navigation.cs

@@ -0,0 +1,211 @@
+namespace Terminal.Gui;
+
+public static partial class Application
+{
+    /// <summary>
+    ///     Gets the list of the Overlapped children which are not modal <see cref="Toplevel"/> from the
+    ///     <see cref="OverlappedTop"/>.
+    /// </summary>
+    public static List<Toplevel> OverlappedChildren
+    {
+        get
+        {
+            if (OverlappedTop is { })
+            {
+                List<Toplevel> _overlappedChildren = new ();
+
+                foreach (Toplevel top in _topLevels)
+                {
+                    if (top != OverlappedTop && !top.Modal)
+                    {
+                        _overlappedChildren.Add (top);
+                    }
+                }
+
+                return _overlappedChildren;
+            }
+
+            return null;
+        }
+    }
+
+#nullable enable
+    /// <summary>
+    ///     The <see cref="Toplevel"/> object used for the application on startup which
+    ///     <see cref="Toplevel.IsOverlappedContainer"/> is true.
+    /// </summary>
+    public static Toplevel? OverlappedTop
+    {
+        get
+        {
+            if (Top is { IsOverlappedContainer: true })
+            {
+                return Top;
+            }
+
+            return null;
+        }
+    }
+#nullable restore
+
+    /// <summary>Brings the superview of the most focused overlapped view is on front.</summary>
+    public static void BringOverlappedTopToFront ()
+    {
+        if (OverlappedTop is { })
+        {
+            return;
+        }
+
+        View top = FindTopFromView (Top?.MostFocused);
+
+        if (top is Toplevel && Top.Subviews.Count > 1 && Top.Subviews [^1] != top)
+        {
+            Top.BringSubviewToFront (top);
+        }
+    }
+
+    /// <summary>Gets the current visible Toplevel overlapped child that matches the arguments pattern.</summary>
+    /// <param name="type">The type.</param>
+    /// <param name="exclude">The strings to exclude.</param>
+    /// <returns>The matched view.</returns>
+    public static Toplevel GetTopOverlappedChild (Type type = null, string [] exclude = null)
+    {
+        if (OverlappedTop is null)
+        {
+            return null;
+        }
+
+        foreach (Toplevel top in OverlappedChildren)
+        {
+            if (type is { } && top.GetType () == type && exclude?.Contains (top.Data.ToString ()) == false)
+            {
+                return top;
+            }
+
+            if ((type is { } && top.GetType () != type) || exclude?.Contains (top.Data.ToString ()) == true)
+            {
+                continue;
+            }
+
+            return top;
+        }
+
+        return null;
+    }
+
+    /// <summary>
+    ///     Move to the next Overlapped child from the <see cref="OverlappedTop"/> and set it as the <see cref="Top"/> if
+    ///     it is not already.
+    /// </summary>
+    /// <param name="top"></param>
+    /// <returns></returns>
+    public static bool MoveToOverlappedChild (Toplevel top)
+    {
+        if (top.Visible && OverlappedTop is { } && Current?.Modal == false)
+        {
+            lock (_topLevels)
+            {
+                _topLevels.MoveTo (top, 0, new ToplevelEqualityComparer ());
+                Current = top;
+            }
+
+            return true;
+        }
+
+        return false;
+    }
+
+    /// <summary>Move to the next Overlapped child from the <see cref="OverlappedTop"/>.</summary>
+    public static void OverlappedMoveNext ()
+    {
+        if (OverlappedTop is { } && !Current.Modal)
+        {
+            lock (_topLevels)
+            {
+                _topLevels.MoveNext ();
+                var isOverlapped = false;
+
+                while (_topLevels.Peek () == OverlappedTop || !_topLevels.Peek ().Visible)
+                {
+                    if (!isOverlapped && _topLevels.Peek () == OverlappedTop)
+                    {
+                        isOverlapped = true;
+                    }
+                    else if (isOverlapped && _topLevels.Peek () == OverlappedTop)
+                    {
+                        MoveCurrent (Top);
+
+                        break;
+                    }
+
+                    _topLevels.MoveNext ();
+                }
+
+                Current = _topLevels.Peek ();
+            }
+        }
+    }
+
+    /// <summary>Move to the previous Overlapped child from the <see cref="OverlappedTop"/>.</summary>
+    public static void OverlappedMovePrevious ()
+    {
+        if (OverlappedTop is { } && !Current.Modal)
+        {
+            lock (_topLevels)
+            {
+                _topLevels.MovePrevious ();
+                var isOverlapped = false;
+
+                while (_topLevels.Peek () == OverlappedTop || !_topLevels.Peek ().Visible)
+                {
+                    if (!isOverlapped && _topLevels.Peek () == OverlappedTop)
+                    {
+                        isOverlapped = true;
+                    }
+                    else if (isOverlapped && _topLevels.Peek () == OverlappedTop)
+                    {
+                        MoveCurrent (Top);
+
+                        break;
+                    }
+
+                    _topLevels.MovePrevious ();
+                }
+
+                Current = _topLevels.Peek ();
+            }
+        }
+    }
+
+    private static bool OverlappedChildNeedsDisplay ()
+    {
+        if (OverlappedTop is null)
+        {
+            return false;
+        }
+
+        foreach (Toplevel top in _topLevels)
+        {
+            if (top != Current && top.Visible && (top.NeedsDisplay || top.SubViewNeedsDisplay || top.LayoutNeeded))
+            {
+                OverlappedTop.SetSubViewNeedsDisplay ();
+
+                return true;
+            }
+        }
+
+        return false;
+    }
+
+    private static bool SetCurrentOverlappedAsTop ()
+    {
+        if (OverlappedTop is null && Current != Top && Current?.SuperView is null && Current?.Modal == false)
+        {
+            Top = Current;
+
+            return true;
+        }
+
+        return false;
+    }
+}

+ 7 - 0
Terminal.Gui/Application/Application.Overlapped.cs

@@ -0,0 +1,7 @@
+#nullable enable
+namespace Terminal.Gui;
+
+public static partial class Application // App-level View Navigation
+{
+ 
+}

+ 1 - 0
Terminal.Gui/Application/Application.Run.cs

@@ -1,3 +1,4 @@
+#nullable enable
 using System.Diagnostics;
 using System.Diagnostics.CodeAnalysis;
 

+ 20 - 2
Terminal.Gui/Application/Application.Toplevel.cs

@@ -1,10 +1,10 @@
+#nullable enable
 namespace Terminal.Gui;
 
 public static partial class Application // Toplevel handling
 {
-    /// <summary>Holds the stack of TopLevel views.</summary>
-
     // BUGBUG: Technically, this is not the full lst of TopLevels. There be dragons here, e.g. see how Toplevel.Id is used. What
+    /// <summary>Holds the stack of TopLevel views.</summary>
     // about TopLevels that are just a SubView of another View?
     internal static readonly Stack<Toplevel> _topLevels = new ();
 
@@ -12,6 +12,7 @@ public static partial class Application // Toplevel handling
     /// <value>The top.</value>
     public static Toplevel Top { get; private set; }
 
+    // TODO: Determine why this can't just return _topLevels.Peek()?
     /// <summary>
     ///     The current <see cref="Toplevel"/> object. This is updated in <see cref="Application.Begin"/> enters and leaves to
     ///     point to the current
@@ -23,6 +24,9 @@ public static partial class Application // Toplevel handling
     /// <value>The current.</value>
     public static Toplevel Current { get; private set; }
 
+    /// <summary>
+    ///     If <paramref name="topLevel"/> is not already Current and visible, finds the last Modal Toplevel in the stack and makes it Current.
+    /// </summary>
     private static void EnsureModalOrVisibleAlwaysOnTop (Toplevel topLevel)
     {
         if (!topLevel.Running
@@ -49,6 +53,12 @@ public static partial class Application // Toplevel handling
         }
     }
 
+    /// <summary>
+    ///    Finds the first Toplevel in the stack that is Visible and who's Frame contains the <paramref name="location"/>.
+    /// </summary>
+    /// <param name="start"></param>
+    /// <param name="location"></param>
+    /// <returns></returns>
     private static Toplevel FindDeepestTop (Toplevel start, in Point location)
     {
         if (!start.Frame.Contains (location))
@@ -78,6 +88,9 @@ public static partial class Application // Toplevel handling
         return start;
     }
 
+    /// <summary>
+    /// Given <paramref name="view"/>, returns the first Superview up the chain that is <see cref="Top"/>.
+    /// </summary>
     private static View FindTopFromView (View view)
     {
         View top = view?.SuperView is { } && view?.SuperView != Top
@@ -92,6 +105,11 @@ public static partial class Application // Toplevel handling
         return top;
     }
 
+    /// <summary>
+    ///    If the <see cref="Current"/> is not the <paramref name="top"/> then <paramref name="top"/> is moved to the top of the Toplevel stack and made Current.
+    /// </summary>
+    /// <param name="top"></param>
+    /// <returns></returns>
     private static bool MoveCurrent (Toplevel top)
     {
         // The Current is modal and the top is not modal Toplevel then

+ 20 - 12
Terminal.Gui/View/ViewSubViews.cs

@@ -627,7 +627,7 @@ public partial class View
         }
     }
 
-    /// <summary>Causes the specified view and the entire parent hierarchy to have the focused order updated.</summary>
+    /// <summary>Causes this view to be focused and entire Superview hierarchy to have the focused order updated.</summary>
     public void SetFocus ()
     {
         if (!CanBeVisible (this) || !Enabled)
@@ -651,7 +651,7 @@ public partial class View
     }
 
     /// <summary>
-    ///     Finds the first view in the hierarchy that wants to get the focus if nothing is currently focused, otherwise,
+    ///     If there is no focused subview, calls <see cref="FocusFirst"/> or <see cref="FocusLast"/> based on <see cref="FocusDirection"/>. 
     ///     does nothing.
     /// </summary>
     public void EnsureFocus ()
@@ -669,7 +669,9 @@ public partial class View
         }
     }
 
-    /// <summary>Focuses the first focusable subview if one exists.</summary>
+    /// <summary>
+    ///     Focuses the last focusable view in <see cref="View.TabIndexes"/> if one exists. If there are no views in <see cref="View.TabIndexes"/> then the focus is set to the view itself.
+    /// </summary>
     public void FocusFirst ()
     {
         if (!CanBeVisible (this))
@@ -695,7 +697,9 @@ public partial class View
         }
     }
 
-    /// <summary>Focuses the last focusable subview if one exists.</summary>
+    /// <summary>
+    ///     Focuses the last focusable view in <see cref="View.TabIndexes"/> if one exists. If there are no views in <see cref="View.TabIndexes"/> then the focus is set to the view itself.
+    /// </summary>
     public void FocusLast ()
     {
         if (!CanBeVisible (this))
@@ -725,7 +729,9 @@ public partial class View
         }
     }
 
-    /// <summary>Focuses the previous view.</summary>
+    /// <summary>
+    ///     Focuses the previous view in <see cref="View.TabIndexes"/>. If there is no previous view, the focus is set to the view itself.
+    /// </summary>
     /// <returns><see langword="true"/> if previous was focused, <see langword="false"/> otherwise.</returns>
     public bool FocusPrev ()
     {
@@ -736,7 +742,7 @@ public partial class View
 
         FocusDirection = NavigationDirection.Backward;
 
-        if (_tabIndexes is null || _tabIndexes.Count == 0)
+        if (TabIndexes is null || TabIndexes.Count == 0)
         {
             return false;
         }
@@ -750,10 +756,10 @@ public partial class View
 
         int focusedIdx = -1;
 
-        for (int i = _tabIndexes.Count; i > 0;)
+        for (int i = TabIndexes.Count; i > 0;)
         {
             i--;
-            View w = _tabIndexes [i];
+            View w = TabIndexes [i];
 
             if (w.HasFocus)
             {
@@ -791,7 +797,9 @@ public partial class View
         return false;
     }
 
-    /// <summary>Focuses the next view.</summary>
+    /// <summary>
+    ///     Focuses the previous view in <see cref="View.TabIndexes"/>. If there is no previous view, the focus is set to the view itself.
+    /// </summary>
     /// <returns><see langword="true"/> if next was focused, <see langword="false"/> otherwise.</returns>
     public bool FocusNext ()
     {
@@ -802,7 +810,7 @@ public partial class View
 
         FocusDirection = NavigationDirection.Forward;
 
-        if (_tabIndexes is null || _tabIndexes.Count == 0)
+        if (TabIndexes is null || TabIndexes.Count == 0)
         {
             return false;
         }
@@ -816,9 +824,9 @@ public partial class View
 
         int focusedIdx = -1;
 
-        for (var i = 0; i < _tabIndexes.Count; i++)
+        for (var i = 0; i < TabIndexes.Count; i++)
         {
-            View w = _tabIndexes [i];
+            View w = TabIndexes [i];
 
             if (w.HasFocus)
             {

+ 20 - 7
Terminal.Gui/Views/Toplevel.cs

@@ -80,7 +80,7 @@ public partial class Toplevel : View
                    );
 
         /// TODO: Overlapped: Add Command.ShowHide
-        
+
         AddCommand (
                     Command.Suspend,    // TODO: Move to Application
                     () =>
@@ -566,7 +566,7 @@ public partial class Toplevel : View
 
     #endregion
 
-    #region Focus
+    #region Navigation
 
     /// <inheritdoc/>
     public override bool OnEnter (View view) { return MostFocused?.OnEnter (view) ?? base.OnEnter (view); }
@@ -574,9 +574,14 @@ public partial class Toplevel : View
     /// <inheritdoc/>
     public override bool OnLeave (View view) { return MostFocused?.OnLeave (view) ?? base.OnLeave (view); }
 
-    private void FocusNearestView (IEnumerable<View> views, NavigationDirection direction)
+    /// <summary>
+    ///    Sets the focus to the next view in the <see cref="TabIndexes"/> list. If the last view is focused, the first view is focused.
+    /// </summary>
+    /// <param name="viewsInTabIndexes"></param>
+    /// <param name="direction"></param>
+    private void FocusNearestView (IEnumerable<View> viewsInTabIndexes, NavigationDirection direction)
     {
-        if (views is null)
+        if (viewsInTabIndexes is null)
         {
             return;
         }
@@ -585,7 +590,7 @@ public partial class Toplevel : View
         var focusProcessed = false;
         var idx = 0;
 
-        foreach (View v in views)
+        foreach (View v in viewsInTabIndexes)
         {
             if (v == this)
             {
@@ -610,15 +615,20 @@ public partial class Toplevel : View
                     return;
                 }
             }
-            else if (found && !focusProcessed && idx == views.Count () - 1)
+            else if (found && !focusProcessed && idx == viewsInTabIndexes.Count () - 1)
             {
-                views.ToList () [0].SetFocus ();
+                viewsInTabIndexes.ToList () [0].SetFocus ();
             }
 
             idx++;
         }
     }
 
+    /// <summary>
+    ///    Gets the deepest focused subview of the specified <paramref name="view"/>.
+    /// </summary>
+    /// <param name="view"></param>
+    /// <returns></returns>
     private View GetDeepestFocusedSubview (View view)
     {
         if (view is null)
@@ -637,6 +647,9 @@ public partial class Toplevel : View
         return view;
     }
 
+    /// <summary>
+    ///     Moves the focus to 
+    /// </summary>
     private void MoveNextView ()
     {
         View old = GetDeepestFocusedSubview (Focused);

+ 0 - 209
Terminal.Gui/Views/ToplevelOverlapped.cs

@@ -9,212 +9,3 @@ public partial class Toplevel
     public bool IsOverlappedContainer { get; set; }
 }
 
-public static partial class Application
-{
-    /// <summary>
-    ///     Gets the list of the Overlapped children which are not modal <see cref="Toplevel"/> from the
-    ///     <see cref="OverlappedTop"/>.
-    /// </summary>
-    public static List<Toplevel> OverlappedChildren
-    {
-        get
-        {
-            if (OverlappedTop is { })
-            {
-                List<Toplevel> _overlappedChildren = new ();
-
-                foreach (Toplevel top in _topLevels)
-                {
-                    if (top != OverlappedTop && !top.Modal)
-                    {
-                        _overlappedChildren.Add (top);
-                    }
-                }
-
-                return _overlappedChildren;
-            }
-
-            return null;
-        }
-    }
-
-    #nullable enable
-    /// <summary>
-    ///     The <see cref="Toplevel"/> object used for the application on startup which
-    ///     <see cref="Toplevel.IsOverlappedContainer"/> is true.
-    /// </summary>
-    public static Toplevel? OverlappedTop
-    {
-        get
-        {
-            if (Top is { IsOverlappedContainer: true })
-            {
-                return Top;
-            }
-
-            return null;
-        }
-    }
-    #nullable restore
-
-    /// <summary>Brings the superview of the most focused overlapped view is on front.</summary>
-    public static void BringOverlappedTopToFront ()
-    {
-        if (OverlappedTop is { })
-        {
-            return;
-        }
-
-        View top = FindTopFromView (Top?.MostFocused);
-
-        if (top is Toplevel && Top.Subviews.Count > 1 && Top.Subviews [^1] != top)
-        {
-            Top.BringSubviewToFront (top);
-        }
-    }
-
-    /// <summary>Gets the current visible Toplevel overlapped child that matches the arguments pattern.</summary>
-    /// <param name="type">The type.</param>
-    /// <param name="exclude">The strings to exclude.</param>
-    /// <returns>The matched view.</returns>
-    public static Toplevel GetTopOverlappedChild (Type type = null, string [] exclude = null)
-    {
-        if (OverlappedTop is null)
-        {
-            return null;
-        }
-
-        foreach (Toplevel top in OverlappedChildren)
-        {
-            if (type is { } && top.GetType () == type && exclude?.Contains (top.Data.ToString ()) == false)
-            {
-                return top;
-            }
-
-            if ((type is { } && top.GetType () != type) || exclude?.Contains (top.Data.ToString ()) == true)
-            {
-                continue;
-            }
-
-            return top;
-        }
-
-        return null;
-    }
-
-    /// <summary>
-    ///     Move to the next Overlapped child from the <see cref="OverlappedTop"/> and set it as the <see cref="Top"/> if
-    ///     it is not already.
-    /// </summary>
-    /// <param name="top"></param>
-    /// <returns></returns>
-    public static bool MoveToOverlappedChild (Toplevel top)
-    {
-        if (top.Visible && OverlappedTop is { } && Current?.Modal == false)
-        {
-            lock (_topLevels)
-            {
-                _topLevels.MoveTo (top, 0, new ToplevelEqualityComparer ());
-                Current = top;
-            }
-
-            return true;
-        }
-
-        return false;
-    }
-
-    /// <summary>Move to the next Overlapped child from the <see cref="OverlappedTop"/>.</summary>
-    public static void OverlappedMoveNext ()
-    {
-        if (OverlappedTop is { } && !Current.Modal)
-        {
-            lock (_topLevels)
-            {
-                _topLevels.MoveNext ();
-                var isOverlapped = false;
-
-                while (_topLevels.Peek () == OverlappedTop || !_topLevels.Peek ().Visible)
-                {
-                    if (!isOverlapped && _topLevels.Peek () == OverlappedTop)
-                    {
-                        isOverlapped = true;
-                    }
-                    else if (isOverlapped && _topLevels.Peek () == OverlappedTop)
-                    {
-                        MoveCurrent (Top);
-
-                        break;
-                    }
-
-                    _topLevels.MoveNext ();
-                }
-
-                Current = _topLevels.Peek ();
-            }
-        }
-    }
-
-    /// <summary>Move to the previous Overlapped child from the <see cref="OverlappedTop"/>.</summary>
-    public static void OverlappedMovePrevious ()
-    {
-        if (OverlappedTop is { } && !Current.Modal)
-        {
-            lock (_topLevels)
-            {
-                _topLevels.MovePrevious ();
-                var isOverlapped = false;
-
-                while (_topLevels.Peek () == OverlappedTop || !_topLevels.Peek ().Visible)
-                {
-                    if (!isOverlapped && _topLevels.Peek () == OverlappedTop)
-                    {
-                        isOverlapped = true;
-                    }
-                    else if (isOverlapped && _topLevels.Peek () == OverlappedTop)
-                    {
-                        MoveCurrent (Top);
-
-                        break;
-                    }
-
-                    _topLevels.MovePrevious ();
-                }
-
-                Current = _topLevels.Peek ();
-            }
-        }
-    }
-
-    private static bool OverlappedChildNeedsDisplay ()
-    {
-        if (OverlappedTop is null)
-        {
-            return false;
-        }
-
-        foreach (Toplevel top in _topLevels)
-        {
-            if (top != Current && top.Visible && (top.NeedsDisplay || top.SubViewNeedsDisplay || top.LayoutNeeded))
-            {
-                OverlappedTop.SetSubViewNeedsDisplay ();
-
-                return true;
-            }
-        }
-
-        return false;
-    }
-
-    private static bool SetCurrentOverlappedAsTop ()
-    {
-        if (OverlappedTop is null && Current != Top && Current?.SuperView is null && Current?.Modal == false)
-        {
-            Top = Current;
-
-            return true;
-        }
-
-        return false;
-    }
-}