diff --git a/Terminal.Gui/Application/Application.Keyboard.cs b/Terminal.Gui/Application/Application.Keyboard.cs
index 95d6923b2..0e92961a5 100644
--- a/Terminal.Gui/Application/Application.Keyboard.cs
+++ b/Terminal.Gui/Application/Application.Keyboard.cs
@@ -95,7 +95,7 @@ public static partial class Application // Keyboard handling
return true;
}
- if (Current is null)
+ if (Top is null)
{
foreach (Toplevel topLevel in TopLevels.ToList ())
{
@@ -112,7 +112,7 @@ public static partial class Application // Keyboard handling
}
else
{
- if (Current.NewKeyDownEvent (keyEvent))
+ if (Top.NewKeyDownEvent (keyEvent))
{
return true;
}
@@ -285,15 +285,7 @@ public static partial class Application // Keyboard handling
Command.Quit,
static () =>
{
- if (ApplicationOverlapped.OverlappedTop is { })
- {
- RequestStop (Current!);
- }
- else
- {
- RequestStop ();
- }
-
+ RequestStop ();
return true;
}
);
@@ -318,35 +310,11 @@ public static partial class Application // Keyboard handling
AddCommand (
Command.NextTabGroup,
- static () =>
- {
- // TODO: This OverlapppedTop tomfoolery goes away in addressing #2491
- if (ApplicationOverlapped.OverlappedTop is { })
- {
- ApplicationOverlapped.OverlappedMoveNext ();
-
- return true;
- }
-
- return Navigation?.AdvanceFocus (NavigationDirection.Forward, TabBehavior.TabGroup);
- }
- );
+ static () => Navigation?.AdvanceFocus (NavigationDirection.Forward, TabBehavior.TabGroup));
AddCommand (
Command.PreviousTabGroup,
- static () =>
- {
- // TODO: This OverlapppedTop tomfoolery goes away in addressing #2491
- if (ApplicationOverlapped.OverlappedTop is { })
- {
- ApplicationOverlapped.OverlappedMovePrevious ();
-
- return true;
- }
-
- return Navigation?.AdvanceFocus (NavigationDirection.Backward, TabBehavior.TabGroup);
- }
- );
+ static () => Navigation?.AdvanceFocus (NavigationDirection.Backward, TabBehavior.TabGroup));
AddCommand (
Command.Refresh,
diff --git a/Terminal.Gui/Application/Application.Mouse.cs b/Terminal.Gui/Application/Application.Mouse.cs
index 2b16686d3..9da49e652 100644
--- a/Terminal.Gui/Application/Application.Mouse.cs
+++ b/Terminal.Gui/Application/Application.Mouse.cs
@@ -139,7 +139,7 @@ public static partial class Application // Mouse handling
return;
}
- var view = View.FindDeepestView (Current, mouseEvent.Position);
+ var view = View.FindDeepestView (Top, mouseEvent.Position);
if (view is { })
{
@@ -208,23 +208,6 @@ public static partial class Application // Mouse handling
_ => null
};
- if (view is not Adornment
- && (view is null || view == ApplicationOverlapped.OverlappedTop)
- && Current is { Modal: false }
- && ApplicationOverlapped.OverlappedTop != null
- && mouseEvent.Flags is not MouseFlags.ReportMousePosition and not 0)
- {
- // This occurs when there are multiple overlapped "tops"
- // E.g. "Mdi" - in the Background Worker Scenario
- View? top = ApplicationOverlapped.FindDeepestTop (Top!, mouseEvent.Position);
- view = View.FindDeepestView (top, mouseEvent.Position);
-
- if (view is { } && view != ApplicationOverlapped.OverlappedTop && top != Current && top is { })
- {
- ApplicationOverlapped.MoveCurrent ((Toplevel)top);
- }
- }
-
// May be null before the prior condition or the condition may set it as null.
// So, the checking must be outside the prior condition.
if (view is null)
@@ -310,8 +293,6 @@ public static partial class Application // Mouse handling
View = view
};
}
-
- ApplicationOverlapped.BringOverlappedTopToFront ();
}
#endregion Mouse handling
diff --git a/Terminal.Gui/Application/Application.Run.cs b/Terminal.Gui/Application/Application.Run.cs
index 5099788fd..97ba63350 100644
--- a/Terminal.Gui/Application/Application.Run.cs
+++ b/Terminal.Gui/Application/Application.Run.cs
@@ -54,11 +54,6 @@ public static partial class Application // Run (Begin, Run, End, Stop)
}
#endif
- if (toplevel.IsOverlappedContainer && ApplicationOverlapped.OverlappedTop != toplevel && ApplicationOverlapped.OverlappedTop is { })
- {
- throw new InvalidOperationException ("Only one Overlapped Container is allowed.");
- }
-
// Ensure the mouse is ungrabbed.
MouseGrabView = null;
@@ -96,11 +91,6 @@ public static partial class Application // Run (Begin, Run, End, Stop)
throw new ObjectDisposedException (Top.GetType ().FullName);
}
}
- else if (ApplicationOverlapped.OverlappedTop is { } && toplevel != Top && TopLevels.Contains (Top!))
- {
- // BUGBUG: Don't call OnLeave/OnEnter directly! Set HasFocus to false and let the system handle it.
- //Top!.OnLeave (toplevel);
- }
// BUGBUG: We should not depend on `Id` internally.
// BUGBUG: It is super unclear what this code does anyway.
@@ -135,79 +125,46 @@ public static partial class Application // Run (Begin, Run, End, Stop)
}
}
- if (Top is null || toplevel.IsOverlappedContainer)
+ if (Top is null)
{
Top = toplevel;
}
- var refreshDriver = true;
-
- if (ApplicationOverlapped.OverlappedTop is null
- || toplevel.IsOverlappedContainer
- || (Current?.Modal == false && toplevel.Modal)
- || (Current?.Modal == false && !toplevel.Modal)
- || (Current?.Modal == true && toplevel.Modal))
+ if ((Top?.Modal == false && toplevel.Modal)
+ || (Top?.Modal == false && !toplevel.Modal)
+ || (Top?.Modal == true && toplevel.Modal))
{
if (toplevel.Visible)
{
- if (Current is { HasFocus: true })
+ if (Top is { HasFocus: true })
{
- Current.HasFocus = false;
+ Top.HasFocus = false;
}
- Current?.OnDeactivate (toplevel);
- Toplevel previousCurrent = Current!;
+ Top?.OnDeactivate (toplevel);
+ Toplevel previousCurrent = Top!;
- Current = toplevel;
- Current.OnActivate (previousCurrent);
-
- ApplicationOverlapped.SetCurrentOverlappedAsTop ();
+ Top = toplevel;
+ Top.OnActivate (previousCurrent);
}
- else
- {
- refreshDriver = false;
- }
- }
- else if ((toplevel != ApplicationOverlapped.OverlappedTop
- && Current?.Modal == true
- && !TopLevels.Peek ().Modal)
- || (toplevel != ApplicationOverlapped.OverlappedTop && Current?.Running == false))
- {
- refreshDriver = false;
- ApplicationOverlapped.MoveCurrent (toplevel);
- }
- else
- {
- refreshDriver = false;
- ApplicationOverlapped.MoveCurrent (Current!);
}
toplevel.SetRelativeLayout (Driver!.Screen.Size);
-
toplevel.LayoutSubviews ();
- toplevel.PositionToplevels ();
- // TODO: Should this use FindDeepestFocusableView instead?
// Try to set initial focus to any TabStop
if (!toplevel.HasFocus)
{
toplevel.SetFocus ();
}
- ApplicationOverlapped.BringOverlappedTopToFront ();
+ toplevel.OnLoaded ();
- if (refreshDriver)
+ Refresh ();
+
+ if (PositionCursor ())
{
- ApplicationOverlapped.OverlappedTop?.OnChildLoaded (toplevel);
- toplevel.OnLoaded ();
- toplevel.SetNeedsDisplay ();
- toplevel.Draw ();
- Driver.UpdateScreen ();
-
- if (PositionCursor (toplevel))
- {
- Driver.UpdateCursor ();
- }
+ Driver.UpdateCursor ();
}
NotifyNewRunState?.Invoke (toplevel, new (rs));
@@ -226,25 +183,13 @@ public static partial class Application // Run (Begin, Run, End, Stop)
///
///
/// if a view positioned the cursor and the position is visible.
- internal static bool PositionCursor (View view)
+ internal static bool PositionCursor ()
{
// Find the most focused view and position the cursor there.
- View? mostFocused = view?.MostFocused;
-
- if (mostFocused is null)
- {
- if (view is { HasFocus: true })
- {
- mostFocused = view;
- }
- else
- {
- return false;
- }
- }
+ View? mostFocused = Navigation?.GetFocused ();
// If the view is not visible or enabled, don't position the cursor
- if (!mostFocused.Visible || !mostFocused.Enabled)
+ if (mostFocused is null || !mostFocused.Visible || !mostFocused.Enabled)
{
Driver!.GetCursorVisibility (out CursorVisibility current);
@@ -510,11 +455,12 @@ public static partial class Application // Run (Begin, Run, End, Stop)
/// Triggers a refresh of the entire display.
public static void Refresh ()
{
- // TODO: Figure out how to remove this call to ClearContents. Refresh should just repaint damaged areas, not clear
- Driver!.ClearContents ();
-
foreach (Toplevel v in TopLevels.Reverse ())
{
+ if (v.LayoutNeeded)
+ {
+ v.LayoutSubviews ();
+ }
if (v.Visible)
{
v.SetNeedsDisplay ();
@@ -523,7 +469,7 @@ public static partial class Application // Run (Begin, Run, End, Stop)
}
}
- Driver.Refresh ();
+ Driver!.Refresh ();
}
/// This event is raised on each iteration of the main loop.
@@ -586,80 +532,22 @@ public static partial class Application // Run (Begin, Run, End, Stop)
MainLoop.RunIteration ();
Iteration?.Invoke (null, new ());
- EnsureModalOrVisibleAlwaysOnTop (state.Toplevel);
-
- // TODO: Overlapped - Move elsewhere
- if (state.Toplevel != Current)
- {
- ApplicationOverlapped.OverlappedTop?.OnDeactivate (state.Toplevel);
- state.Toplevel = Current;
- ApplicationOverlapped.OverlappedTop?.OnActivate (state.Toplevel!);
- Top!.SetSubViewNeedsDisplay ();
- Refresh ();
- }
}
firstIteration = false;
- if (Current == null)
+ if (Top is null)
{
return;
}
- if (state.Toplevel != Top && (Top!.NeedsDisplay || Top.SubViewNeedsDisplay || Top.LayoutNeeded))
- {
- state.Toplevel!.SetNeedsDisplay (state.Toplevel.Frame);
- Top.Draw ();
+ Refresh ();
- foreach (Toplevel top in TopLevels.Reverse ())
- {
- if (top != Top && top != state.Toplevel)
- {
- top.SetNeedsDisplay ();
- top.SetSubViewNeedsDisplay ();
- top.Draw ();
- }
- }
- }
-
- if (TopLevels.Count == 1
- && state.Toplevel == Top
- && (Driver!.Cols != state.Toplevel!.Frame.Width
- || Driver!.Rows != state.Toplevel.Frame.Height)
- && (state.Toplevel.NeedsDisplay
- || state.Toplevel.SubViewNeedsDisplay
- || state.Toplevel.LayoutNeeded))
- {
- Driver.ClearContents ();
- }
-
- if (state.Toplevel!.NeedsDisplay || state.Toplevel.SubViewNeedsDisplay || state.Toplevel.LayoutNeeded || ApplicationOverlapped.OverlappedChildNeedsDisplay ())
- {
- state.Toplevel.SetNeedsDisplay ();
- state.Toplevel.Draw ();
- Driver!.UpdateScreen ();
-
- //Driver.UpdateCursor ();
- }
-
- if (PositionCursor (state.Toplevel))
+ if (PositionCursor ())
{
Driver!.UpdateCursor ();
}
- // else
- {
- //if (PositionCursor (state.Toplevel))
- //{
- // Driver.Refresh ();
- //}
- //Driver.UpdateCursor ();
- }
-
- if (state.Toplevel != Top && !state.Toplevel.Modal && (Top!.NeedsDisplay || Top.SubViewNeedsDisplay || Top.LayoutNeeded))
- {
- Top.Draw ();
- }
}
/// Stops the provided , causing or the if provided.
@@ -673,112 +561,26 @@ public static partial class Application // Run (Begin, Run, End, Stop)
///
public static void RequestStop (Toplevel? top = null)
{
- if (ApplicationOverlapped.OverlappedTop is null || top is null)
+ if (top is null)
{
- top = Current;
+ top = Top;
}
- if (ApplicationOverlapped.OverlappedTop != null
- && top!.IsOverlappedContainer
- && top?.Running == true
- && (Current?.Modal == false || Current is { Modal: true, Running: false }))
+ if (!top!.Running)
{
- ApplicationOverlapped.OverlappedTop.RequestStop ();
+ return;
}
- else if (ApplicationOverlapped.OverlappedTop != null
- && top != Current
- && Current is { Running: true, Modal: true }
- && top!.Modal
- && top.Running)
+
+ var ev = new ToplevelClosingEventArgs (top);
+ top.OnClosing (ev);
+
+ if (ev.Cancel)
{
- var ev = new ToplevelClosingEventArgs (Current);
- Current.OnClosing (ev);
-
- if (ev.Cancel)
- {
- return;
- }
-
- ev = new (top);
- top.OnClosing (ev);
-
- if (ev.Cancel)
- {
- return;
- }
-
- Current.Running = false;
- OnNotifyStopRunState (Current);
- top.Running = false;
- OnNotifyStopRunState (top);
+ return;
}
- else if ((ApplicationOverlapped.OverlappedTop != null
- && top != ApplicationOverlapped.OverlappedTop
- && top != Current
- && Current is { Modal: false, Running: true }
- && !top!.Running)
- || (ApplicationOverlapped.OverlappedTop != null
- && top != ApplicationOverlapped.OverlappedTop
- && top != Current
- && Current is { Modal: false, Running: false }
- && !top!.Running
- && TopLevels.ToArray () [1].Running))
- {
- ApplicationOverlapped.MoveCurrent (top);
- }
- else if (ApplicationOverlapped.OverlappedTop != null
- && Current != top
- && Current?.Running == true
- && !top!.Running
- && Current?.Modal == true
- && top.Modal)
- {
- // The Current and the top are both modal so needed to set the Current.Running to false too.
- Current.Running = false;
- OnNotifyStopRunState (Current);
- }
- else if (ApplicationOverlapped.OverlappedTop != null
- && Current == top
- && ApplicationOverlapped.OverlappedTop?.Running == true
- && Current?.Running == true
- && top!.Running
- && Current?.Modal == true
- && top!.Modal)
- {
- // The OverlappedTop was requested to stop inside a modal Toplevel which is the Current and top,
- // both are the same, so needed to set the Current.Running to false too.
- Current.Running = false;
- OnNotifyStopRunState (Current);
- }
- else
- {
- Toplevel currentTop;
- if (top == Current || (Current?.Modal == true && !top!.Modal))
- {
- currentTop = Current!;
- }
- else
- {
- currentTop = top!;
- }
-
- if (!currentTop.Running)
- {
- return;
- }
-
- var ev = new ToplevelClosingEventArgs (currentTop);
- currentTop.OnClosing (ev);
-
- if (ev.Cancel)
- {
- return;
- }
-
- currentTop.Running = false;
- OnNotifyStopRunState (currentTop);
- }
+ top.Running = false;
+ OnNotifyStopRunState (top);
}
private static void OnNotifyStopRunState (Toplevel top)
@@ -798,14 +600,7 @@ public static partial class Application // Run (Begin, Run, End, Stop)
{
ArgumentNullException.ThrowIfNull (runState);
- if (ApplicationOverlapped.OverlappedTop is { })
- {
- ApplicationOverlapped.OverlappedTop.OnChildUnloaded (runState.Toplevel);
- }
- else
- {
- runState.Toplevel.OnUnloaded ();
- }
+ runState.Toplevel.OnUnloaded ();
// End the RunState.Toplevel
// First, take it off the Toplevel Stack
@@ -824,65 +619,26 @@ public static partial class Application // Run (Begin, Run, End, Stop)
// Notify that it is closing
runState.Toplevel?.OnClosed (runState.Toplevel);
- // If there is a OverlappedTop that is not the RunState.Toplevel then RunState.Toplevel
- // is a child of MidTop, and we should notify the OverlappedTop that it is closing
- if (ApplicationOverlapped.OverlappedTop is { } && !runState.Toplevel!.Modal && runState.Toplevel != ApplicationOverlapped.OverlappedTop)
+ if (TopLevels.Count > 0)
{
- ApplicationOverlapped.OverlappedTop.OnChildClosed (runState.Toplevel);
+ Top = TopLevels.Peek ();
}
- // Set Current and Top to the next TopLevel on the stack
- if (TopLevels.Count == 0)
+ // BUGBUG: We should not call OnEnter/OnLeave directly; they should only be called by SetHasFocus
+ if (runState.Toplevel is { HasFocus: true })
{
- if (Current is { HasFocus: true })
- {
- Current.HasFocus = false;
- }
- Current = null;
- }
- else
- {
- if (TopLevels.Count > 1 && TopLevels.Peek () == ApplicationOverlapped.OverlappedTop && ApplicationOverlapped.OverlappedChildren?.Any (t => t.Visible) != null)
- {
- ApplicationOverlapped.OverlappedMoveNext ();
- }
-
- Current = TopLevels.Peek ();
-
- if (TopLevels.Count == 1 && Current == ApplicationOverlapped.OverlappedTop)
- {
- ApplicationOverlapped.OverlappedTop.OnAllChildClosed ();
- }
- else
- {
- ApplicationOverlapped.SetCurrentOverlappedAsTop ();
- // BUGBUG: We should not call OnEnter/OnLeave directly; they should only be called by SetHasFocus
- if (runState.Toplevel is { HasFocus: true })
- {
- runState.Toplevel.HasFocus = false;
- }
-
- if (Current is { HasFocus: false })
- {
- Current.SetFocus ();
- }
- }
-
- Refresh ();
+ runState.Toplevel.HasFocus = false;
}
- // Don't dispose runState.Toplevel. It's up to caller dispose it
- // If it's not the same as the current in the RunIteration,
- // it will be fixed later in the next RunIteration.
- if (ApplicationOverlapped.OverlappedTop is { } && !TopLevels.Contains (ApplicationOverlapped.OverlappedTop))
+ if (Top is { HasFocus: false })
{
- _cachedRunStateToplevel = ApplicationOverlapped.OverlappedTop;
- }
- else
- {
- _cachedRunStateToplevel = runState.Toplevel;
+ Top.SetFocus ();
}
+ //Refresh ();
+
+ _cachedRunStateToplevel = runState.Toplevel;
+
runState.Toplevel = null;
runState.Dispose ();
}
diff --git a/Terminal.Gui/Application/Application.Screen.cs b/Terminal.Gui/Application/Application.Screen.cs
index a3d56da06..141e1a7e0 100644
--- a/Terminal.Gui/Application/Application.Screen.cs
+++ b/Terminal.Gui/Application/Application.Screen.cs
@@ -37,13 +37,9 @@ public static partial class Application // Screen related stuff
{
t.SetRelativeLayout (args.Size.Value);
t.LayoutSubviews ();
- t.PositionToplevels ();
+ //t.PositionToplevels ();
t.OnSizeChanging (new (args.Size));
- if (PositionCursor (t))
- {
- Driver?.UpdateCursor ();
- }
}
Refresh ();
diff --git a/Terminal.Gui/Application/Application.Toplevel.cs b/Terminal.Gui/Application/Application.Toplevel.cs
index a1844b2d0..edb6714bb 100644
--- a/Terminal.Gui/Application/Application.Toplevel.cs
+++ b/Terminal.Gui/Application/Application.Toplevel.cs
@@ -11,46 +11,4 @@ public static partial class Application // Toplevel handling
/// 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 ();
- }
- }
-
}
diff --git a/Terminal.Gui/Application/Application.cs b/Terminal.Gui/Application/Application.cs
index d37ba3513..a2b62583e 100644
--- a/Terminal.Gui/Application/Application.cs
+++ b/Terminal.Gui/Application/Application.cs
@@ -149,7 +149,6 @@ public static partial class Application
}
TopLevels.Clear ();
- Current = null;
#if DEBUG_IDISPOSABLE
// Don't dispose the Top. It's up to caller dispose it
diff --git a/Terminal.Gui/Application/ApplicationNavigation.cs b/Terminal.Gui/Application/ApplicationNavigation.cs
index 088629140..cc1df9a7e 100644
--- a/Terminal.Gui/Application/ApplicationNavigation.cs
+++ b/Terminal.Gui/Application/ApplicationNavigation.cs
@@ -85,6 +85,11 @@ public class ApplicationNavigation
_focused = value;
+ //if (_focused is { } && Application.PositionCursor ())
+ //{
+ // Application.Driver?.UpdateCursor ();
+ //}
+
FocusedChanged?.Invoke (null, EventArgs.Empty);
}
@@ -105,6 +110,6 @@ public class ApplicationNavigation
///
public bool AdvanceFocus (NavigationDirection direction, TabBehavior? behavior)
{
- return Application.Current is { } && Application.Current.AdvanceFocus (direction, behavior);
+ return Application.Top is { } && Application.Top.AdvanceFocus (direction, behavior);
}
}
diff --git a/Terminal.Gui/Application/ApplicationOverlapped.cs b/Terminal.Gui/Application/ApplicationOverlapped.cs
deleted file mode 100644
index 328897580..000000000
--- a/Terminal.Gui/Application/ApplicationOverlapped.cs
+++ /dev/null
@@ -1,444 +0,0 @@
-#nullable enable
-using System.Diagnostics;
-using System.Reflection;
-
-namespace Terminal.Gui;
-
-///
-/// Helper class for managing overlapped views in the application.
-///
-public static class ApplicationOverlapped
-{
-
- ///
- /// Gets or sets if is in overlapped mode within a Toplevel container.
- ///
- ///
- ///
- public static bool IsOverlapped (Toplevel? top)
- {
- return ApplicationOverlapped.OverlappedTop is { } && ApplicationOverlapped.OverlappedTop != top && !top!.Modal;
- }
-
- ///
- /// Gets the list of the Overlapped children which are not modal from the
- /// .
- ///
- public static List? OverlappedChildren
- {
- get
- {
- if (OverlappedTop is { })
- {
- List overlappedChildren = new ();
-
- lock (Application.TopLevels)
- {
- foreach (Toplevel top in Application.TopLevels)
- {
- if (top != OverlappedTop && !top.Modal)
- {
- overlappedChildren.Add (top);
- }
- }
- }
-
- return overlappedChildren;
- }
-
- return null;
- }
- }
-
- ///
- /// The object used for the application on startup which
- /// is true.
- ///
- public static Toplevel? OverlappedTop
- {
- get
- {
- if (Application.Top is { IsOverlappedContainer: true })
- {
- return Application.Top;
- }
-
- return null;
- }
- }
-
- /// Brings the superview of the most focused overlapped view is on front.
- public static void BringOverlappedTopToFront ()
- {
- if (OverlappedTop is { })
- {
- return;
- }
-
- View? top = FindTopFromView (Application.Top?.MostFocused);
-
- if (top is Toplevel && Application.Top?.Subviews.Count > 1 && Application.Top.Subviews [^1] != top)
- {
- Application.Top.MoveSubviewToStart (top);
- }
- }
-
- /// Gets the current visible Toplevel overlapped child that matches the arguments pattern.
- /// The type.
- /// The strings to exclude.
- /// The matched view.
- public static Toplevel? GetTopOverlappedChild (Type? type = null, string []? exclude = null)
- {
- if (OverlappedChildren is null || 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;
- }
-
-
- ///
- /// Sets the focus to the next view in the specified direction within the provided list of views.
- /// If the end of the list is reached, the focus wraps around to the first view in the list.
- /// The method considers the current focused view (`Application.Current`) and attempts to move the focus
- /// to the next view in the specified direction. If the focus cannot be set to the next view, it wraps around
- /// to the first view in the list.
- ///
- ///
- ///
- internal static void SetFocusToNextViewWithWrap (IEnumerable? viewsInTabIndexes, NavigationDirection direction)
- {
- if (viewsInTabIndexes is null)
- {
- return;
- }
-
- // This code-path only executes in obtuse IsOverlappedContainer scenarios.
- Debug.Assert (Application.Current!.IsOverlappedContainer);
-
- bool foundCurrentView = false;
- bool focusSet = false;
- IEnumerable indexes = viewsInTabIndexes as View [] ?? viewsInTabIndexes.ToArray ();
- int viewCount = indexes.Count ();
- int currentIndex = 0;
-
- foreach (View view in indexes)
- {
- if (view == Application.Current)
- {
- foundCurrentView = true;
- }
- else if (foundCurrentView && !focusSet)
- {
- // One of the views is Current, but view is not. Attempt to Advance...
- Application.Current!.SuperView?.AdvanceFocus (direction, null);
- // QUESTION: AdvanceFocus returns false AND sets Focused to null if no view was found to advance to. Should't we only set focusProcessed if it returned true?
- focusSet = true;
-
- if (Application.Current.SuperView?.Focused != Application.Current)
- {
- return;
- }
-
- // Either AdvanceFocus didn't set focus or the view it set focus to is not current...
- // continue...
- }
-
- currentIndex++;
-
- if (foundCurrentView && !focusSet && currentIndex == viewCount)
- {
- // One of the views is Current AND AdvanceFocus didn't set focus AND we are at the last view in the list...
- // This means we should wrap around to the first view in the list.
- indexes.First ().SetFocus ();
- }
- }
- }
-
- ///
- /// Move to the next Overlapped child from the and set it as the if
- /// it is not already.
- ///
- ///
- ///
- public static bool MoveToOverlappedChild (Toplevel? top)
- {
- ArgumentNullException.ThrowIfNull (top);
-
- if (top.Visible && OverlappedTop is { } && Application.Current?.Modal == false)
- {
- lock (Application.TopLevels)
- {
- Application.TopLevels.MoveTo (top, 0, new ToplevelEqualityComparer ());
- Application.Current = top;
- }
-
- return true;
- }
-
- return false;
- }
-
- /// Move to the next Overlapped child from the .
- public static void OverlappedMoveNext ()
- {
- if (OverlappedTop is { } && !Application.Current!.Modal)
- {
- lock (Application.TopLevels)
- {
- Application.TopLevels.MoveNext ();
- var isOverlapped = false;
-
- while (Application.TopLevels.Peek () == OverlappedTop || !Application.TopLevels.Peek ().Visible)
- {
- if (!isOverlapped && Application.TopLevels.Peek () == OverlappedTop)
- {
- isOverlapped = true;
- }
- else if (isOverlapped && Application.TopLevels.Peek () == OverlappedTop)
- {
- MoveCurrent (Application.Top!);
-
- break;
- }
-
- Application.TopLevels.MoveNext ();
- }
-
- Application.Current = Application.TopLevels.Peek ();
- }
- }
- }
-
- /// Move to the previous Overlapped child from the .
- public static void OverlappedMovePrevious ()
- {
- if (OverlappedTop is { } && !Application.Current!.Modal)
- {
- lock (Application.TopLevels)
- {
- Application.TopLevels.MovePrevious ();
- var isOverlapped = false;
-
- while (Application.TopLevels.Peek () == OverlappedTop || !Application.TopLevels.Peek ().Visible)
- {
- if (!isOverlapped && Application.TopLevels.Peek () == OverlappedTop)
- {
- isOverlapped = true;
- }
- else if (isOverlapped && Application.TopLevels.Peek () == OverlappedTop)
- {
- MoveCurrent (Application.Top!);
-
- break;
- }
-
- Application.TopLevels.MovePrevious ();
- }
-
- Application.Current = Application.TopLevels.Peek ();
- }
- }
- }
-
- internal static bool OverlappedChildNeedsDisplay ()
- {
- if (OverlappedTop is null)
- {
- return false;
- }
-
- lock (Application.TopLevels)
- {
- foreach (Toplevel top in Application.TopLevels)
- {
- if (top != Application.Current && top.Visible && (top.NeedsDisplay || top.SubViewNeedsDisplay || top.LayoutNeeded))
- {
- OverlappedTop.SetSubViewNeedsDisplay ();
-
- return true;
- }
- }
- }
-
- return false;
- }
-
- internal static bool SetCurrentOverlappedAsTop ()
- {
- if (OverlappedTop is null && Application.Current != Application.Top && Application.Current?.SuperView is null && Application.Current?.Modal == false)
- {
- Application.Top = Application.Current;
-
- return true;
- }
-
- return false;
- }
-
- ///
- /// Finds the first Toplevel in the stack that is Visible and who's Frame contains the .
- ///
- ///
- ///
- ///
- internal static Toplevel? FindDeepestTop (Toplevel start, in Point location)
- {
- if (!start.Frame.Contains (location))
- {
- return null;
- }
-
- lock (Application.TopLevels)
- {
- if (Application.TopLevels is not { Count: > 0 })
- {
- return start;
- }
-
- int rx = location.X - start.Frame.X;
- int ry = location.Y - start.Frame.Y;
-
- foreach (Toplevel t in Application.TopLevels)
- {
- if (t == Application.Current)
- {
- continue;
- }
-
- if (t != start && t.Visible && t.Frame.Contains (rx, ry))
- {
- start = t;
-
- break;
- }
- }
- }
-
- return start;
- }
-
- ///
- /// Given , returns the first Superview up the chain that is .
- ///
- internal static View? FindTopFromView (View? view)
- {
- if (view is null)
- {
- return null;
- }
-
- View top = view.SuperView is { } && view.SuperView != Application.Top
- ? view.SuperView
- : view;
-
- while (top?.SuperView is { } && top?.SuperView != Application.Top)
- {
- top = top!.SuperView;
- }
-
- return top;
- }
-
- ///
- /// If the is not the then is moved to the top of
- /// the Toplevel stack and made Current.
- ///
- ///
- ///
- internal static bool MoveCurrent (Toplevel top)
- {
- // The Current is modal and the top is not modal Toplevel then
- // the Current must be moved above the first not modal Toplevel.
- if (OverlappedTop is { }
- && top != OverlappedTop
- && top != Application.Current
- && Application.Current?.Modal == true
- && !Application.TopLevels.Peek ().Modal)
- {
- lock (Application.TopLevels)
- {
- Application.TopLevels.MoveTo (Application.Current, 0, new ToplevelEqualityComparer ());
- }
-
- var index = 0;
- Toplevel [] savedToplevels = Application.TopLevels.ToArray ();
-
- foreach (Toplevel t in savedToplevels)
- {
- if (!t!.Modal && t != Application.Current && t != top && t != savedToplevels [index])
- {
- lock (Application.TopLevels)
- {
- Application.TopLevels.MoveTo (top, index, new ToplevelEqualityComparer ());
- }
- }
-
- index++;
- }
-
- return false;
- }
-
- // The Current and the top are both not running Toplevel then
- // the top must be moved above the first not running Toplevel.
- if (OverlappedTop is { }
- && top != OverlappedTop
- && top != Application.Current
- && Application.Current?.Running == false
- && top?.Running == false)
- {
- lock (Application.TopLevels)
- {
- Application.TopLevels.MoveTo (Application.Current, 0, new ToplevelEqualityComparer ());
- }
-
- var index = 0;
-
- foreach (Toplevel t in Application.TopLevels.ToArray ())
- {
- if (!t.Running && t != Application.Current && index > 0)
- {
- lock (Application.TopLevels)
- {
- Application.TopLevels.MoveTo (top, index - 1, new ToplevelEqualityComparer ());
- }
- }
-
- index++;
- }
-
- return false;
- }
-
- if ((OverlappedTop is { } && top?.Modal == true && Application.TopLevels.Peek () != top)
- || (OverlappedTop is { } && Application.Current != OverlappedTop && Application.Current?.Modal == false && top == OverlappedTop)
- || (OverlappedTop is { } && Application.Current?.Modal == false && top != Application.Current)
- || (OverlappedTop is { } && Application.Current?.Modal == true && top == OverlappedTop))
- {
- lock (Application.TopLevels)
- {
- Application.TopLevels.MoveTo (top!, 0, new ToplevelEqualityComparer ());
- Application.Current = top;
- }
- }
-
- return true;
- }
-}
diff --git a/Terminal.Gui/View/Adornment/Border.cs b/Terminal.Gui/View/Adornment/Border.cs
index 397c7b742..181526158 100644
--- a/Terminal.Gui/View/Adornment/Border.cs
+++ b/Terminal.Gui/View/Adornment/Border.cs
@@ -290,7 +290,6 @@ public class Border : Adornment
if (!_dragPosition.HasValue && mouseEvent.Flags.HasFlag (MouseFlags.Button1Pressed))
{
Parent!.SetFocus ();
- ApplicationOverlapped.BringOverlappedTopToFront ();
if (!Parent!.Arrangement.HasFlag (ViewArrangement.Movable)
&& !Parent!.Arrangement.HasFlag (ViewArrangement.BottomResizable)
@@ -580,6 +579,7 @@ public class Border : Adornment
break;
}
+ Application.Refresh ();
return true;
}
@@ -1260,6 +1260,8 @@ public class Border : Adornment
}
}
+ Application.Refresh ();
+
return true;
});
@@ -1282,6 +1284,8 @@ public class Border : Adornment
Parent!.Height = Parent.Height! + 1;
}
+ Application.Refresh ();
+
return true;
});
@@ -1307,6 +1311,8 @@ public class Border : Adornment
}
}
+ Application.Refresh ();
+
return true;
});
@@ -1329,6 +1335,8 @@ public class Border : Adornment
Parent!.Width = Parent.Width! + 1;
}
+ Application.Refresh ();
+
return true;
});
diff --git a/Terminal.Gui/View/View.Navigation.cs b/Terminal.Gui/View/View.Navigation.cs
index e1b652cbb..5a507b343 100644
--- a/Terminal.Gui/View/View.Navigation.cs
+++ b/Terminal.Gui/View/View.Navigation.cs
@@ -245,7 +245,7 @@ public partial class View // Focus and cross-view navigation management (TabStop
}
/// Returns a value indicating if this View is currently on Top (Active)
- public bool IsCurrentTop => Application.Current == this;
+ public bool IsCurrentTop => Application.Top == this;
///
/// Returns the most focused Subview down the subview-hierarchy.
@@ -609,12 +609,12 @@ public partial class View // Focus and cross-view navigation management (TabStop
newFocusedView = superViewOrParent;
}
- if (Application.Navigation is { } && Application.Current is { })
+ if (Application.Navigation is { } && Application.Top is { })
{
// Temporarily ensure this view can't get focus
bool prevCanFocus = _canFocus;
_canFocus = false;
- bool restoredFocus = Application.Current!.RestoreFocus ();
+ bool restoredFocus = Application.Top!.RestoreFocus ();
_canFocus = prevCanFocus;
if (restoredFocus)
diff --git a/Terminal.Gui/Views/Menu/ContextMenu.cs b/Terminal.Gui/Views/Menu/ContextMenu.cs
index 8751ada92..a963036dc 100644
--- a/Terminal.Gui/Views/Menu/ContextMenu.cs
+++ b/Terminal.Gui/Views/Menu/ContextMenu.cs
@@ -177,7 +177,7 @@ public sealed class ContextMenu : IDisposable
}
MenuItems = menuItems;
- _container = Application.Current;
+ _container = Application.Top;
_container!.Closing += Container_Closing;
_container.Deactivate += Container_Deactivate;
_container.Disposing += Container_Disposing;
diff --git a/Terminal.Gui/Views/Menu/Menu.cs b/Terminal.Gui/Views/Menu/Menu.cs
index d251a382a..f90107941 100644
--- a/Terminal.Gui/Views/Menu/Menu.cs
+++ b/Terminal.Gui/Views/Menu/Menu.cs
@@ -144,10 +144,10 @@ internal sealed class Menu : View
public Menu ()
{
- if (Application.Current is { })
+ if (Application.Top is { })
{
- Application.Current.DrawContentComplete += Current_DrawContentComplete;
- Application.Current.SizeChanging += Current_TerminalResized;
+ Application.Top.DrawContentComplete += Current_DrawContentComplete;
+ Application.Top.SizeChanging += Current_TerminalResized;
}
Application.MouseEvent += Application_RootMouseEvent;
@@ -607,6 +607,7 @@ internal sealed class Menu : View
Application.UngrabMouse ();
_host.CloseAllMenus ();
+ Application.Driver!.ClearContents ();
Application.Refresh ();
_host.Run (action);
@@ -952,10 +953,10 @@ internal sealed class Menu : View
{
RemoveKeyBindingsHotKey (_barItems);
- if (Application.Current is { })
+ if (Application.Top is { })
{
- Application.Current.DrawContentComplete -= Current_DrawContentComplete;
- Application.Current.SizeChanging -= Current_TerminalResized;
+ Application.Top.DrawContentComplete -= Current_DrawContentComplete;
+ Application.Top.SizeChanging -= Current_TerminalResized;
}
Application.MouseEvent -= Application_RootMouseEvent;
diff --git a/Terminal.Gui/Views/Menu/MenuBar.cs b/Terminal.Gui/Views/Menu/MenuBar.cs
index cbe3efd20..a0f79725e 100644
--- a/Terminal.Gui/Views/Menu/MenuBar.cs
+++ b/Terminal.Gui/Views/Menu/MenuBar.cs
@@ -402,7 +402,7 @@ public class MenuBar : View, IDesignable
_selected = 0;
SetNeedsDisplay ();
- _previousFocused = (SuperView is null ? Application.Current?.Focused : SuperView.Focused)!;
+ _previousFocused = (SuperView is null ? Application.Top?.Focused : SuperView.Focused)!;
OpenMenu (_selected);
if (!SelectEnabledItem (
@@ -463,7 +463,7 @@ public class MenuBar : View, IDesignable
if (_openMenu is null)
{
- _previousFocused = (SuperView is null ? Application.Current?.Focused ?? null : SuperView.Focused)!;
+ _previousFocused = (SuperView is null ? Application.Top?.Focused ?? null : SuperView.Focused)!;
}
OpenMenu (idx, sIdx, subMenu);
@@ -540,10 +540,10 @@ public class MenuBar : View, IDesignable
private void CloseOtherOpenedMenuBar ()
{
- if (Application.Current is { })
+ if (Application.Top is { })
{
// Close others menu bar opened
- Menu? menu = Application.Current.Subviews.FirstOrDefault (v => v is Menu m && m.Host != this && m.Host.IsMenuOpen) as Menu;
+ Menu? menu = Application.Top.Subviews.FirstOrDefault (v => v is Menu m && m.Host != this && m.Host.IsMenuOpen) as Menu;
menu?.Host.CleanUp ();
}
}
@@ -579,7 +579,7 @@ public class MenuBar : View, IDesignable
case false:
if (_openMenu is { })
{
- Application.Current?.Remove (_openMenu);
+ Application.Top?.Remove (_openMenu);
}
SetNeedsDisplay ();
@@ -614,7 +614,7 @@ public class MenuBar : View, IDesignable
if (OpenCurrentMenu is { })
{
- Application.Current?.Remove (OpenCurrentMenu);
+ Application.Top?.Remove (OpenCurrentMenu);
OpenCurrentMenu.Dispose ();
OpenCurrentMenu = null;
}
@@ -662,7 +662,7 @@ public class MenuBar : View, IDesignable
}
Rectangle superViewFrame = SuperView?.Frame ?? Application.Screen;
- View? sv = SuperView ?? Application.Current;
+ View? sv = SuperView ?? Application.Top;
if (sv is null)
{
@@ -789,7 +789,7 @@ public class MenuBar : View, IDesignable
{
case null:
// Open a submenu below a MenuBar
- _lastFocused ??= SuperView is null ? Application.Current?.MostFocused : SuperView.MostFocused;
+ _lastFocused ??= SuperView is null ? Application.Top?.MostFocused : SuperView.MostFocused;
if (_openSubMenu is { } && !CloseMenu (false, true))
{
@@ -798,7 +798,7 @@ public class MenuBar : View, IDesignable
if (_openMenu is { })
{
- Application.Current?.Remove (_openMenu);
+ Application.Top?.Remove (_openMenu);
_openMenu.Dispose ();
_openMenu = null;
}
@@ -818,7 +818,7 @@ public class MenuBar : View, IDesignable
locationOffset = GetScreenOffset ();
}
- if (SuperView is { } && SuperView != Application.Current)
+ if (SuperView is { } && SuperView != Application.Top)
{
locationOffset.X += SuperView.Border.Thickness.Left;
locationOffset.Y += SuperView.Border.Thickness.Top;
@@ -835,9 +835,9 @@ public class MenuBar : View, IDesignable
OpenCurrentMenu = _openMenu;
OpenCurrentMenu._previousSubFocused = _openMenu;
- if (Application.Current is { })
+ if (Application.Top is { })
{
- Application.Current.Add (_openMenu);
+ Application.Top.Add (_openMenu);
}
else
{
@@ -902,7 +902,7 @@ public class MenuBar : View, IDesignable
OpenCurrentMenu._previousSubFocused = last._previousSubFocused;
_openSubMenu.Add (OpenCurrentMenu);
- Application.Current?.Add (OpenCurrentMenu);
+ Application.Top?.Add (OpenCurrentMenu);
if (!OpenCurrentMenu.IsInitialized)
{
@@ -985,7 +985,7 @@ public class MenuBar : View, IDesignable
{
foreach (Menu item in _openSubMenu)
{
- Application.Current!.Remove (item);
+ Application.Top!.Remove (item);
item.Dispose ();
}
}
@@ -1224,7 +1224,7 @@ public class MenuBar : View, IDesignable
if (_openSubMenu is { })
{
menu = _openSubMenu [i];
- Application.Current!.Remove (menu);
+ Application.Top!.Remove (menu);
_openSubMenu.Remove (menu);
if (Application.MouseGrabView == menu)
diff --git a/Terminal.Gui/Views/Slider.cs b/Terminal.Gui/Views/Slider.cs
index b96d96a4a..47dd76d45 100644
--- a/Terminal.Gui/Views/Slider.cs
+++ b/Terminal.Gui/Views/Slider.cs
@@ -848,7 +848,7 @@ public class Slider : View, IOrientation
if (IsInitialized)
{
- normalAttr = ColorScheme?.Normal ?? Application.Current.ColorScheme.Normal;
+ normalAttr = ColorScheme?.Normal ?? Application.Top.ColorScheme.Normal;
setAttr = Style.SetChar.Attribute ?? ColorScheme!.HotNormal;
}
diff --git a/Terminal.Gui/Views/TileView.cs b/Terminal.Gui/Views/TileView.cs
index 698f67d43..b6e57dd90 100644
--- a/Terminal.Gui/Views/TileView.cs
+++ b/Terminal.Gui/Views/TileView.cs
@@ -916,7 +916,6 @@ public class TileView : View
{
// Start a Drag
SetFocus ();
- ApplicationOverlapped.BringOverlappedTopToFront ();
if (mouseEvent.Flags == MouseFlags.Button1Pressed)
{
diff --git a/Terminal.Gui/Views/Toplevel.cs b/Terminal.Gui/Views/Toplevel.cs
index a97bef473..07f4878cb 100644
--- a/Terminal.Gui/Views/Toplevel.cs
+++ b/Terminal.Gui/Views/Toplevel.cs
@@ -175,55 +175,7 @@ public partial class Toplevel : View
///
public virtual void RequestStop ()
{
- if (IsOverlappedContainer
- && Running
- && (Application.Current == this
- || Application.Current?.Modal == false
- || (Application.Current?.Modal == true && Application.Current?.Running == false)))
- {
- foreach (Toplevel child in ApplicationOverlapped.OverlappedChildren!)
- {
- var ev = new ToplevelClosingEventArgs (this);
-
- if (child.OnClosing (ev))
- {
- return;
- }
-
- child.Running = false;
- Application.RequestStop (child);
- }
-
- Running = false;
- Application.RequestStop (this);
- }
- else if (IsOverlappedContainer && Running && Application.Current?.Modal == true && Application.Current?.Running == true)
- {
- var ev = new ToplevelClosingEventArgs (Application.Current);
-
- if (OnClosing (ev))
- {
- return;
- }
-
- Application.RequestStop (Application.Current);
- }
- else if (!IsOverlappedContainer && Running && (!Modal || (Modal && Application.Current != this)))
- {
- var ev = new ToplevelClosingEventArgs (this);
-
- if (OnClosing (ev))
- {
- return;
- }
-
- Running = false;
- Application.RequestStop (this);
- }
- else
- {
- Application.RequestStop (Application.Current);
- }
+ Application.RequestStop (Application.Top);
}
///
@@ -246,11 +198,6 @@ public partial class Toplevel : View
internal virtual void OnChildClosed (Toplevel top)
{
- if (IsOverlappedContainer)
- {
- SetSubViewNeedsDisplay ();
- }
-
ChildClosed?.Invoke (this, new (top));
}
@@ -311,26 +258,8 @@ public partial class Toplevel : View
Clear ();
//LayoutSubviews ();
- PositionToplevels ();
-
- if (this == ApplicationOverlapped.OverlappedTop)
- {
- // This enables correct draw behavior when switching between overlapped subviews
- foreach (Toplevel top in ApplicationOverlapped.OverlappedChildren!.AsEnumerable ().Reverse ())
- {
- if (top.Frame.IntersectsWith (Viewport))
- {
- if (top != this && !top.IsCurrentTop && !OutsideTopFrame (top) && top.Visible)
- {
- top.SetNeedsLayout ();
- top.SetNeedsDisplay (top.Viewport);
- top.Draw ();
- top.OnRenderLineCanvas ();
- }
- }
- }
- }
-
+ //PositionToplevels ();
+
// BUGBUG: This appears to be a hack to get ScrollBarViews to render correctly.
foreach (View view in Subviews)
{
@@ -353,35 +282,6 @@ public partial class Toplevel : View
// TODO: Make cancelable?
internal virtual void OnSizeChanging (SizeChangedEventArgs size) { SizeChanging?.Invoke (this, size); }
- ///
- public override Point? PositionCursor ()
- {
- if (!IsOverlappedContainer)
- {
- return null;
- }
-
- // This code path only happens when the Toplevel is an Overlapped container
-
- if (Focused is null)
- {
- // TODO: this is an Overlapped hack
- foreach (Toplevel top in ApplicationOverlapped.OverlappedChildren!)
- {
- if (top != this && top.Visible)
- {
- top.SetFocus ();
-
- return null;
- }
- }
- }
-
- Point? cursor2 = base.PositionCursor ();
-
- return null;
- }
-
///
/// Adjusts the location and size of within this Toplevel. Virtual method enabling
/// implementation of specific positions for inherited views.
@@ -416,8 +316,10 @@ public partial class Toplevel : View
maxWidth -= superView.GetAdornmentsThickness ().Left + superView.GetAdornmentsThickness ().Right;
}
- if ((superView != top || top?.SuperView is { } || (top != Application.Top && top!.Modal) || (top?.SuperView is null && ApplicationOverlapped.IsOverlapped (top)))
+ // BUGBUG: The && true is a temp hack
+ if ((superView != top || top?.SuperView is { } || (top != Application.Top && top!.Modal) || (top == Application.Top && top?.SuperView is null))
&& (top!.Frame.X + top.Frame.Width > maxWidth || ny > top.Frame.Y))
+
{
if (top?.X is null or PosAbsolute && top?.Frame.X != nx)
{
@@ -470,6 +372,9 @@ public partial class Toplevel : View
// TODO: v2 - Not sure this is needed anymore.
internal void PositionToplevels ()
{
+ return;
+
+
PositionToplevel (this);
foreach (View top in Subviews)
diff --git a/Terminal.Gui/Views/ToplevelOverlapped.cs b/Terminal.Gui/Views/ToplevelOverlapped.cs
deleted file mode 100644
index 28513c4ce..000000000
--- a/Terminal.Gui/Views/ToplevelOverlapped.cs
+++ /dev/null
@@ -1,8 +0,0 @@
-namespace Terminal.Gui;
-
-public partial class Toplevel
-{
- /// Gets or sets if this Toplevel is a container for overlapped children.
- public bool IsOverlappedContainer { get; set; }
-}
-
diff --git a/UICatalog/Scenarios/BackgroundWorkerCollection.cs b/UICatalog/Scenarios/BackgroundWorkerCollection.cs
deleted file mode 100644
index 3522f059e..000000000
--- a/UICatalog/Scenarios/BackgroundWorkerCollection.cs
+++ /dev/null
@@ -1,540 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Collections.ObjectModel;
-using System.ComponentModel;
-using System.Diagnostics;
-using System.Threading;
-using Terminal.Gui;
-
-namespace UICatalog.Scenarios;
-
-[ScenarioMetadata ("BackgroundWorker Collection", "A persisting multi Toplevel BackgroundWorker threading")]
-[ScenarioCategory ("Threading")]
-[ScenarioCategory ("Overlapped")]
-[ScenarioCategory ("Runnable")]
-[ScenarioCategory ("Dialogs")]
-[ScenarioCategory ("Controls")]
-public class BackgroundWorkerCollection : Scenario
-{
- public override void Main ()
- {
- Application.Run ().Dispose ();
-
-#if DEBUG_IDISPOSABLE
- if (ApplicationOverlapped.OverlappedChildren is { })
- {
- Debug.Assert (ApplicationOverlapped.OverlappedChildren?.Count == 0);
- Debug.Assert (Application.Top == ApplicationOverlapped.OverlappedTop);
- }
-#endif
-
- Application.Shutdown ();
- }
-
- private class OverlappedMain : Toplevel
- {
- private readonly MenuBar _menu;
- private WorkerApp _workerApp;
-
- public OverlappedMain ()
- {
- Arrangement = ViewArrangement.Movable;
- Data = "OverlappedMain";
-
- IsOverlappedContainer = true;
-
- _workerApp = new WorkerApp { Visible = false };
- _workerApp.Border.Thickness = new (0, 1, 0, 0);
- _workerApp.Border.LineStyle = LineStyle.Dashed;
-
- _menu = new MenuBar
- {
- Menus =
- [
- new MenuBarItem (
- "_Options",
- new MenuItem []
- {
- new (
- "_Run Worker",
- "",
- () => _workerApp.RunWorker (),
- null,
- null,
- KeyCode.CtrlMask | KeyCode.R
- ),
- new (
- "_Cancel Worker",
- "",
- () => _workerApp.CancelWorker (),
- null,
- null,
- KeyCode.CtrlMask | KeyCode.C
- ),
- null,
- new (
- "_Quit",
- "",
- () => Quit (),
- null,
- null,
- Application.QuitKey
- )
- }
- ),
- new MenuBarItem ("_View", new MenuItem [] { }),
- new MenuBarItem ("_Window", new MenuItem [] { })
- ]
- };
- ;
- _menu.MenuOpening += Menu_MenuOpening;
- Add (_menu);
- var statusBar = new StatusBar (
- new []
- {
- new Shortcut (Application.QuitKey, $"Quit", Quit),
- new Shortcut (
- Key.R.WithCtrl,
- "Run Worker",
- () => _workerApp.RunWorker ()
- ),
- new Shortcut (
- Key.C.WithCtrl,
- "Cancel Worker",
- () => _workerApp.CancelWorker ()
- )
- }
- );
- Add (statusBar);
- Ready += OverlappedMain_Ready;
- Activate += OverlappedMain_Activate;
- Deactivate += OverlappedMain_Deactivate;
- }
-
- private void OverlappedMain_Ready (object sender, EventArgs e)
- {
- if (_workerApp?.Running == false)
- {
- Application.Run (_workerApp);
- }
- }
-
- private void Menu_MenuOpening (object sender, MenuOpeningEventArgs menu)
- {
- if (menu.CurrentMenu.Title == "_Window")
- {
- menu.NewMenuBarItem = OpenedWindows ();
- }
- else if (menu.CurrentMenu.Title == "_View")
- {
- menu.NewMenuBarItem = View ();
- }
- }
-
- private MenuBarItem OpenedWindows ()
- {
- var index = 1;
- List