diff --git a/Examples/CommunityToolkitExample/Program.cs b/Examples/CommunityToolkitExample/Program.cs index 74e45ce06..ab1357224 100644 --- a/Examples/CommunityToolkitExample/Program.cs +++ b/Examples/CommunityToolkitExample/Program.cs @@ -16,7 +16,7 @@ public static class Program Services = ConfigureServices (); Application.Init (); Application.Run (Services.GetRequiredService ()); - Application.Current?.Dispose (); + Application.TopRunnable?.Dispose (); Application.Shutdown (); } diff --git a/Examples/ReactiveExample/Program.cs b/Examples/ReactiveExample/Program.cs index f73aa807d..2dcb27b90 100644 --- a/Examples/ReactiveExample/Program.cs +++ b/Examples/ReactiveExample/Program.cs @@ -16,7 +16,7 @@ public static class Program RxApp.MainThreadScheduler = TerminalScheduler.Default; RxApp.TaskpoolScheduler = TaskPoolScheduler.Default; Application.Run (new LoginView (new LoginViewModel ())); - Application.Current.Dispose (); + Application.TopRunnable.Dispose (); Application.Shutdown (); } } diff --git a/Examples/UICatalog/Scenario.cs b/Examples/UICatalog/Scenario.cs index 0531d06c9..0fa13e6db 100644 --- a/Examples/UICatalog/Scenario.cs +++ b/Examples/UICatalog/Scenario.cs @@ -221,7 +221,7 @@ public class Scenario : IDisposable private void OnApplicationSessionBegun (object? sender, SessionTokenEventArgs e) { - SubscribeAllSubViews (Application.Current!); + SubscribeAllSubViews (Application.TopRunnable!); _demoKeys = GetDemoKeyStrokes (); @@ -241,7 +241,7 @@ public class Scenario : IDisposable return; - // Get a list of all subviews under Application.Current (and their subviews, etc.) + // Get a list of all subviews under Application.TopRunnable (and their subviews, etc.) // and subscribe to their DrawComplete event void SubscribeAllSubViews (View view) { diff --git a/Examples/UICatalog/Scenarios/AllViewsTester.cs b/Examples/UICatalog/Scenarios/AllViewsTester.cs index 5ac97bea9..aae301c3a 100644 --- a/Examples/UICatalog/Scenarios/AllViewsTester.cs +++ b/Examples/UICatalog/Scenarios/AllViewsTester.cs @@ -28,7 +28,7 @@ public class AllViewsTester : Scenario public override void Main () { - // Don't create a sub-win (Scenario.Win); just use Application.Current + // Don't create a sub-win (Scenario.Win); just use Application.TopRunnable Application.Init (); var app = new Window diff --git a/Examples/UICatalog/Scenarios/Bars.cs b/Examples/UICatalog/Scenarios/Bars.cs index 03f908611..730ddf969 100644 --- a/Examples/UICatalog/Scenarios/Bars.cs +++ b/Examples/UICatalog/Scenarios/Bars.cs @@ -28,7 +28,7 @@ public class Bars : Scenario // QuitKey and it only sticks if changed after init private void App_Loaded (object sender, EventArgs e) { - Application.Current!.Title = GetQuitKeyAndName (); + Application.TopRunnable!.Title = GetQuitKeyAndName (); ObservableCollection eventSource = new (); ListView eventLog = new ListView () @@ -41,7 +41,7 @@ public class Bars : Scenario Source = new ListWrapper (eventSource) }; eventLog.Border!.Thickness = new (0, 1, 0, 0); - Application.Current.Add (eventLog); + Application.TopRunnable.Add (eventLog); FrameView menuBarLikeExamples = new () { @@ -51,7 +51,7 @@ public class Bars : Scenario Width = Dim.Fill () - Dim.Width (eventLog), Height = Dim.Percent(33), }; - Application.Current.Add (menuBarLikeExamples); + Application.TopRunnable.Add (menuBarLikeExamples); Label label = new Label () { @@ -98,7 +98,7 @@ public class Bars : Scenario Width = Dim.Fill () - Dim.Width (eventLog), Height = Dim.Percent (33), }; - Application.Current.Add (menuLikeExamples); + Application.TopRunnable.Add (menuLikeExamples); label = new Label () { @@ -212,7 +212,7 @@ public class Bars : Scenario Width = Dim.Width (menuLikeExamples), Height = Dim.Percent (33), }; - Application.Current.Add (statusBarLikeExamples); + Application.TopRunnable.Add (statusBarLikeExamples); label = new Label () { @@ -249,7 +249,7 @@ public class Bars : Scenario ConfigStatusBar (bar); statusBarLikeExamples.Add (bar); - foreach (FrameView frameView in Application.Current.SubViews.Where (f => f is FrameView)!) + foreach (FrameView frameView in Application.TopRunnable.SubViews.Where (f => f is FrameView)!) { foreach (Bar barView in frameView.SubViews.Where (b => b is Bar)!) { @@ -269,8 +269,8 @@ public class Bars : Scenario //private void SetupContentMenu () //{ - // Application.Current.Add (new Label { Text = "Right Click for Context Menu", X = Pos.Center (), Y = 4 }); - // Application.Current.MouseClick += ShowContextMenu; + // Application.TopRunnable.Add (new Label { Text = "Right Click for Context Menu", X = Pos.Center (), Y = 4 }); + // Application.TopRunnable.MouseClick += ShowContextMenu; //} //private void ShowContextMenu (object s, MouseEventEventArgs e) diff --git a/Examples/UICatalog/Scenarios/CombiningMarks.cs b/Examples/UICatalog/Scenarios/CombiningMarks.cs index 62181c500..5a729760e 100644 --- a/Examples/UICatalog/Scenarios/CombiningMarks.cs +++ b/Examples/UICatalog/Scenarios/CombiningMarks.cs @@ -13,7 +13,7 @@ public class CombiningMarks : Scenario top.DrawComplete += (s, e) => { // Forces reset _lineColsOffset because we're dealing with direct draw - Application.Current!.SetNeedsDraw (); + Application.TopRunnable!.SetNeedsDraw (); var i = -1; top.Move (0, ++i); diff --git a/Examples/UICatalog/Scenarios/ConfigurationEditor.cs b/Examples/UICatalog/Scenarios/ConfigurationEditor.cs index 36011a78c..c0bfcb03d 100644 --- a/Examples/UICatalog/Scenarios/ConfigurationEditor.cs +++ b/Examples/UICatalog/Scenarios/ConfigurationEditor.cs @@ -75,7 +75,7 @@ public class ConfigurationEditor : Scenario void ConfigurationManagerOnApplied (object? sender, ConfigurationManagerEventArgs e) { - Application.Current?.SetNeedsDraw (); + Application.TopRunnable?.SetNeedsDraw (); } } public void Save () diff --git a/Examples/UICatalog/Scenarios/CsvEditor.cs b/Examples/UICatalog/Scenarios/CsvEditor.cs index aca10fdac..f61d03b14 100644 --- a/Examples/UICatalog/Scenarios/CsvEditor.cs +++ b/Examples/UICatalog/Scenarios/CsvEditor.cs @@ -502,7 +502,7 @@ public class CsvEditor : Scenario // Only set the current filename if we successfully loaded the entire file _currentFile = filename; _selectedCellTextField.SuperView.Enabled = true; - Application.Current.Title = $"{GetName ()} - {Path.GetFileName (_currentFile)}"; + Application.TopRunnable.Title = $"{GetName ()} - {Path.GetFileName (_currentFile)}"; } catch (Exception ex) { diff --git a/Examples/UICatalog/Scenarios/Mazing.cs b/Examples/UICatalog/Scenarios/Mazing.cs index 935c72ae5..04cca789d 100644 --- a/Examples/UICatalog/Scenarios/Mazing.cs +++ b/Examples/UICatalog/Scenarios/Mazing.cs @@ -171,7 +171,7 @@ public class Mazing : Scenario if (_m.PlayerHp <= 0) { _message = "You died!"; - Application.Current!.SetNeedsDraw (); // trigger redraw + Application.TopRunnable!.SetNeedsDraw (); // trigger redraw _dead = true; return; // Stop further action if dead @@ -190,7 +190,7 @@ public class Mazing : Scenario _message = string.Empty; } - Application.Current!.SetNeedsDraw (); // trigger redraw + Application.TopRunnable!.SetNeedsDraw (); // trigger redraw } // Optional win condition: @@ -200,7 +200,7 @@ public class Mazing : Scenario _m = new (); // Generate a new maze _m.PlayerHp = hp; GenerateNpcs (); - Application.Current!.SetNeedsDraw (); // trigger redraw + Application.TopRunnable!.SetNeedsDraw (); // trigger redraw } } } diff --git a/Examples/UICatalog/Scenarios/Shortcuts.cs b/Examples/UICatalog/Scenarios/Shortcuts.cs index 331ed0337..573834aa3 100644 --- a/Examples/UICatalog/Scenarios/Shortcuts.cs +++ b/Examples/UICatalog/Scenarios/Shortcuts.cs @@ -28,7 +28,7 @@ public class Shortcuts : Scenario private void App_Loaded (object? sender, EventArgs e) { Application.QuitKey = Key.F4.WithCtrl; - Application.Current!.Title = GetQuitKeyAndName (); + Application.TopRunnable!.Title = GetQuitKeyAndName (); ObservableCollection eventSource = new (); @@ -46,14 +46,14 @@ public class Shortcuts : Scenario eventLog.Width = Dim.Func ( _ => Math.Min ( - Application.Current.Viewport.Width / 2, + Application.TopRunnable.Viewport.Width / 2, eventLog?.MaxLength + eventLog!.GetAdornmentsThickness ().Horizontal ?? 0)); eventLog.Width = Dim.Func ( _ => Math.Min ( eventLog.SuperView!.Viewport.Width / 2, eventLog?.MaxLength + eventLog!.GetAdornmentsThickness ().Horizontal ?? 0)); - Application.Current.Add (eventLog); + Application.TopRunnable.Add (eventLog); var alignKeysShortcut = new Shortcut { @@ -86,7 +86,7 @@ public class Shortcuts : Scenario }; - Application.Current.Add (alignKeysShortcut); + Application.TopRunnable.Add (alignKeysShortcut); var commandFirstShortcut = new Shortcut { @@ -115,7 +115,7 @@ public class Shortcuts : Scenario $"{commandFirstShortcut.Id}.CommandView.CheckedStateChanging: {cb.Text}"); eventLog.MoveDown (); - IEnumerable toAlign = Application.Current.SubViews.OfType (); + IEnumerable toAlign = Application.TopRunnable.SubViews.OfType (); IEnumerable enumerable = toAlign as View [] ?? toAlign.ToArray (); foreach (View view in enumerable) @@ -134,7 +134,7 @@ public class Shortcuts : Scenario } }; - Application.Current.Add (commandFirstShortcut); + Application.TopRunnable.Add (commandFirstShortcut); var canFocusShortcut = new Shortcut { @@ -159,7 +159,7 @@ public class Shortcuts : Scenario SetCanFocus (e.Result == CheckState.Checked); } }; - Application.Current.Add (canFocusShortcut); + Application.TopRunnable.Add (canFocusShortcut); var appShortcut = new Shortcut { @@ -173,7 +173,7 @@ public class Shortcuts : Scenario BindKeyToApplication = true }; - Application.Current.Add (appShortcut); + Application.TopRunnable.Add (appShortcut); var buttonShortcut = new Shortcut { @@ -193,7 +193,7 @@ public class Shortcuts : Scenario var button = (Button)buttonShortcut.CommandView; buttonShortcut.Accepting += Button_Clicked; - Application.Current.Add (buttonShortcut); + Application.TopRunnable.Add (buttonShortcut); var optionSelectorShortcut = new Shortcut { @@ -221,7 +221,7 @@ public class Shortcuts : Scenario } }; - Application.Current.Add (optionSelectorShortcut); + Application.TopRunnable.Add (optionSelectorShortcut); var sliderShortcut = new Shortcut { @@ -248,7 +248,7 @@ public class Shortcuts : Scenario eventLog.MoveDown (); }; - Application.Current.Add (sliderShortcut); + Application.TopRunnable.Add (sliderShortcut); ListView listView = new ListView () { @@ -270,7 +270,7 @@ public class Shortcuts : Scenario Key = Key.F5.WithCtrl, }; - Application.Current.Add (listViewShortcut); + Application.TopRunnable.Add (listViewShortcut); var noCommandShortcut = new Shortcut { @@ -282,7 +282,7 @@ public class Shortcuts : Scenario Key = Key.D0 }; - Application.Current.Add (noCommandShortcut); + Application.TopRunnable.Add (noCommandShortcut); var noKeyShortcut = new Shortcut { @@ -295,7 +295,7 @@ public class Shortcuts : Scenario HelpText = "Keyless" }; - Application.Current.Add (noKeyShortcut); + Application.TopRunnable.Add (noKeyShortcut); var noHelpShortcut = new Shortcut { @@ -308,7 +308,7 @@ public class Shortcuts : Scenario HelpText = "" }; - Application.Current.Add (noHelpShortcut); + Application.TopRunnable.Add (noHelpShortcut); noHelpShortcut.SetFocus (); var framedShortcut = new Shortcut @@ -340,7 +340,7 @@ public class Shortcuts : Scenario } framedShortcut.SchemeName = SchemeManager.SchemesToSchemeName (Schemes.Toplevel); - Application.Current.Add (framedShortcut); + Application.TopRunnable.Add (framedShortcut); // Horizontal var progressShortcut = new Shortcut @@ -387,7 +387,7 @@ public class Shortcuts : Scenario }; timer.Start (); - Application.Current.Add (progressShortcut); + Application.TopRunnable.Add (progressShortcut); var textField = new TextField { @@ -408,7 +408,7 @@ public class Shortcuts : Scenario }; textField.CanFocus = true; - Application.Current.Add (textFieldShortcut); + Application.TopRunnable.Add (textFieldShortcut); var bgColorShortcut = new Shortcut { @@ -450,19 +450,19 @@ public class Shortcuts : Scenario eventSource.Add ($"ColorChanged: {o.GetType ().Name} - {args.Result}"); eventLog.MoveDown (); - Application.Current.SetScheme ( - new (Application.Current.GetScheme ()) + Application.TopRunnable.SetScheme ( + new (Application.TopRunnable.GetScheme ()) { Normal = new ( - Application.Current!.GetAttributeForRole (VisualRole.Normal).Foreground, + Application.TopRunnable!.GetAttributeForRole (VisualRole.Normal).Foreground, args.Result, - Application.Current!.GetAttributeForRole (VisualRole.Normal).Style) + Application.TopRunnable!.GetAttributeForRole (VisualRole.Normal).Style) }); } }; bgColorShortcut.CommandView = bgColor; - Application.Current.Add (bgColorShortcut); + Application.TopRunnable.Add (bgColorShortcut); var appQuitShortcut = new Shortcut { @@ -476,9 +476,9 @@ public class Shortcuts : Scenario }; appQuitShortcut.Accepting += (o, args) => { Application.RequestStop (); }; - Application.Current.Add (appQuitShortcut); + Application.TopRunnable.Add (appQuitShortcut); - foreach (Shortcut shortcut in Application.Current.SubViews.OfType ()) + foreach (Shortcut shortcut in Application.TopRunnable.SubViews.OfType ()) { shortcut.Selecting += (o, args) => { @@ -529,7 +529,7 @@ public class Shortcuts : Scenario void SetCanFocus (bool canFocus) { - foreach (Shortcut peer in Application.Current!.SubViews.OfType ()) + foreach (Shortcut peer in Application.TopRunnable!.SubViews.OfType ()) { if (peer.CanFocus) { @@ -542,7 +542,7 @@ public class Shortcuts : Scenario { var max = 0; - IEnumerable toAlign = Application.Current!.SubViews.OfType ().Where(s => !s.Y.Has(out _)).Cast(); + IEnumerable toAlign = Application.TopRunnable!.SubViews.OfType ().Where(s => !s.Y.Has(out _)).Cast(); IEnumerable enumerable = toAlign as Shortcut [] ?? toAlign.ToArray (); if (align) diff --git a/Examples/UICatalog/Scenarios/SingleBackgroundWorker.cs b/Examples/UICatalog/Scenarios/SingleBackgroundWorker.cs index 571597f8c..92e126b84 100644 --- a/Examples/UICatalog/Scenarios/SingleBackgroundWorker.cs +++ b/Examples/UICatalog/Scenarios/SingleBackgroundWorker.cs @@ -179,9 +179,9 @@ public class SingleBackgroundWorker : Scenario var builderUI = new StagingUIController (_startStaging, e.Result as ObservableCollection); - Toplevel top = Application.Current; + Toplevel top = Application.TopRunnable; top.Visible = false; - Application.Current.Visible = false; + Application.TopRunnable.Visible = false; builderUI.Load (); builderUI.Dispose (); top.Visible = true; diff --git a/Examples/UICatalog/Scenarios/Themes.cs b/Examples/UICatalog/Scenarios/Themes.cs index d515b5ee0..68d73ed40 100644 --- a/Examples/UICatalog/Scenarios/Themes.cs +++ b/Examples/UICatalog/Scenarios/Themes.cs @@ -129,7 +129,7 @@ public sealed class Themes : Scenario { if (_view is { }) { - Application.Current!.SchemeName = args.NewValue; + Application.TopRunnable!.SchemeName = args.NewValue; if (_view.HasScheme) { diff --git a/Examples/UICatalog/Scenarios/TreeUseCases.cs b/Examples/UICatalog/Scenarios/TreeUseCases.cs index d9ee48d15..021b5b65b 100644 --- a/Examples/UICatalog/Scenarios/TreeUseCases.cs +++ b/Examples/UICatalog/Scenarios/TreeUseCases.cs @@ -77,7 +77,7 @@ public class TreeUseCases : Scenario if (_currentTree != null) { - Application.Current.Remove (_currentTree); + Application.TopRunnable.Remove (_currentTree); _currentTree.Dispose (); } @@ -97,7 +97,7 @@ public class TreeUseCases : Scenario tree.TreeBuilder = new GameObjectTreeBuilder (); } - Application.Current.Add (tree); + Application.TopRunnable.Add (tree); tree.AddObject (army1); @@ -117,13 +117,13 @@ public class TreeUseCases : Scenario if (_currentTree != null) { - Application.Current.Remove (_currentTree); + Application.TopRunnable.Remove (_currentTree); _currentTree.Dispose (); } var tree = new TreeView { X = 0, Y = 1, Width = Dim.Fill(), Height = Dim.Fill (1) }; - Application.Current.Add (tree); + Application.TopRunnable.Add (tree); tree.AddObject (myHouse); @@ -134,13 +134,13 @@ public class TreeUseCases : Scenario { if (_currentTree != null) { - Application.Current.Remove (_currentTree); + Application.TopRunnable.Remove (_currentTree); _currentTree.Dispose (); } var tree = new TreeView { X = 0, Y = 1, Width = Dim.Fill (), Height = Dim.Fill (1) }; - Application.Current.Add (tree); + Application.TopRunnable.Add (tree); var root1 = new TreeNode ("Root1"); root1.Children.Add (new TreeNode ("Child1.1")); diff --git a/Examples/UICatalog/Scenarios/WindowsAndFrameViews.cs b/Examples/UICatalog/Scenarios/WindowsAndFrameViews.cs index afe039f1c..d2b58d847 100644 --- a/Examples/UICatalog/Scenarios/WindowsAndFrameViews.cs +++ b/Examples/UICatalog/Scenarios/WindowsAndFrameViews.cs @@ -69,7 +69,7 @@ public class WindowsAndFrameViews : Scenario // add it to our list listWin.Add (win); - // create 3 more Windows in a loop, adding them Application.Current + // create 3 more Windows in a loop, adding them Application.TopRunnable // Each with a // button // sub Window with diff --git a/Examples/UICatalog/UICatalog.cs b/Examples/UICatalog/UICatalog.cs index 8b8eeca71..884e65fd1 100644 --- a/Examples/UICatalog/UICatalog.cs +++ b/Examples/UICatalog/UICatalog.cs @@ -246,7 +246,7 @@ public class UICatalog /// /// Shows the UI Catalog selection UI. When the user selects a Scenario to run, the UI Catalog main app UI is - /// killed and the Scenario is run as though it were Application.Current. When the Scenario exits, this function exits. + /// killed and the Scenario is run as though it were Application.TopRunnable. When the Scenario exits, this function exits. /// /// private static Scenario RunUICatalogTopLevel () @@ -347,7 +347,7 @@ public class UICatalog private static void ConfigFileChanged (object sender, FileSystemEventArgs e) { - if (Application.Current == null) + if (Application.TopRunnable == null) { return; } diff --git a/Examples/UICatalog/UICatalogTop.cs b/Examples/UICatalog/UICatalogTop.cs index 63c3eb528..304876a87 100644 --- a/Examples/UICatalog/UICatalogTop.cs +++ b/Examples/UICatalog/UICatalogTop.cs @@ -700,7 +700,7 @@ public class UICatalogTop : Toplevel _disableMouseCb!.CheckedState = Application.IsMouseDisabled ? CheckState.Checked : CheckState.UnChecked; _force16ColorsShortcutCb!.CheckedState = Application.Force16Colors ? CheckState.Checked : CheckState.UnChecked; - Application.Current?.SetNeedsDraw (); + Application.TopRunnable?.SetNeedsDraw (); } private void ConfigAppliedHandler (object? sender, ConfigurationManagerEventArgs? a) { ConfigApplied (); } diff --git a/Terminal.Gui/App/Application.Current.cs b/Terminal.Gui/App/Application.Current.cs index e94d074e7..1b91a45ff 100644 --- a/Terminal.Gui/App/Application.Current.cs +++ b/Terminal.Gui/App/Application.Current.cs @@ -7,12 +7,12 @@ public static partial class Application // Current handling /// [Obsolete ("The legacy static Application object is going away.")] public static ConcurrentStack SessionStack => ApplicationImpl.Instance.SessionStack; - /// The that is currently active. - /// The current toplevel. + /// The that is on the top of the . + /// The top runnable. [Obsolete ("The legacy static Application object is going away.")] - public static Toplevel? Current + public static Toplevel? TopRunnable { - get => ApplicationImpl.Instance.Current; - internal set => ApplicationImpl.Instance.Current = value; + get => ApplicationImpl.Instance.TopRunnable; + internal set => ApplicationImpl.Instance.TopRunnable = value; } } diff --git a/Terminal.Gui/App/ApplicationImpl.Lifecycle.cs b/Terminal.Gui/App/ApplicationImpl.Lifecycle.cs index e20fd7ce8..3e08a3f72 100644 --- a/Terminal.Gui/App/ApplicationImpl.Lifecycle.cs +++ b/Terminal.Gui/App/ApplicationImpl.Lifecycle.cs @@ -178,21 +178,21 @@ public partial class ApplicationImpl #if DEBUG_IDISPOSABLE - // Don't dispose the Current. It's up to caller dispose it - if (View.EnableDebugIDisposableAsserts && !ignoreDisposed && Current is { }) + // Don't dispose the TopRunnable. It's up to caller dispose it + if (View.EnableDebugIDisposableAsserts && !ignoreDisposed && TopRunnable is { }) { - Debug.Assert (Current.WasDisposed, $"Title = {Current.Title}, Id = {Current.Id}"); + Debug.Assert (TopRunnable.WasDisposed, $"Title = {TopRunnable.Title}, Id = {TopRunnable.Id}"); // If End wasn't called _CachedSessionTokenToplevel may be null if (CachedSessionTokenToplevel is { }) { Debug.Assert (CachedSessionTokenToplevel.WasDisposed); - Debug.Assert (CachedSessionTokenToplevel == Current); + Debug.Assert (CachedSessionTokenToplevel == TopRunnable); } } #endif - Current = null; + TopRunnable = null; CachedSessionTokenToplevel = null; // === 4. Clean up driver === diff --git a/Terminal.Gui/App/ApplicationImpl.Run.cs b/Terminal.Gui/App/ApplicationImpl.Run.cs index 4e9f59645..f5b785eb2 100644 --- a/Terminal.Gui/App/ApplicationImpl.Run.cs +++ b/Terminal.Gui/App/ApplicationImpl.Run.cs @@ -36,28 +36,28 @@ public partial class ApplicationImpl var rs = new SessionToken (toplevel); #if DEBUG_IDISPOSABLE - if (View.EnableDebugIDisposableAsserts && Current is { } && toplevel != Current && !SessionStack.Contains (Current)) + if (View.EnableDebugIDisposableAsserts && TopRunnable is { } && toplevel != TopRunnable && !SessionStack.Contains (TopRunnable)) { - // This assertion confirm if the Current was already disposed - Debug.Assert (Current.WasDisposed); - Debug.Assert (Current == CachedSessionTokenToplevel); + // This assertion confirm if the TopRunnable was already disposed + Debug.Assert (TopRunnable.WasDisposed); + Debug.Assert (TopRunnable == CachedSessionTokenToplevel); } #endif lock (SessionStack) { - if (Current is { } && toplevel != Current && !SessionStack.Contains (Current)) + if (TopRunnable is { } && toplevel != TopRunnable && !SessionStack.Contains (TopRunnable)) { - // If Current was already disposed and isn't on the Toplevels Stack, + // If TopRunnable was already disposed and isn't on the Toplevels Stack, // clean it up here if is the same as _CachedSessionTokenToplevel - if (Current == CachedSessionTokenToplevel) + if (TopRunnable == CachedSessionTokenToplevel) { - Current = null; + TopRunnable = null; } else { // Probably this will never hit - throw new ObjectDisposedException (Current.GetType ().FullName); + throw new ObjectDisposedException (TopRunnable.GetType ().FullName); } } @@ -89,35 +89,35 @@ public partial class ApplicationImpl } } - if (Current is null) + if (TopRunnable is null) { toplevel.App = this; - Current = toplevel; + TopRunnable = toplevel; } - if ((Current?.Modal == false && toplevel.Modal) - || (Current?.Modal == false && !toplevel.Modal) - || (Current?.Modal == true && toplevel.Modal)) + if ((TopRunnable?.Modal == false && toplevel.Modal) + || (TopRunnable?.Modal == false && !toplevel.Modal) + || (TopRunnable?.Modal == true && toplevel.Modal)) { if (toplevel.Visible) { - if (Current is { HasFocus: true }) + if (TopRunnable is { HasFocus: true }) { - Current.HasFocus = false; + TopRunnable.HasFocus = false; } - // Force leave events for any entered views in the old Current + // Force leave events for any entered views in the old TopRunnable if (Mouse.LastMousePosition is { }) { Mouse.RaiseMouseEnterLeaveEvents (Mouse.LastMousePosition!.Value, new ()); } - Current?.OnDeactivate (toplevel); - Toplevel previousTop = Current!; + TopRunnable?.OnDeactivate (toplevel); + Toplevel previousTop = TopRunnable!; - Current = toplevel; - Current.App = this; - Current.OnActivate (previousTop); + TopRunnable = toplevel; + TopRunnable.App = this; + TopRunnable.OnActivate (previousTop); } } @@ -194,11 +194,11 @@ public partial class ApplicationImpl throw new InvalidOperationException ("Driver was inexplicably null when trying to Run view"); } - Current = view; + TopRunnable = view; SessionToken rs = Begin (view); - Current.Running = true; + TopRunnable.Running = true; var firstIteration = true; @@ -254,8 +254,8 @@ public partial class ApplicationImpl if (SessionStack.TryPeek (out Toplevel? newTop)) { newTop.App = this; - Current = newTop; - Current?.SetNeedsDraw (); + TopRunnable = newTop; + TopRunnable?.SetNeedsDraw (); } if (sessionToken.Toplevel is { HasFocus: true }) @@ -263,9 +263,9 @@ public partial class ApplicationImpl sessionToken.Toplevel.HasFocus = false; } - if (Current is { HasFocus: false }) + if (TopRunnable is { HasFocus: false }) { - Current.SetFocus (); + TopRunnable.SetFocus (); } CachedSessionTokenToplevel = sessionToken.Toplevel; @@ -285,9 +285,9 @@ public partial class ApplicationImpl /// public void RequestStop (Toplevel? top) { - Logging.Trace ($"Current: '{(top is { } ? top : "null")}'"); + Logging.Trace ($"TopRunnable: '{(top is { } ? top : "null")}'"); - top ??= Current; + top ??= TopRunnable; if (top == null) { @@ -327,7 +327,7 @@ public partial class ApplicationImpl public void Invoke (Action? action) { // If we are already on the main UI thread - if (Current is { Running: true } && MainThreadId == Thread.CurrentThread.ManagedThreadId) + if (TopRunnable is { Running: true } && MainThreadId == Thread.CurrentThread.ManagedThreadId) { action?.Invoke (this); @@ -350,7 +350,7 @@ public partial class ApplicationImpl public void Invoke (Action action) { // If we are already on the main UI thread - if (Current is { Running: true } && MainThreadId == Thread.CurrentThread.ManagedThreadId) + if (TopRunnable is { Running: true } && MainThreadId == Thread.CurrentThread.ManagedThreadId) { action?.Invoke (); diff --git a/Terminal.Gui/App/ApplicationImpl.cs b/Terminal.Gui/App/ApplicationImpl.cs index bcedf0b14..1aca088dd 100644 --- a/Terminal.Gui/App/ApplicationImpl.cs +++ b/Terminal.Gui/App/ApplicationImpl.cs @@ -121,19 +121,19 @@ public partial class ApplicationImpl : IApplication set => _navigation = value ?? throw new ArgumentNullException (nameof (value)); } - private Toplevel? _current; + private Toplevel? _topRunnable; /// - public Toplevel? Current + public Toplevel? TopRunnable { - get => _current; + get => _topRunnable; set { - _current = value; + _topRunnable = value; - if (_current is { }) + if (_topRunnable is { }) { - _current.App = this; + _topRunnable.App = this; } } } diff --git a/Terminal.Gui/App/ApplicationNavigation.cs b/Terminal.Gui/App/ApplicationNavigation.cs index d0ef40d9c..1149c3ad6 100644 --- a/Terminal.Gui/App/ApplicationNavigation.cs +++ b/Terminal.Gui/App/ApplicationNavigation.cs @@ -113,6 +113,6 @@ public class ApplicationNavigation { return visiblePopover.AdvanceFocus (direction, behavior); } - return App?.Current is { } && App.Current.AdvanceFocus (direction, behavior); + return App?.TopRunnable is { } && App.TopRunnable.AdvanceFocus (direction, behavior); } } diff --git a/Terminal.Gui/App/ApplicationPopover.cs b/Terminal.Gui/App/ApplicationPopover.cs index 72f9957df..3a7aac879 100644 --- a/Terminal.Gui/App/ApplicationPopover.cs +++ b/Terminal.Gui/App/ApplicationPopover.cs @@ -41,8 +41,8 @@ public sealed class ApplicationPopover : IDisposable { if (popover is { } && !IsRegistered (popover)) { - // When created, set IPopover.Toplevel to the current Application.Current - popover.Current ??= App?.Current; + // When created, set IPopover.Toplevel to the current Application.TopRunnable + popover.Current ??= App?.TopRunnable; if (popover is View popoverView) { @@ -166,7 +166,7 @@ public sealed class ApplicationPopover : IDisposable { _activePopover = null; popoverView.Visible = false; - popoverView.App?.Current?.SetNeedsDraw (); + popoverView.App?.TopRunnable?.SetNeedsDraw (); } } @@ -215,7 +215,7 @@ public sealed class ApplicationPopover : IDisposable { if (popover == activePopover || popover is not View popoverView - || (popover.Current is { } && popover.Current != App?.Current)) + || (popover.Current is { } && popover.Current != App?.TopRunnable)) { continue; } diff --git a/Terminal.Gui/App/IApplication.cs b/Terminal.Gui/App/IApplication.cs index c02563170..a14f3534b 100644 --- a/Terminal.Gui/App/IApplication.cs +++ b/Terminal.Gui/App/IApplication.cs @@ -301,14 +301,14 @@ public interface IApplication /// /// This will cause to return. /// - /// This is equivalent to calling with as the parameter. + /// This is equivalent to calling with as the parameter. /// /// void RequestStop (); /// Requests that the currently running Session stop. The Session will stop after the current iteration completes. /// - /// The to stop. If , stops the currently running . + /// The to stop. If , stops the currently running . /// /// /// This will cause to return. @@ -356,13 +356,14 @@ public interface IApplication #region Toplevel Management - /// Gets or sets the currently active Toplevel. + /// Gets or sets the Toplevel that is on the top of the . /// /// + /// The top runnable in the session stack captures all mouse and keyboard input. /// This is set by and cleared by . /// /// - Toplevel? Current { get; set; } + Toplevel? TopRunnable { get; set; } /// Gets the stack of all active Toplevel sessions. /// @@ -433,7 +434,7 @@ public interface IApplication /// /// /// This is typically set to when a View's changes and that view - /// has no SuperView (e.g. when is moved or resized). + /// has no SuperView (e.g. when is moved or resized). /// /// /// Automatically reset to after processes it. diff --git a/Terminal.Gui/App/IPopover.cs b/Terminal.Gui/App/IPopover.cs index 87218d07a..816c69613 100644 --- a/Terminal.Gui/App/IPopover.cs +++ b/Terminal.Gui/App/IPopover.cs @@ -55,7 +55,7 @@ public interface IPopover /// events from the . If set, it will only receive keyboard events the Toplevel would normally /// receive. /// When is called, the is set to the current - /// if not already set. + /// if not already set. /// Toplevel? Current { get; set; } } diff --git a/Terminal.Gui/App/Keyboard/KeyboardImpl.cs b/Terminal.Gui/App/Keyboard/KeyboardImpl.cs index e1be672e5..75c37d4b8 100644 --- a/Terminal.Gui/App/Keyboard/KeyboardImpl.cs +++ b/Terminal.Gui/App/Keyboard/KeyboardImpl.cs @@ -138,7 +138,7 @@ internal class KeyboardImpl : IKeyboard return true; } - if (App?.Current is null) + if (App?.TopRunnable is null) { if (App?.SessionStack is { }) { @@ -158,7 +158,7 @@ internal class KeyboardImpl : IKeyboard } else { - if (App.Current.NewKeyDownEvent (key)) + if (App.TopRunnable.NewKeyDownEvent (key)) { return true; } diff --git a/Terminal.Gui/App/MainLoop/ApplicationMainLoop.cs b/Terminal.Gui/App/MainLoop/ApplicationMainLoop.cs index df03c3187..e52af3f0e 100644 --- a/Terminal.Gui/App/MainLoop/ApplicationMainLoop.cs +++ b/Terminal.Gui/App/MainLoop/ApplicationMainLoop.cs @@ -82,7 +82,7 @@ public class ApplicationMainLoop : IApplicationMainLoop - /// Handles raising events and setting required draw status etc when changes + /// Handles raising events and setting required draw status etc when changes /// public IToplevelTransitionManager ToplevelTransitionManager = new ToplevelTransitionManager (); @@ -145,10 +145,10 @@ public class ApplicationMainLoop : IApplicationMainLoop : IApplicationMainLoop? currentViewsUnderMouse = App?.Current?.GetViewsUnderLocation (mouseEvent.ScreenPosition, ViewportSettingsFlags.TransparentMouse); + List? currentViewsUnderMouse = App?.TopRunnable?.GetViewsUnderLocation (mouseEvent.ScreenPosition, ViewportSettingsFlags.TransparentMouse); View? deepestViewUnderMouse = currentViewsUnderMouse?.LastOrDefault (); @@ -114,9 +114,9 @@ internal class MouseImpl : IMouse return; } - // if the mouse is outside the Application.Current or Popover hierarchy, we don't want to + // if the mouse is outside the Application.TopRunnable or Popover hierarchy, we don't want to // send the mouse event to the deepest view under the mouse. - if (!View.IsInHierarchy (App?.Current, deepestViewUnderMouse, true) && !View.IsInHierarchy (App?.Popover?.GetActivePopover () as View, deepestViewUnderMouse, true)) + if (!View.IsInHierarchy (App?.TopRunnable, deepestViewUnderMouse, true) && !View.IsInHierarchy (App?.Popover?.GetActivePopover () as View, deepestViewUnderMouse, true)) { return; } diff --git a/Terminal.Gui/App/PopoverBaseImpl.cs b/Terminal.Gui/App/PopoverBaseImpl.cs index 41258401f..70f771de1 100644 --- a/Terminal.Gui/App/PopoverBaseImpl.cs +++ b/Terminal.Gui/App/PopoverBaseImpl.cs @@ -119,7 +119,7 @@ public abstract class PopoverBaseImpl : View, IPopover // Whenever visible is changing to false, we need to reset the focus if (ApplicationNavigation.IsInHierarchy (this, App?.Navigation?.GetFocused ())) { - App?.Navigation?.SetFocused (App?.Current?.MostFocused); + App?.Navigation?.SetFocused (App?.TopRunnable?.MostFocused); } } diff --git a/Terminal.Gui/App/Toplevel/ToplevelTransitionManager.cs b/Terminal.Gui/App/Toplevel/ToplevelTransitionManager.cs index 10166b450..edb09d0e9 100644 --- a/Terminal.Gui/App/Toplevel/ToplevelTransitionManager.cs +++ b/Terminal.Gui/App/Toplevel/ToplevelTransitionManager.cs @@ -13,7 +13,7 @@ public class ToplevelTransitionManager : IToplevelTransitionManager /// public void RaiseReadyEventIfNeeded (IApplication? app) { - Toplevel? top = app?.Current; + Toplevel? top = app?.TopRunnable; if (top != null && !_readiedTopLevels.Contains (top)) { @@ -29,13 +29,13 @@ public class ToplevelTransitionManager : IToplevelTransitionManager /// public void HandleTopMaybeChanging (IApplication? app) { - Toplevel? newTop = app?.Current; + Toplevel? newTop = app?.TopRunnable; if (_lastTop != null && _lastTop != newTop && newTop != null) { newTop.SetNeedsDraw (); } - _lastTop = app?.Current; + _lastTop = app?.TopRunnable; } } diff --git a/Terminal.Gui/ViewBase/Adornment/Border.Arrangment.cs b/Terminal.Gui/ViewBase/Adornment/Border.Arrangment.cs index f2e52fab8..3b2caefe4 100644 --- a/Terminal.Gui/ViewBase/Adornment/Border.Arrangment.cs +++ b/Terminal.Gui/ViewBase/Adornment/Border.Arrangment.cs @@ -657,7 +657,7 @@ public partial class Border if (Parent!.SuperView is null) { // Redraw the entire app window. - App?.Current?.SetNeedsDraw (); + App?.TopRunnable?.SetNeedsDraw (); } else { diff --git a/Terminal.Gui/ViewBase/View.Hierarchy.cs b/Terminal.Gui/ViewBase/View.Hierarchy.cs index b88a07199..0b18e4e3e 100644 --- a/Terminal.Gui/ViewBase/View.Hierarchy.cs +++ b/Terminal.Gui/ViewBase/View.Hierarchy.cs @@ -362,12 +362,12 @@ public partial class View // SuperView/SubView hierarchy management (SuperView, #endregion AddRemove - // TODO: This drives a weird coupling of Application.Current and View. It's not clear why this is needed. + // TODO: This drives a weird coupling of Application.TopRunnable and View. It's not clear why this is needed. /// Get the top superview of a given . /// The superview view. internal View? GetTopSuperView (View? view = null, View? superview = null) { - View? top = superview ?? App?.Current; + View? top = superview ?? App?.TopRunnable; for (View? v = view?.SuperView ?? this?.SuperView; v != null; v = v.SuperView) { diff --git a/Terminal.Gui/ViewBase/View.Layout.cs b/Terminal.Gui/ViewBase/View.Layout.cs index ecd58e737..76135f600 100644 --- a/Terminal.Gui/ViewBase/View.Layout.cs +++ b/Terminal.Gui/ViewBase/View.Layout.cs @@ -437,7 +437,7 @@ public partial class View // Layout APIs private void NeedsClearScreenNextIteration () { - if (App is { Current: { } } && App.Current == this && App.SessionStack.Count == 1) + if (App is { TopRunnable: { } } && App.TopRunnable == this && App.SessionStack.Count == 1) { // If this is the only TopLevel, we need to redraw the screen App.ClearScreenNextIteration = true; @@ -1113,8 +1113,8 @@ public partial class View // Layout APIs { // TODO: Get rid of refs to Top Size superViewContentSize = SuperView?.GetContentSize () - ?? (App?.Current is { } && App?.Current != this && App!.Current.IsInitialized - ? App.Current.GetContentSize () + ?? (App?.TopRunnable is { } && App?.TopRunnable != this && App!.TopRunnable.IsInitialized + ? App.TopRunnable.GetContentSize () : App?.Screen.Size ?? new (2048, 2048)); return superViewContentSize; @@ -1130,7 +1130,7 @@ public partial class View // Layout APIs /// /// /// If does not have a or it's SuperView is not - /// the position will be bound by . + /// the position will be bound by . /// /// The View that is to be moved. /// The target x location. @@ -1138,7 +1138,7 @@ public partial class View // Layout APIs /// The new x location that will ensure will be fully visible. /// The new y location that will ensure will be fully visible. /// - /// Either (if does not have a Super View) or + /// Either (if does not have a Super View) or /// 's SuperView. This can be used to ensure LayoutSubViews is called on the correct View. /// internal static View? GetLocationEnsuringFullVisibility ( @@ -1154,10 +1154,10 @@ public partial class View // Layout APIs IApplication? app = viewToMove.App; - if (viewToMove?.SuperView is null || viewToMove == app?.Current || viewToMove?.SuperView == app?.Current) + if (viewToMove?.SuperView is null || viewToMove == app?.TopRunnable || viewToMove?.SuperView == app?.TopRunnable) { maxDimension = app?.Screen.Width ?? 0; - superView = app?.Current; + superView = app?.TopRunnable; } else { @@ -1190,9 +1190,9 @@ public partial class View // Layout APIs var menuVisible = false; var statusVisible = false; - if (viewToMove?.SuperView is null || viewToMove == app?.Current || viewToMove?.SuperView == app?.Current) + if (viewToMove?.SuperView is null || viewToMove == app?.TopRunnable || viewToMove?.SuperView == app?.TopRunnable) { - menuVisible = app?.Current?.MenuBar?.Visible == true; + menuVisible = app?.TopRunnable?.MenuBar?.Visible == true; } else { @@ -1209,7 +1209,7 @@ public partial class View // Layout APIs } } - if (viewToMove?.SuperView is null || viewToMove == app?.Current || viewToMove?.SuperView == app?.Current) + if (viewToMove?.SuperView is null || viewToMove == app?.TopRunnable || viewToMove?.SuperView == app?.TopRunnable) { maxDimension = menuVisible ? 1 : 0; } @@ -1220,7 +1220,7 @@ public partial class View // Layout APIs ny = Math.Max (targetY, maxDimension); - if (viewToMove?.SuperView is null || viewToMove == app?.Current || viewToMove?.SuperView == app?.Current) + if (viewToMove?.SuperView is null || viewToMove == app?.TopRunnable || viewToMove?.SuperView == app?.TopRunnable) { if (app is { }) { @@ -1310,7 +1310,7 @@ public partial class View // Layout APIs } } - if (toplevel == App.Current) + if (toplevel == App.TopRunnable) { checkedTop = true; } @@ -1318,7 +1318,7 @@ public partial class View // Layout APIs } // Fallback: If TopLevels is empty or Top is not in TopLevels, check Top directly (for test compatibility) - if (!checkedTop && App?.Current is { Visible: true } top) + if (!checkedTop && App?.TopRunnable is { Visible: true } top) { // For root toplevels, allow hit-testing even if location is outside bounds (for drag/move) List result = GetViewsUnderLocation (top, screenLocation, excludeViewportSettingsFlags); diff --git a/Terminal.Gui/ViewBase/View.Navigation.cs b/Terminal.Gui/ViewBase/View.Navigation.cs index 5ff60aa7e..fb6f13030 100644 --- a/Terminal.Gui/ViewBase/View.Navigation.cs +++ b/Terminal.Gui/ViewBase/View.Navigation.cs @@ -395,7 +395,7 @@ public partial class View // Focus and cross-view navigation management (TabStop public event EventHandler? FocusedChanged; /// Returns a value indicating if this View is currently on Top (Active) - public bool IsCurrentTop => App?.Current == this; + public bool IsCurrentTop => App?.TopRunnable == this; /// /// Returns the most focused SubView down the subview-hierarchy. @@ -853,18 +853,18 @@ public partial class View // Focus and cross-view navigation management (TabStop } } - // Application.Current? - if (newFocusedView is null && App?.Current is { CanFocus: true, HasFocus: false }) + // Application.TopRunnable? + if (newFocusedView is null && App?.TopRunnable is { CanFocus: true, HasFocus: false }) { // Temporarily ensure this view can't get focus bool prevCanFocus = _canFocus; _canFocus = false; - bool restoredFocus = App?.Current.RestoreFocus () ?? false; + bool restoredFocus = App?.TopRunnable.RestoreFocus () ?? false; _canFocus = prevCanFocus; - if (App?.Current is { CanFocus: true, HasFocus: true }) + if (App?.TopRunnable is { CanFocus: true, HasFocus: true }) { - newFocusedView = App?.Current; + newFocusedView = App?.TopRunnable; } else if (restoredFocus) { diff --git a/Terminal.Gui/Views/Dialog.cs b/Terminal.Gui/Views/Dialog.cs index 4037d7312..1a5b4b362 100644 --- a/Terminal.Gui/Views/Dialog.cs +++ b/Terminal.Gui/Views/Dialog.cs @@ -21,7 +21,7 @@ public class Dialog : Window /// /// By default, , , , and are /// set - /// such that the will be centered in, and no larger than 90% of , if + /// such that the will be centered in, and no larger than 90% of , if /// there is one. Otherwise, /// it will be bound by the screen dimensions. /// diff --git a/Terminal.Gui/Views/Menuv1/Menu.cs b/Terminal.Gui/Views/Menuv1/Menu.cs index f538af7dd..61b58649a 100644 --- a/Terminal.Gui/Views/Menuv1/Menu.cs +++ b/Terminal.Gui/Views/Menuv1/Menu.cs @@ -12,10 +12,10 @@ internal sealed class Menu : View { public Menu () { - if (Application.Current is { }) + if (Application.TopRunnable is { }) { - Application.Current.DrawComplete += Top_DrawComplete; - Application.Current.SizeChanging += Current_TerminalResized; + Application.TopRunnable.DrawComplete += Top_DrawComplete; + Application.TopRunnable.SizeChanging += Current_TerminalResized; } Application.MouseEvent += Application_RootMouseEvent; @@ -231,10 +231,10 @@ internal sealed class Menu : View { RemoveKeyBindingsHotKey (_barItems); - if (Application.Current is { }) + if (Application.TopRunnable is { }) { - Application.Current.DrawComplete -= Top_DrawComplete; - Application.Current.SizeChanging -= Current_TerminalResized; + Application.TopRunnable.DrawComplete -= Top_DrawComplete; + Application.TopRunnable.SizeChanging -= Current_TerminalResized; } Application.MouseEvent -= Application_RootMouseEvent; diff --git a/Terminal.Gui/Views/Menuv1/MenuBar.cs b/Terminal.Gui/Views/Menuv1/MenuBar.cs index 78d1c3a29..2c09e6c56 100644 --- a/Terminal.Gui/Views/Menuv1/MenuBar.cs +++ b/Terminal.Gui/Views/Menuv1/MenuBar.cs @@ -421,7 +421,7 @@ public class MenuBar : View, IDesignable _selected = 0; SetNeedsDraw (); - _previousFocused = (SuperView is null ? Application.Current?.Focused : SuperView.Focused)!; + _previousFocused = (SuperView is null ? Application.TopRunnable?.Focused : SuperView.Focused)!; OpenMenu (_selected); if (!SelectEnabledItem ( @@ -490,7 +490,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.TopRunnable?.Focused ?? null : SuperView.Focused)!; } OpenMenu (idx, sIdx, subMenu); @@ -702,7 +702,7 @@ public class MenuBar : View, IDesignable } Rectangle superViewFrame = SuperView?.Frame ?? Application.Screen; - View? sv = SuperView ?? Application.Current; + View? sv = SuperView ?? Application.TopRunnable; if (sv is null) { @@ -834,7 +834,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.TopRunnable?.MostFocused : SuperView.MostFocused; if (_openSubMenu is { } && !CloseMenu (false, true)) { diff --git a/Terminal.Gui/Views/Toplevel.cs b/Terminal.Gui/Views/Toplevel.cs index fedc501f4..6f9bb2268 100644 --- a/Terminal.Gui/Views/Toplevel.cs +++ b/Terminal.Gui/Views/Toplevel.cs @@ -13,7 +13,7 @@ namespace Terminal.Gui.Views; /// /// /// A Toplevel is created when an application initializes Terminal.Gui by calling . -/// The application Toplevel can be accessed via . Additional Toplevels can be created +/// The application Toplevel can be accessed via . Additional Toplevels can be created /// and run (e.g. s). To run a Toplevel, create the and call /// . /// @@ -152,7 +152,7 @@ public partial class Toplevel : View /// public virtual void RequestStop () { - App?.RequestStop (App?.Current); + App?.RequestStop (App?.TopRunnable); } /// @@ -244,7 +244,7 @@ public partial class Toplevel : View } // BUGBUG: The && true is a temp hack - if ((superView != top || top?.SuperView is { } || (top != App?.Current && top!.Modal) || (top == App?.Current && top?.SuperView is null)) + if ((superView != top || top?.SuperView is { } || (top != App?.TopRunnable && top!.Modal) || (top == App?.TopRunnable && top?.SuperView is null)) && (top!.Frame.X + top.Frame.Width > maxWidth || ny > top.Frame.Y)) { diff --git a/Terminal.Gui/Views/Wizard/Wizard.cs b/Terminal.Gui/Views/Wizard/Wizard.cs index fe3cfcc63..50b21c7ed 100644 --- a/Terminal.Gui/Views/Wizard/Wizard.cs +++ b/Terminal.Gui/Views/Wizard/Wizard.cs @@ -42,7 +42,7 @@ namespace Terminal.Gui.Views; /// Application.RequestStop(); /// }; /// -/// Application.Current.Add (wizard); +/// Application.TopRunnable.Add (wizard); /// Application.Run (); /// Application.Shutdown (); /// diff --git a/Tests/IntegrationTests/FluentTests/GuiTestContextKeyEventTests.cs b/Tests/IntegrationTests/FluentTests/GuiTestContextKeyEventTests.cs index 51097c74c..2e1efe92e 100644 --- a/Tests/IntegrationTests/FluentTests/GuiTestContextKeyEventTests.cs +++ b/Tests/IntegrationTests/FluentTests/GuiTestContextKeyEventTests.cs @@ -16,9 +16,9 @@ public class GuiTestContextKeyEventTests (ITestOutputHelper outputHelper) public void QuitKey_ViaApplication_Stops (TestDriver d) { using GuiTestContext context = With.A (40, 10, d); - Assert.True (context.App?.Current!.Running); + Assert.True (context.App?.TopRunnable!.Running); - Toplevel? top = context.App?.Current; + Toplevel? top = context.App?.TopRunnable; context.Then ((_) => context!.App?.Keyboard.RaiseKeyDownEvent (Application.QuitKey)); Assert.False (top!.Running); } @@ -28,9 +28,9 @@ public class GuiTestContextKeyEventTests (ITestOutputHelper outputHelper) public void QuitKey_ViaEnqueueKey_Stops (TestDriver d) { using GuiTestContext context = With.A (40, 10, d, _out); - Assert.True (context.App?.Current!.Running); + Assert.True (context.App?.TopRunnable!.Running); - Toplevel? top = context.App?.Current; + Toplevel? top = context.App?.TopRunnable; context.EnqueueKeyEvent (Application.QuitKey); Assert.False (top!.Running); diff --git a/Tests/IntegrationTests/FluentTests/GuiTestContextTests.cs b/Tests/IntegrationTests/FluentTests/GuiTestContextTests.cs index 30ea80cd8..e78161774 100644 --- a/Tests/IntegrationTests/FluentTests/GuiTestContextTests.cs +++ b/Tests/IntegrationTests/FluentTests/GuiTestContextTests.cs @@ -43,7 +43,7 @@ public class GuiTestContextTests (ITestOutputHelper outputHelper) public void With_New_A_Runs (TestDriver d) { using GuiTestContext context = With.A (40, 10, d, _out); - Assert.True (context.App!.Current!.Running); + Assert.True (context.App!.TopRunnable!.Running); Assert.NotEqual (Rectangle.Empty, context.App!.Screen); } @@ -54,9 +54,9 @@ public class GuiTestContextTests (ITestOutputHelper outputHelper) using GuiTestContext context = With.A (10, 3, d, _out) .Then ((app) => { - app.Current!.BorderStyle = LineStyle.None; - app.Current!.Border!.Thickness = Thickness.Empty; - app.Current.Text = "hello"; + app.TopRunnable!.BorderStyle = LineStyle.None; + app.TopRunnable!.Border!.Thickness = Thickness.Empty; + app.TopRunnable.Text = "hello"; }) .ScreenShot ("ScreenShot", _out) .AnsiScreenShot ("AnsiScreenShot", _out) diff --git a/Tests/IntegrationTests/FluentTests/MenuBarv2Tests.cs b/Tests/IntegrationTests/FluentTests/MenuBarv2Tests.cs index bc96b6f95..e0ca97b45 100644 --- a/Tests/IntegrationTests/FluentTests/MenuBarv2Tests.cs +++ b/Tests/IntegrationTests/FluentTests/MenuBarv2Tests.cs @@ -143,7 +143,7 @@ public class MenuBarv2Tests .Then ((app) => { menuBar = new MenuBarv2 (); - top = app.Current!; + top = app.TopRunnable!; top.Add ( new View () @@ -153,7 +153,7 @@ public class MenuBarv2Tests }); menuBar.EnableForDesign (ref top); - app.Current!.Add (menuBar); + app.TopRunnable!.Add (menuBar); }) .WaitIteration () .AssertIsNotType (top?.App?.Navigation!.GetFocused ()) @@ -178,7 +178,7 @@ public class MenuBarv2Tests { app = a; menuBar = new MenuBarv2 (); - Toplevel top = app.Current!; + Toplevel top = app.TopRunnable!; top.Add ( new View () @@ -188,7 +188,7 @@ public class MenuBarv2Tests }); menuBar.EnableForDesign (ref top); - app.Current!.Add (menuBar); + app.TopRunnable!.Add (menuBar); }) .WaitIteration () .AssertIsNotType (app?.Navigation!.GetFocused ()) @@ -266,10 +266,10 @@ public class MenuBarv2Tests .Then ((app) => { var menuBar = new MenuBarv2 (); - app.Current!.Add (menuBar); + app.TopRunnable!.Add (menuBar); // Call EnableForDesign - Toplevel top = app.Current!; + Toplevel top = app.TopRunnable!; bool result = menuBar.EnableForDesign (ref top); // Should return true @@ -302,9 +302,9 @@ public class MenuBarv2Tests { app = a; menuBar = new MenuBarv2 (); - Toplevel top = app.Current!; + Toplevel top = app.TopRunnable!; menuBar.EnableForDesign (ref top); - app.Current!.Add (menuBar); + app.TopRunnable!.Add (menuBar); }) .WaitIteration () .ScreenShot ("MenuBar initial state", _out) @@ -342,7 +342,7 @@ public class MenuBarv2Tests { app = a; menuBar = new MenuBarv2 (); - Toplevel top = app.Current!; + Toplevel top = app.TopRunnable!; top.Add ( new View () @@ -352,7 +352,7 @@ public class MenuBarv2Tests }); menuBar.EnableForDesign (ref top); - app.Current!.Add (menuBar); + app.TopRunnable!.Add (menuBar); }) .AssertIsNotType (app!.Navigation!.GetFocused ()) .ScreenShot ("MenuBar initial state", _out) @@ -386,9 +386,9 @@ public class MenuBarv2Tests { app = a; menuBar = new MenuBarv2 (); - Toplevel? toplevel = app.Current; + Toplevel? toplevel = app.TopRunnable; menuBar.EnableForDesign (ref toplevel!); - app.Current!.Add (menuBar); + app.TopRunnable!.Add (menuBar); }) .WaitIteration () .AssertIsNotType (app?.Navigation!.GetFocused ()) @@ -417,7 +417,7 @@ public class MenuBarv2Tests { app = a; menuBar = new MenuBarv2 (); - Toplevel top = app.Current!; + Toplevel top = app.TopRunnable!; top.Add ( new View () @@ -427,18 +427,18 @@ public class MenuBarv2Tests }); menuBar.EnableForDesign (ref top); - app.Current!.Add (menuBar); + app.TopRunnable!.Add (menuBar); }) .WaitIteration () .AssertIsNotType (app!.Navigation!.GetFocused ()) .ScreenShot ("MenuBar initial state", _out) .EnqueueKeyEvent (MenuBarv2.DefaultKey) .AssertEqual ("_New file", app.Navigation!.GetFocused ()!.Title) - .AssertTrue (app?.Current!.Running) + .AssertTrue (app?.TopRunnable!.Running) .ScreenShot ($"After {MenuBarv2.DefaultKey}", _out) .EnqueueKeyEvent (Application.QuitKey) .AssertFalse (app?.Popover?.GetActivePopover () is PopoverMenu) - .AssertTrue (app!.Current!.Running); + .AssertTrue (app!.TopRunnable!.Running); } [Theory] @@ -453,7 +453,7 @@ public class MenuBarv2Tests { app = a; menuBar = new MenuBarv2 (); - Toplevel top = app.Current!; + Toplevel top = app.TopRunnable!; top.Add ( new View () @@ -470,7 +470,7 @@ public class MenuBarv2Tests item.Key = Key.Empty; } - app.Current!.Add (menuBar); + app.TopRunnable!.Add (menuBar); }) .WaitIteration () .AssertIsNotType (app?.Navigation!.GetFocused ()) @@ -480,7 +480,7 @@ public class MenuBarv2Tests .ScreenShot ($"After {MenuBarv2.DefaultKey}", _out) .EnqueueKeyEvent (Application.QuitKey) .AssertFalse (app?.Popover?.GetActivePopover () is PopoverMenu) - .AssertTrue (app?.Current!.Running); + .AssertTrue (app?.TopRunnable!.Running); } [Theory] @@ -506,9 +506,9 @@ public class MenuBarv2Tests .Then ((a) => { var menuBar = new MenuBarv2 (); - Toplevel top = a.Current!; + Toplevel top = a.TopRunnable!; menuBar.EnableForDesign (ref top); - a.Current!.Add (menuBar); + a.TopRunnable!.Add (menuBar); }) .Add (testView) .WaitIteration () @@ -540,9 +540,9 @@ public class MenuBarv2Tests .Then ((a) => { var menuBar = new MenuBarv2 (); - Toplevel top = a.Current!; + Toplevel top = a.TopRunnable!; menuBar.EnableForDesign (ref top); - a.Current!.Add (menuBar); + a.TopRunnable!.Add (menuBar); }) .Add (testView) .WaitIteration () diff --git a/Tests/IntegrationTests/FluentTests/NavigationTests.cs b/Tests/IntegrationTests/FluentTests/NavigationTests.cs index fe74c59ea..3796a741f 100644 --- a/Tests/IntegrationTests/FluentTests/NavigationTests.cs +++ b/Tests/IntegrationTests/FluentTests/NavigationTests.cs @@ -29,8 +29,8 @@ public class NavigationTests (ITestOutputHelper outputHelper) w2.Add (v3, v4); var w3 = new Window { Id = "w3" }; w3.Add (v5, v6); - Toplevel top = app?.Current!; - app?.Current!.Add (w1, w2, w3); + Toplevel top = app?.TopRunnable!; + app?.TopRunnable!.Add (w1, w2, w3); }) .AssertTrue (v5.HasFocus) .EnqueueKeyEvent (Key.F6) diff --git a/Tests/IntegrationTests/FluentTests/PopverMenuTests.cs b/Tests/IntegrationTests/FluentTests/PopverMenuTests.cs index 83a173944..09ce0417d 100644 --- a/Tests/IntegrationTests/FluentTests/PopverMenuTests.cs +++ b/Tests/IntegrationTests/FluentTests/PopverMenuTests.cs @@ -26,10 +26,10 @@ public class PopoverMenuTests .Then ((app) => { PopoverMenu popoverMenu = new (); - app.Current!.Add (popoverMenu); + app.TopRunnable!.Add (popoverMenu); // Call EnableForDesign - Toplevel top = app.Current; + Toplevel top = app.TopRunnable; bool result = popoverMenu.EnableForDesign (ref top); // Should return true @@ -65,7 +65,7 @@ public class PopoverMenuTests }; // Call EnableForDesign - Toplevel top = app.Current!; + Toplevel top = app.TopRunnable!; popoverMenu.EnableForDesign (ref top); var view = new View @@ -76,7 +76,7 @@ public class PopoverMenuTests Id = "focusableView", Text = "View" }; - app.Current!.Add (view); + app.TopRunnable!.Add (view); // EnableForDesign sets to true; undo that popoverMenu.Visible = false; @@ -110,7 +110,7 @@ public class PopoverMenuTests }; // Call EnableForDesign - Toplevel top = app.Current!; + Toplevel top = app.TopRunnable!; bool result = popoverMenu.EnableForDesign (ref top); var view = new View @@ -121,7 +121,7 @@ public class PopoverMenuTests Id = "focusableView", Text = "View" }; - app.Current!.Add (view); + app.TopRunnable!.Add (view); // EnableForDesign sets to true; undo that popoverMenu.Visible = false; @@ -139,7 +139,7 @@ public class PopoverMenuTests .ScreenShot ($"After {Application.QuitKey}", _out) .AssertFalse (app?.Popover!.Popovers.Cast ().FirstOrDefault ()!.Visible) .AssertNull (app?.Popover!.GetActivePopover ()) - .AssertTrue (app?.Current!.Running); + .AssertTrue (app?.TopRunnable!.Running); } [Theory] @@ -157,7 +157,7 @@ public class PopoverMenuTests }; // Call EnableForDesign - Toplevel top = app.Current!; + Toplevel top = app.TopRunnable!; bool result = popoverMenu.EnableForDesign (ref top); var view = new View @@ -168,7 +168,7 @@ public class PopoverMenuTests Id = "focusableView", Text = "View" }; - app.Current!.Add (view); + app.TopRunnable!.Add (view); // EnableForDesign sets to true; undo that popoverMenu.Visible = false; @@ -206,7 +206,7 @@ public class PopoverMenuTests }; // Call EnableForDesign - Toplevel top = app.Current!; + Toplevel top = app.TopRunnable!; bool result = popoverMenu.EnableForDesign (ref top); var view = new View @@ -217,7 +217,7 @@ public class PopoverMenuTests Id = "focusableView", Text = "View" }; - app.Current!.Add (view); + app.TopRunnable!.Add (view); // EnableForDesign sets to true; undo that popoverMenu.Visible = false; @@ -231,11 +231,11 @@ public class PopoverMenuTests .Then ((_) => app?.Popover!.Show (app?.Popover.Popovers.First ())) .ScreenShot ("PopoverMenu after Show", _out) .AssertEqual ("Cu_t", app?.Navigation!.GetFocused ()!.Title) - .AssertTrue (app?.Current!.Running) + .AssertTrue (app?.TopRunnable!.Running) .EnqueueKeyEvent (Application.QuitKey) .ScreenShot ($"After {Application.QuitKey}", _out) .AssertFalse (app?.Popover?.GetActivePopover () is PopoverMenu) - .AssertTrue (app?.Current!.Running); + .AssertTrue (app?.TopRunnable!.Running); } [Theory] @@ -267,7 +267,7 @@ public class PopoverMenuTests { App = app }; - Toplevel top = app.Current!; + Toplevel top = app.TopRunnable!; popoverMenu.EnableForDesign (ref top); app?.Popover!.Register (popoverMenu); }) @@ -307,7 +307,7 @@ public class PopoverMenuTests { App = app }; - Toplevel top = app.Current!; + Toplevel top = app.TopRunnable!; popoverMenu.EnableForDesign (ref top); app?.Popover!.Register (popoverMenu); }) @@ -346,7 +346,7 @@ public class PopoverMenuTests { App = app }; - Toplevel top = app.Current!; + Toplevel top = app.TopRunnable!; popoverMenu.EnableForDesign (ref top); app?.Popover!.Register (popoverMenu); }) diff --git a/Tests/StressTests/ApplicationStressTests.cs b/Tests/StressTests/ApplicationStressTests.cs index 0feadf210..f63bbf9b9 100644 --- a/Tests/StressTests/ApplicationStressTests.cs +++ b/Tests/StressTests/ApplicationStressTests.cs @@ -71,8 +71,8 @@ public class ApplicationStressTests { int tbNow = _tbCounter; - // Wait for Application.Current to be running to ensure timed events can be processed - while (Application.Current is null || Application.Current is { Running: false }) + // Wait for Application.TopRunnable to be running to ensure timed events can be processed + while (Application.TopRunnable is null || Application.TopRunnable is { Running: false }) { Thread.Sleep (1); } diff --git a/Tests/StressTests/ScenariosStressTests.cs b/Tests/StressTests/ScenariosStressTests.cs index fead31b84..467bffbb4 100644 --- a/Tests/StressTests/ScenariosStressTests.cs +++ b/Tests/StressTests/ScenariosStressTests.cs @@ -126,7 +126,7 @@ public class ScenariosStressTests void OnApplicationSessionBegun (object? sender, SessionTokenEventArgs e) { - // Get a list of all subviews under Application.Current (and their subviews, etc.) + // Get a list of all subviews under Application.TopRunnable (and their subviews, etc.) // and subscribe to their DrawComplete event void SubscribeAllSubViews (View view) { @@ -140,7 +140,7 @@ public class ScenariosStressTests } } - SubscribeAllSubViews (Application.Current!); + SubscribeAllSubViews (Application.TopRunnable!); } // If the scenario doesn't close within the abort time, this will force it to quit diff --git a/Tests/TerminalGuiFluentTesting/FakeDriver/FakeApplicationLifecycle.cs b/Tests/TerminalGuiFluentTesting/FakeDriver/FakeApplicationLifecycle.cs index 5fced9338..f24764561 100644 --- a/Tests/TerminalGuiFluentTesting/FakeDriver/FakeApplicationLifecycle.cs +++ b/Tests/TerminalGuiFluentTesting/FakeDriver/FakeApplicationLifecycle.cs @@ -13,7 +13,7 @@ internal class FakeApplicationLifecycle (CancellationTokenSource hardStop) : IDi { hardStop.Cancel (); - Application.Current?.Dispose (); + Application.TopRunnable?.Dispose (); Application.Shutdown (); } } diff --git a/Tests/TerminalGuiFluentTesting/GuiTestContext.Navigation.cs b/Tests/TerminalGuiFluentTesting/GuiTestContext.Navigation.cs index 9bd8f5bc9..aa9522b4a 100644 --- a/Tests/TerminalGuiFluentTesting/GuiTestContext.Navigation.cs +++ b/Tests/TerminalGuiFluentTesting/GuiTestContext.Navigation.cs @@ -40,13 +40,13 @@ public partial class GuiTestContext public GuiTestContext Focus (Func? evaluator = null) where T : View { evaluator ??= _ => true; - Toplevel? t = App?.Current; + Toplevel? t = App?.TopRunnable; HashSet seen = new (); if (t == null) { - Fail ("Application.Current was null when trying to set focus"); + Fail ("Application.TopRunnable was null when trying to set focus"); return this; } diff --git a/Tests/TerminalGuiFluentTesting/GuiTestContext.ViewBase.cs b/Tests/TerminalGuiFluentTesting/GuiTestContext.ViewBase.cs index f96505840..ddcaef2fd 100644 --- a/Tests/TerminalGuiFluentTesting/GuiTestContext.ViewBase.cs +++ b/Tests/TerminalGuiFluentTesting/GuiTestContext.ViewBase.cs @@ -14,7 +14,7 @@ public partial class GuiTestContext { WaitIteration ((app) => { - Toplevel top = app.Current ?? throw new ("Top was null so could not add view"); + Toplevel top = app.TopRunnable ?? throw new ("Top was null so could not add view"); top.Add (v); top.Layout (); _lastView = v; @@ -28,15 +28,15 @@ public partial class GuiTestContext /// /// The last view added (e.g. with ) or the root/current top. /// - public View LastView => _lastView ?? App?.Current ?? throw new ("Could not determine which view to add to"); + public View LastView => _lastView ?? App?.TopRunnable ?? throw new ("Could not determine which view to add to"); private T Find (Func evaluator) where T : View { - Toplevel? t = App?.Current; + Toplevel? t = App?.TopRunnable; if (t == null) { - Fail ("App.Current was null when attempting to find view"); + Fail ("App.TopRunnable was null when attempting to find view"); } T? f = FindRecursive (t!, evaluator); diff --git a/Tests/UnitTests/Application/Application.NavigationTests.cs b/Tests/UnitTests/Application/Application.NavigationTests.cs index 21cafa132..083052ddd 100644 --- a/Tests/UnitTests/Application/Application.NavigationTests.cs +++ b/Tests/UnitTests/Application/Application.NavigationTests.cs @@ -82,7 +82,7 @@ public class ApplicationNavigationTests (ITestOutputHelper output) { IApplication app = Application.Create (); - app.Current = new () + app.TopRunnable = new () { Id = "top", CanFocus = true, @@ -101,10 +101,10 @@ public class ApplicationNavigationTests (ITestOutputHelper output) CanFocus = true }; - app.Current?.Add (subView1, subView2); - Assert.False (app.Current?.HasFocus); + app.TopRunnable?.Add (subView1, subView2); + Assert.False (app.TopRunnable?.HasFocus); - app.Current?.SetFocus (); + app.TopRunnable?.SetFocus (); Assert.True (subView1.HasFocus); Assert.Equal (subView1, app.Navigation?.GetFocused ()); @@ -117,7 +117,7 @@ public class ApplicationNavigationTests (ITestOutputHelper output) { IApplication app = Application.Create (); - app.Current = new () + app.TopRunnable = new () { Id = "top", CanFocus = true, @@ -130,20 +130,20 @@ public class ApplicationNavigationTests (ITestOutputHelper output) CanFocus = true }; - app!.Current.Add (subView1); - Assert.False (app.Current.HasFocus); + app!.TopRunnable.Add (subView1); + Assert.False (app.TopRunnable.HasFocus); - app.Current.SetFocus (); + app.TopRunnable.SetFocus (); Assert.True (subView1.HasFocus); Assert.Equal (subView1, app.Navigation!.GetFocused ()); subView1.HasFocus = false; Assert.False (subView1.HasFocus); - Assert.True (app.Current.HasFocus); - Assert.Equal (app.Current, app.Navigation.GetFocused ()); + Assert.True (app.TopRunnable.HasFocus); + Assert.Equal (app.TopRunnable, app.Navigation.GetFocused ()); - app.Current.HasFocus = false; - Assert.False (app.Current.HasFocus); + app.TopRunnable.HasFocus = false; + Assert.False (app.TopRunnable.HasFocus); Assert.Null (app.Navigation.GetFocused ()); } diff --git a/Tests/UnitTests/Application/ApplicationImplBeginEndTests.cs b/Tests/UnitTests/Application/ApplicationImplBeginEndTests.cs index da9faad9d..ad48cf802 100644 --- a/Tests/UnitTests/Application/ApplicationImplBeginEndTests.cs +++ b/Tests/UnitTests/Application/ApplicationImplBeginEndTests.cs @@ -45,12 +45,12 @@ public class ApplicationImplBeginEndTests try { toplevel = new (); - Assert.Null (app.Current); + Assert.Null (app.TopRunnable); app.Begin (toplevel); - Assert.NotNull (app.Current); - Assert.Same (toplevel, app.Current); + Assert.NotNull (app.TopRunnable); + Assert.Same (toplevel, app.TopRunnable); Assert.Single (app.SessionStack); } finally @@ -74,11 +74,11 @@ public class ApplicationImplBeginEndTests app.Begin (toplevel1); Assert.Single (app.SessionStack); - Assert.Same (toplevel1, app.Current); + Assert.Same (toplevel1, app.TopRunnable); app.Begin (toplevel2); Assert.Equal (2, app.SessionStack.Count); - Assert.Same (toplevel2, app.Current); + Assert.Same (toplevel2, app.TopRunnable); } finally { @@ -163,7 +163,7 @@ public class ApplicationImplBeginEndTests app.End (token2); Assert.Single (app.SessionStack); - Assert.Same (toplevel1, app.Current); + Assert.Same (toplevel1, app.TopRunnable); app.End (token1); @@ -228,13 +228,13 @@ public class ApplicationImplBeginEndTests SessionToken token2 = app.Begin (toplevel2); SessionToken token3 = app.Begin (toplevel3); - Assert.Same (toplevel3, app.Current); + Assert.Same (toplevel3, app.TopRunnable); app.End (token3); - Assert.Same (toplevel2, app.Current); + Assert.Same (toplevel2, app.TopRunnable); app.End (token2); - Assert.Same (toplevel1, app.Current); + Assert.Same (toplevel1, app.TopRunnable); app.End (token1); } @@ -265,7 +265,7 @@ public class ApplicationImplBeginEndTests } Assert.Equal (5, app.SessionStack.Count); - Assert.Same (toplevels [4], app.Current); + Assert.Same (toplevels [4], app.TopRunnable); // End them in reverse order (LIFO) for (var i = 4; i >= 0; i--) @@ -275,7 +275,7 @@ public class ApplicationImplBeginEndTests if (i > 0) { Assert.Equal (i, app.SessionStack.Count); - Assert.Same (toplevels [i - 1], app.Current); + Assert.Same (toplevels [i - 1], app.TopRunnable); } else { @@ -358,7 +358,7 @@ public class ApplicationImplBeginEndTests app.Begin (toplevel2); Assert.Equal (2, app.SessionStack.Count); - Assert.NotNull (app.Current); + Assert.NotNull (app.TopRunnable); } finally { @@ -371,7 +371,7 @@ public class ApplicationImplBeginEndTests // Verify cleanup happened Assert.Empty (app.SessionStack); - Assert.Null (app.Current); + Assert.Null (app.TopRunnable); Assert.Null (app.CachedSessionTokenToplevel); } } @@ -432,7 +432,7 @@ public class ApplicationImplBeginEndTests Assert.True (toplevel1Deactivated); Assert.True (toplevel2Activated); - Assert.Same (toplevel2, app.Current); + Assert.Same (toplevel2, app.TopRunnable); } finally { diff --git a/Tests/UnitTests/Application/ApplicationImplTests.cs b/Tests/UnitTests/Application/ApplicationImplTests.cs index faa4cf7a8..c995c02e8 100644 --- a/Tests/UnitTests/Application/ApplicationImplTests.cs +++ b/Tests/UnitTests/Application/ApplicationImplTests.cs @@ -81,7 +81,7 @@ public class ApplicationImplTests TimeSpan.FromMilliseconds (150), () => { - if (app.Current is { }) + if (app.TopRunnable is { }) { app.RequestStop (); @@ -91,7 +91,7 @@ public class ApplicationImplTests return false; } ); - Assert.Null (app?.Current); + Assert.Null (app?.TopRunnable); // Blocks until the timeout call is hit @@ -100,10 +100,10 @@ public class ApplicationImplTests // We returned false above, so we should not have to remove the timeout Assert.False (app?.RemoveTimeout (timeoutToken!)); - Assert.NotNull (app?.Current); - app.Current?.Dispose (); + Assert.NotNull (app?.TopRunnable); + app.TopRunnable?.Dispose (); app.Shutdown (); - Assert.Null (app.Current); + Assert.Null (app.TopRunnable); } [Fact] @@ -124,7 +124,7 @@ public class ApplicationImplTests { Assert.True (top!.Running); - if (app.Current != null) + if (app.TopRunnable != null) { app.RequestStop (); @@ -146,8 +146,8 @@ public class ApplicationImplTests Assert.False (top!.Running); // BUGBUG: Shutdown sets Top to null, not End. - //Assert.Null (Application.Current); - app.Current?.Dispose (); + //Assert.Null (Application.TopRunnable); + app.TopRunnable?.Dispose (); app.Shutdown (); } @@ -156,13 +156,13 @@ public class ApplicationImplTests { IApplication app = NewMockedApplicationImpl ()!; - Assert.Null (app.Current); + Assert.Null (app.TopRunnable); Assert.Null (app.Driver); app.Init ("fake"); Toplevel top = new Window (); - app.Current = top; + app.TopRunnable = top; var closedCount = 0; @@ -193,7 +193,7 @@ public class ApplicationImplTests Assert.Equal (1, closedCount); Assert.Equal (1, unloadedCount); - app.Current?.Dispose (); + app.TopRunnable?.Dispose (); app.Shutdown (); Assert.Equal (1, closedCount); Assert.Equal (1, unloadedCount); @@ -204,7 +204,7 @@ public class ApplicationImplTests { IApplication app = NewMockedApplicationImpl ()!; - Assert.Null (app.Current); + Assert.Null (app.TopRunnable); Assert.Null (app.Driver); app.Init ("fake"); @@ -228,7 +228,7 @@ public class ApplicationImplTests { Assert.True (top!.Running); - if (app.Current != null) + if (app.TopRunnable != null) { app.RequestStop (); @@ -251,7 +251,7 @@ public class ApplicationImplTests // We returned false above, so we should not have to remove the timeout Assert.False (app.RemoveTimeout (timeoutToken)); - app.Current?.Dispose (); + app.TopRunnable?.Dispose (); app.Shutdown (); Assert.Equal (1, closedCount); Assert.Equal (1, unloadedCount); @@ -275,7 +275,7 @@ public class ApplicationImplTests { Assert.True (top!.Running); - if (app.Current != null) + if (app.TopRunnable != null) { app.Keyboard.RaiseKeyDownEvent (app.Keyboard.QuitKey); } @@ -294,10 +294,10 @@ public class ApplicationImplTests Assert.False (top!.Running); - Assert.NotNull (app.Current); + Assert.NotNull (app.TopRunnable); top.Dispose (); app.Shutdown (); - Assert.Null (app.Current); + Assert.Null (app.TopRunnable); } [Fact] @@ -308,16 +308,16 @@ public class ApplicationImplTests app.Init ("fake"); app.AddTimeout (TimeSpan.Zero, () => IdleExit (app)); - Assert.Null (app.Current); + Assert.Null (app.TopRunnable); // Blocks until the timeout call is hit app.Run (); - Assert.NotNull (app.Current); - app.Current?.Dispose (); + Assert.NotNull (app.TopRunnable); + app.TopRunnable?.Dispose (); app.Shutdown (); - Assert.Null (app.Current); + Assert.Null (app.TopRunnable); } [Fact] @@ -357,7 +357,7 @@ public class ApplicationImplTests app.Run (t); - app.Current?.Dispose (); + app.TopRunnable?.Dispose (); app.Shutdown (); Assert.Equal (2, closing); @@ -366,7 +366,7 @@ public class ApplicationImplTests private bool IdleExit (IApplication app) { - if (app.Current != null) + if (app.TopRunnable != null) { app.RequestStop (); @@ -408,7 +408,7 @@ public class ApplicationImplTests () => { // Run asynchronous logic inside Task.Run - if (app.Current != null) + if (app.TopRunnable != null) { b.NewKeyDownEvent (Key.Enter); b.NewKeyUpEvent (Key.Enter); @@ -417,7 +417,7 @@ public class ApplicationImplTests return false; }); - Assert.Null (app.Current); + Assert.Null (app.TopRunnable); var w = new Window { @@ -428,10 +428,10 @@ public class ApplicationImplTests // Blocks until the timeout call is hit app.Run (w); - Assert.NotNull (app.Current); - app.Current?.Dispose (); + Assert.NotNull (app.TopRunnable); + app.TopRunnable?.Dispose (); app.Shutdown (); - Assert.Null (app.Current); + Assert.Null (app.TopRunnable); Assert.True (result); } @@ -448,7 +448,7 @@ public class ApplicationImplTests //Assert.Null (v2.Popover); //Assert.Null (v2.Navigation); - Assert.Null (v2.Current); + Assert.Null (v2.TopRunnable); Assert.Empty (v2.SessionStack); // Init should populate instance fields @@ -459,7 +459,7 @@ public class ApplicationImplTests Assert.True (v2.Initialized); Assert.NotNull (v2.Popover); Assert.NotNull (v2.Navigation); - Assert.Null (v2.Current); // Top is still null until Run + Assert.Null (v2.TopRunnable); // Top is still null until Run // Shutdown should clean up instance fields v2.Shutdown (); @@ -469,7 +469,7 @@ public class ApplicationImplTests //Assert.Null (v2.Popover); //Assert.Null (v2.Navigation); - Assert.Null (v2.Current); + Assert.Null (v2.TopRunnable); Assert.Empty (v2.SessionStack); } } diff --git a/Tests/UnitTests/Application/ApplicationPopoverTests.cs b/Tests/UnitTests/Application/ApplicationPopoverTests.cs index 1ca1944d0..778e681a9 100644 --- a/Tests/UnitTests/Application/ApplicationPopoverTests.cs +++ b/Tests/UnitTests/Application/ApplicationPopoverTests.cs @@ -197,14 +197,14 @@ public class ApplicationPopoverTests // Arrange Application.Init ("fake"); - Application.Current = new (); + Application.TopRunnable = new (); PopoverTestClass? popover = new (); // Act Application.Popover?.Register (popover); // Assert - Assert.Equal (Application.Current, popover.Current); + Assert.Equal (Application.TopRunnable, popover.Current); } finally { @@ -219,7 +219,7 @@ public class ApplicationPopoverTests { // Arrange Application.Init ("fake"); - Application.Current = new() { Id = "initialTop" }; + Application.TopRunnable = new() { Id = "initialTop" }; PopoverTestClass? popover = new () { }; var keyDownEvents = 0; @@ -234,7 +234,7 @@ public class ApplicationPopoverTests // Act Application.RaiseKeyDownEvent (Key.A); // Goes to initialTop - Application.Current = new() { Id = "secondaryTop" }; + Application.TopRunnable = new() { Id = "secondaryTop" }; Application.RaiseKeyDownEvent (Key.A); // Goes to secondaryTop // Test @@ -267,7 +267,7 @@ public class ApplicationPopoverTests // Arrange Application.Init ("fake"); - Application.Current = new () + Application.TopRunnable = new () { Frame = new (0, 0, 10, 10), Id = "top" @@ -282,7 +282,7 @@ public class ApplicationPopoverTests Height = 2 }; - Application.Current.Add (view); + Application.TopRunnable.Add (view); popover = new () { @@ -316,7 +316,7 @@ public class ApplicationPopoverTests finally { popover?.Dispose (); - Application.Current?.Dispose (); + Application.TopRunnable?.Dispose (); Application.ResetState (true); } } diff --git a/Tests/UnitTests/Application/ApplicationScreenTests.cs b/Tests/UnitTests/Application/ApplicationScreenTests.cs index 9d4185adf..f1ee2ea89 100644 --- a/Tests/UnitTests/Application/ApplicationScreenTests.cs +++ b/Tests/UnitTests/Application/ApplicationScreenTests.cs @@ -46,35 +46,35 @@ public class ApplicationScreenTests Assert.Equal (0, clearedContentsRaised); // Act - Application.Current!.SetNeedsLayout (); + Application.TopRunnable!.SetNeedsLayout (); Application.LayoutAndDraw (); // Assert Assert.Equal (0, clearedContentsRaised); // Act - Application.Current.X = 1; + Application.TopRunnable.X = 1; Application.LayoutAndDraw (); // Assert Assert.Equal (1, clearedContentsRaised); // Act - Application.Current.Width = 10; + Application.TopRunnable.Width = 10; Application.LayoutAndDraw (); // Assert Assert.Equal (2, clearedContentsRaised); // Act - Application.Current.Y = 1; + Application.TopRunnable.Y = 1; Application.LayoutAndDraw (); // Assert Assert.Equal (3, clearedContentsRaised); // Act - Application.Current.Height = 10; + Application.TopRunnable.Height = 10; Application.LayoutAndDraw (); // Assert diff --git a/Tests/UnitTests/Application/ApplicationTests.cs b/Tests/UnitTests/Application/ApplicationTests.cs index f9230fccd..52d9276da 100644 --- a/Tests/UnitTests/Application/ApplicationTests.cs +++ b/Tests/UnitTests/Application/ApplicationTests.cs @@ -70,13 +70,13 @@ public class ApplicationTests [SetupFakeApplication] public void Begin_Sets_Application_Top_To_Console_Size () { - Assert.Null (Application.Current); + Assert.Null (Application.TopRunnable); Application.Driver!.SetScreenSize (80, 25); Toplevel top = new (); Application.Begin (top); - Assert.Equal (new (0, 0, 80, 25), Application.Current!.Frame); + Assert.Equal (new (0, 0, 80, 25), Application.TopRunnable!.Frame); Application.Driver!.SetScreenSize (5, 5); - Assert.Equal (new (0, 0, 5, 5), Application.Current!.Frame); + Assert.Equal (new (0, 0, 5, 5), Application.TopRunnable!.Frame); top.Dispose (); } @@ -84,21 +84,21 @@ public class ApplicationTests [SetupFakeApplication] public void End_And_Shutdown_Should_Not_Dispose_ApplicationTop () { - Assert.Null (Application.Current); + Assert.Null (Application.TopRunnable); SessionToken rs = Application.Begin (new ()); - Application.Current!.Title = "End_And_Shutdown_Should_Not_Dispose_ApplicationTop"; - Assert.Equal (rs.Toplevel, Application.Current); + Application.TopRunnable!.Title = "End_And_Shutdown_Should_Not_Dispose_ApplicationTop"; + Assert.Equal (rs.Toplevel, Application.TopRunnable); Application.End (rs); #if DEBUG_IDISPOSABLE Assert.True (rs.WasDisposed); - Assert.False (Application.Current!.WasDisposed); // Is true because the rs.Toplevel is the same as Application.Current + Assert.False (Application.TopRunnable!.WasDisposed); // Is true because the rs.Toplevel is the same as Application.TopRunnable #endif Assert.Null (rs.Toplevel); - Toplevel top = Application.Current; + Toplevel top = Application.TopRunnable; #if DEBUG_IDISPOSABLE Exception exception = Record.Exception (Application.Shutdown); @@ -132,12 +132,12 @@ public class ApplicationTests Assert.NotNull (sessionToken); Assert.Equal (rs, sessionToken); - Assert.Equal (topLevel, Application.Current); + Assert.Equal (topLevel, Application.TopRunnable); Application.SessionBegun -= newSessionTokenFn; Application.End (sessionToken); - Assert.NotNull (Application.Current); + Assert.NotNull (Application.TopRunnable); Assert.NotNull (Application.Driver); topLevel.Dispose (); @@ -246,7 +246,7 @@ public class ApplicationTests // Check that all fields and properties are set to their default values // Public Properties - Assert.Null (Application.Current); + Assert.Null (Application.TopRunnable); Assert.Null (Application.Mouse.MouseGrabView); // Don't check Application.ForceDriver @@ -391,18 +391,18 @@ public class ApplicationTests Assert.NotNull (sessionToken); Assert.Equal (rs, sessionToken); - Assert.Equal (topLevel, Application.Current); + Assert.Equal (topLevel, Application.TopRunnable); Application.SessionBegun -= newSessionTokenFn; Application.End (sessionToken); - Assert.NotNull (Application.Current); + Assert.NotNull (Application.TopRunnable); Assert.NotNull (Application.Driver); topLevel.Dispose (); Application.Shutdown (); - Assert.Null (Application.Current); + Assert.Null (Application.TopRunnable); Assert.Null (Application.Driver); } @@ -411,11 +411,11 @@ public class ApplicationTests public void Internal_Properties_Correct () { Assert.True (Application.Initialized); - Assert.Null (Application.Current); + Assert.Null (Application.TopRunnable); SessionToken rs = Application.Begin (new ()); - Assert.Equal (Application.Current, rs.Toplevel); + Assert.Equal (Application.TopRunnable, rs.Toplevel); Assert.Null (Application.Mouse.MouseGrabView); // public - Application.Current!.Dispose (); + Application.TopRunnable!.Dispose (); } // Invoke Tests @@ -511,9 +511,9 @@ public class ApplicationTests // Run when already initialized or not with a Driver will not throw (because Window is derived from Toplevel) // Using another type not derived from Toplevel will throws at compile time Application.Run (); - Assert.True (Application.Current is Window); + Assert.True (Application.TopRunnable is Window); - Application.Current!.Dispose (); + Application.TopRunnable!.Dispose (); } [Fact] @@ -524,15 +524,15 @@ public class ApplicationTests // Run when already initialized or not with a Driver will not throw (because Window is derived from Toplevel) // Using another type not derived from Toplevel will throws at compile time Application.Run (null, "fake"); - Assert.True (Application.Current is Window); + Assert.True (Application.TopRunnable is Window); - Application.Current!.Dispose (); + Application.TopRunnable!.Dispose (); // Run when already initialized or not with a Driver will not throw (because Dialog is derived from Toplevel) Application.Run (null, "fake"); - Assert.True (Application.Current is Dialog); + Assert.True (Application.TopRunnable is Dialog); - Application.Current!.Dispose (); + Application.TopRunnable!.Dispose (); Application.Shutdown (); } @@ -540,7 +540,7 @@ public class ApplicationTests [SetupFakeApplication] public void Run_T_After_Init_Does_Not_Disposes_Application_Top () { - // Init doesn't create a Toplevel and assigned it to Application.Current + // Init doesn't create a Toplevel and assigned it to Application.TopRunnable // but Begin does var initTop = new Toplevel (); @@ -554,13 +554,13 @@ public class ApplicationTests initTop.Dispose (); Assert.True (initTop.WasDisposed); #endif - Application.Current!.Dispose (); + Application.TopRunnable!.Dispose (); return; void OnApplicationOnIteration (object s, IterationEventArgs a) { - Assert.NotEqual (initTop, Application.Current); + Assert.NotEqual (initTop, Application.TopRunnable); #if DEBUG_IDISPOSABLE Assert.False (initTop.WasDisposed); #endif @@ -577,7 +577,7 @@ public class ApplicationTests // Init has been called and we're passing no driver to Run. This is ok. Application.Run (); - Application.Current!.Dispose (); + Application.TopRunnable!.Dispose (); } [Fact] @@ -589,7 +589,7 @@ public class ApplicationTests // Init has been called, selecting FakeDriver; we're passing no driver to Run. Should be fine. Application.Run (); - Application.Current!.Dispose (); + Application.TopRunnable!.Dispose (); } [Fact] @@ -620,7 +620,7 @@ public class ApplicationTests // Init has NOT been called and we're passing a valid driver to Run. This is ok. Application.Run (null, "fake"); - Application.Current!.Dispose (); + Application.TopRunnable!.Dispose (); } [Fact] @@ -744,9 +744,9 @@ public class ApplicationTests Assert.NotNull (w); Assert.Equal (string.Empty, w.Title); // Valid - w has not been disposed. The user may want to run it again - Assert.NotNull (Application.Current); - Assert.Equal (w, Application.Current); - Assert.NotEqual (top, Application.Current); + Assert.NotNull (Application.TopRunnable); + Assert.Equal (w, Application.TopRunnable); + Assert.NotEqual (top, Application.TopRunnable); Application.Run (w); // Valid - w has not been disposed. @@ -774,14 +774,14 @@ public class ApplicationTests [Fact] public void Run_Creates_Top_Without_Init () { - Assert.Null (Application.Current); + Assert.Null (Application.TopRunnable); Application.StopAfterFirstIteration = true; Application.Iteration += OnApplicationOnIteration; Toplevel top = Application.Run (null, "fake"); Application.Iteration -= OnApplicationOnIteration; #if DEBUG_IDISPOSABLE - Assert.Equal (top, Application.Current); + Assert.Equal (top, Application.TopRunnable); Assert.False (top.WasDisposed); Exception exception = Record.Exception (Application.Shutdown); Assert.NotNull (exception); @@ -794,38 +794,38 @@ public class ApplicationTests #if DEBUG_IDISPOSABLE Assert.True (top.WasDisposed); #endif - Assert.NotNull (Application.Current); + Assert.NotNull (Application.TopRunnable); Application.Shutdown (); - Assert.Null (Application.Current); + Assert.Null (Application.TopRunnable); return; - void OnApplicationOnIteration (object s, IterationEventArgs e) { Assert.NotNull (Application.Current); } + void OnApplicationOnIteration (object s, IterationEventArgs e) { Assert.NotNull (Application.TopRunnable); } } [Fact] public void Run_T_Creates_Top_Without_Init () { - Assert.Null (Application.Current); + Assert.Null (Application.TopRunnable); Application.StopAfterFirstIteration = true; Application.Run (null, "fake"); #if DEBUG_IDISPOSABLE - Assert.False (Application.Current!.WasDisposed); + Assert.False (Application.TopRunnable!.WasDisposed); Exception exception = Record.Exception (Application.Shutdown); Assert.NotNull (exception); - Assert.False (Application.Current!.WasDisposed); + Assert.False (Application.TopRunnable!.WasDisposed); // It's up to caller to dispose it - Application.Current!.Dispose (); - Assert.True (Application.Current!.WasDisposed); + Application.TopRunnable!.Dispose (); + Assert.True (Application.TopRunnable!.WasDisposed); #endif - Assert.NotNull (Application.Current); + Assert.NotNull (Application.TopRunnable); Application.Shutdown (); - Assert.Null (Application.Current); + Assert.Null (Application.TopRunnable); } [Fact] @@ -839,7 +839,7 @@ public class ApplicationTests // the new(Toplevel) may be a derived class that is possible using Application static // properties that is only available after the Application.Init was called - Assert.Null (Application.Current); + Assert.Null (Application.TopRunnable); Assert.Throws (() => Application.Run (new Toplevel ())); @@ -849,25 +849,25 @@ public class ApplicationTests Application.Run (new Toplevel ()); Application.Iteration -= OnApplication_OnIteration; #if DEBUG_IDISPOSABLE - Assert.False (Application.Current!.WasDisposed); + Assert.False (Application.TopRunnable!.WasDisposed); Exception exception = Record.Exception (Application.Shutdown); Assert.NotNull (exception); - Assert.False (Application.Current!.WasDisposed); + Assert.False (Application.TopRunnable!.WasDisposed); // It's up to caller to dispose it - Application.Current!.Dispose (); - Assert.True (Application.Current!.WasDisposed); + Application.TopRunnable!.Dispose (); + Assert.True (Application.TopRunnable!.WasDisposed); #endif - Assert.NotNull (Application.Current); + Assert.NotNull (Application.TopRunnable); Application.Shutdown (); - Assert.Null (Application.Current); + Assert.Null (Application.TopRunnable); return; void OnApplication_OnIteration (object s, IterationEventArgs e) { - Assert.NotNull (Application.Current); + Assert.NotNull (Application.TopRunnable); Application.RequestStop (); } } @@ -892,9 +892,9 @@ public class ApplicationTests TaskScheduler.FromCurrentSynchronizationContext ()); Application.Run (); Assert.NotNull (Application.Driver); - Assert.NotNull (Application.Current); - Assert.False (Application.Current!.Running); - Application.Current!.Dispose (); + Assert.NotNull (Application.TopRunnable); + Assert.False (Application.TopRunnable!.Running); + Application.TopRunnable!.Dispose (); Application.Shutdown (); } diff --git a/Tests/UnitTests/Application/Mouse/ApplicationMouseEnterLeaveTests.cs b/Tests/UnitTests/Application/Mouse/ApplicationMouseEnterLeaveTests.cs index 06c3cc4d1..7fd6468d7 100644 --- a/Tests/UnitTests/Application/Mouse/ApplicationMouseEnterLeaveTests.cs +++ b/Tests/UnitTests/Application/Mouse/ApplicationMouseEnterLeaveTests.cs @@ -41,9 +41,9 @@ public class ApplicationMouseEnterLeaveTests public void RaiseMouseEnterLeaveEvents_MouseEntersView_CallsOnMouseEnter () { // Arrange - Application.Current = new () { Frame = new (0, 0, 10, 10) }; + Application.TopRunnable = new () { Frame = new (0, 0, 10, 10) }; var view = new TestView (); - Application.Current.Add (view); + Application.TopRunnable.Add (view); var mousePosition = new Point (1, 1); List currentViewsUnderMouse = new () { view }; @@ -66,7 +66,7 @@ public class ApplicationMouseEnterLeaveTests finally { // Cleanup - Application.Current?.Dispose (); + Application.TopRunnable?.Dispose (); Application.ResetState (); } } @@ -75,9 +75,9 @@ public class ApplicationMouseEnterLeaveTests public void RaiseMouseEnterLeaveEvents_MouseLeavesView_CallsOnMouseLeave () { // Arrange - Application.Current = new () { Frame = new (0, 0, 10, 10) }; + Application.TopRunnable = new () { Frame = new (0, 0, 10, 10) }; var view = new TestView (); - Application.Current.Add (view); + Application.TopRunnable.Add (view); var mousePosition = new Point (0, 0); List currentViewsUnderMouse = new (); var mouseEvent = new MouseEventArgs (); @@ -97,7 +97,7 @@ public class ApplicationMouseEnterLeaveTests finally { // Cleanup - Application.Current?.Dispose (); + Application.TopRunnable?.Dispose (); Application.ResetState (); } } @@ -106,7 +106,7 @@ public class ApplicationMouseEnterLeaveTests public void RaiseMouseEnterLeaveEvents_MouseMovesBetweenAdjacentViews_CallsOnMouseEnterAndLeave () { // Arrange - Application.Current = new () { Frame = new (0, 0, 10, 10) }; + Application.TopRunnable = new () { Frame = new (0, 0, 10, 10) }; var view1 = new TestView (); // at 1,1 to 2,2 var view2 = new TestView () // at 2,2 to 3,3 @@ -114,8 +114,8 @@ public class ApplicationMouseEnterLeaveTests X = 2, Y = 2 }; - Application.Current.Add (view1); - Application.Current.Add (view2); + Application.TopRunnable.Add (view1); + Application.TopRunnable.Add (view2); Application.CachedViewsUnderMouse.Clear (); @@ -126,7 +126,7 @@ public class ApplicationMouseEnterLeaveTests Application.RaiseMouseEnterLeaveEvents ( mousePosition, - Application.Current.GetViewsUnderLocation (mousePosition, ViewportSettingsFlags.TransparentMouse)); + Application.TopRunnable.GetViewsUnderLocation (mousePosition, ViewportSettingsFlags.TransparentMouse)); // Assert Assert.Equal (0, view1.OnMouseEnterCalled); @@ -139,7 +139,7 @@ public class ApplicationMouseEnterLeaveTests Application.RaiseMouseEnterLeaveEvents ( mousePosition, - Application.Current.GetViewsUnderLocation (mousePosition, ViewportSettingsFlags.TransparentMouse)); + Application.TopRunnable.GetViewsUnderLocation (mousePosition, ViewportSettingsFlags.TransparentMouse)); // Assert Assert.Equal (1, view1.OnMouseEnterCalled); @@ -152,7 +152,7 @@ public class ApplicationMouseEnterLeaveTests Application.RaiseMouseEnterLeaveEvents ( mousePosition, - Application.Current.GetViewsUnderLocation (mousePosition, ViewportSettingsFlags.TransparentMouse)); + Application.TopRunnable.GetViewsUnderLocation (mousePosition, ViewportSettingsFlags.TransparentMouse)); // Assert Assert.Equal (1, view1.OnMouseEnterCalled); @@ -165,7 +165,7 @@ public class ApplicationMouseEnterLeaveTests Application.RaiseMouseEnterLeaveEvents ( mousePosition, - Application.Current.GetViewsUnderLocation (mousePosition, ViewportSettingsFlags.TransparentMouse)); + Application.TopRunnable.GetViewsUnderLocation (mousePosition, ViewportSettingsFlags.TransparentMouse)); // Assert Assert.Equal (1, view1.OnMouseEnterCalled); @@ -178,7 +178,7 @@ public class ApplicationMouseEnterLeaveTests Application.RaiseMouseEnterLeaveEvents ( mousePosition, - Application.Current.GetViewsUnderLocation (mousePosition, ViewportSettingsFlags.TransparentMouse)); + Application.TopRunnable.GetViewsUnderLocation (mousePosition, ViewportSettingsFlags.TransparentMouse)); // Assert Assert.Equal (1, view1.OnMouseEnterCalled); @@ -189,7 +189,7 @@ public class ApplicationMouseEnterLeaveTests finally { // Cleanup - Application.Current?.Dispose (); + Application.TopRunnable?.Dispose (); Application.ResetState (); } } @@ -198,9 +198,9 @@ public class ApplicationMouseEnterLeaveTests public void RaiseMouseEnterLeaveEvents_NoViewsUnderMouse_DoesNotCallOnMouseEnterOrLeave () { // Arrange - Application.Current = new () { Frame = new (0, 0, 10, 10) }; + Application.TopRunnable = new () { Frame = new (0, 0, 10, 10) }; var view = new TestView (); - Application.Current.Add (view); + Application.TopRunnable.Add (view); var mousePosition = new Point (0, 0); List currentViewsUnderMouse = new (); var mouseEvent = new MouseEventArgs (); @@ -219,7 +219,7 @@ public class ApplicationMouseEnterLeaveTests finally { // Cleanup - Application.Current?.Dispose (); + Application.TopRunnable?.Dispose (); Application.ResetState (); } } @@ -228,7 +228,7 @@ public class ApplicationMouseEnterLeaveTests public void RaiseMouseEnterLeaveEvents_MouseMovesBetweenOverlappingPeerViews_CallsOnMouseEnterAndLeave () { // Arrange - Application.Current = new () { Frame = new (0, 0, 10, 10) }; + Application.TopRunnable = new () { Frame = new (0, 0, 10, 10) }; var view1 = new TestView { @@ -241,8 +241,8 @@ public class ApplicationMouseEnterLeaveTests X = 2, Y = 2 }; - Application.Current.Add (view1); - Application.Current.Add (view2); + Application.TopRunnable.Add (view1); + Application.TopRunnable.Add (view2); Application.CachedViewsUnderMouse.Clear (); @@ -253,7 +253,7 @@ public class ApplicationMouseEnterLeaveTests Application.RaiseMouseEnterLeaveEvents ( mousePosition, - Application.Current.GetViewsUnderLocation (mousePosition, ViewportSettingsFlags.TransparentMouse)); + Application.TopRunnable.GetViewsUnderLocation (mousePosition, ViewportSettingsFlags.TransparentMouse)); // Assert Assert.Equal (0, view1.OnMouseEnterCalled); @@ -266,7 +266,7 @@ public class ApplicationMouseEnterLeaveTests Application.RaiseMouseEnterLeaveEvents ( mousePosition, - Application.Current.GetViewsUnderLocation (mousePosition, ViewportSettingsFlags.TransparentMouse)); + Application.TopRunnable.GetViewsUnderLocation (mousePosition, ViewportSettingsFlags.TransparentMouse)); // Assert Assert.Equal (1, view1.OnMouseEnterCalled); @@ -279,7 +279,7 @@ public class ApplicationMouseEnterLeaveTests Application.RaiseMouseEnterLeaveEvents ( mousePosition, - Application.Current.GetViewsUnderLocation (mousePosition, ViewportSettingsFlags.TransparentMouse)); + Application.TopRunnable.GetViewsUnderLocation (mousePosition, ViewportSettingsFlags.TransparentMouse)); // Assert Assert.Equal (1, view1.OnMouseEnterCalled); @@ -292,7 +292,7 @@ public class ApplicationMouseEnterLeaveTests Application.RaiseMouseEnterLeaveEvents ( mousePosition, - Application.Current.GetViewsUnderLocation (mousePosition, ViewportSettingsFlags.TransparentMouse)); + Application.TopRunnable.GetViewsUnderLocation (mousePosition, ViewportSettingsFlags.TransparentMouse)); // Assert Assert.Equal (1, view1.OnMouseEnterCalled); @@ -305,7 +305,7 @@ public class ApplicationMouseEnterLeaveTests Application.RaiseMouseEnterLeaveEvents ( mousePosition, - Application.Current.GetViewsUnderLocation (mousePosition, ViewportSettingsFlags.TransparentMouse)); + Application.TopRunnable.GetViewsUnderLocation (mousePosition, ViewportSettingsFlags.TransparentMouse)); // Assert Assert.Equal (1, view1.OnMouseEnterCalled); @@ -318,7 +318,7 @@ public class ApplicationMouseEnterLeaveTests Application.RaiseMouseEnterLeaveEvents ( mousePosition, - Application.Current.GetViewsUnderLocation (mousePosition, ViewportSettingsFlags.TransparentMouse)); + Application.TopRunnable.GetViewsUnderLocation (mousePosition, ViewportSettingsFlags.TransparentMouse)); // Assert Assert.Equal (1, view1.OnMouseEnterCalled); @@ -329,7 +329,7 @@ public class ApplicationMouseEnterLeaveTests finally { // Cleanup - Application.Current?.Dispose (); + Application.TopRunnable?.Dispose (); Application.ResetState (); } } @@ -338,7 +338,7 @@ public class ApplicationMouseEnterLeaveTests public void RaiseMouseEnterLeaveEvents_MouseMovesBetweenOverlappingSubViews_CallsOnMouseEnterAndLeave () { // Arrange - Application.Current = new () { Frame = new (0, 0, 10, 10) }; + Application.TopRunnable = new () { Frame = new (0, 0, 10, 10) }; var view1 = new TestView { @@ -358,7 +358,7 @@ public class ApplicationMouseEnterLeaveTests Arrangement = ViewArrangement.Overlapped }; // at 2,2 to 4,4 (screen) view1.Add (subView); - Application.Current.Add (view1); + Application.TopRunnable.Add (view1); Application.CachedViewsUnderMouse.Clear (); @@ -372,7 +372,7 @@ public class ApplicationMouseEnterLeaveTests Application.RaiseMouseEnterLeaveEvents ( mousePosition, - Application.Current.GetViewsUnderLocation (mousePosition, ViewportSettingsFlags.TransparentMouse)); + Application.TopRunnable.GetViewsUnderLocation (mousePosition, ViewportSettingsFlags.TransparentMouse)); // Assert Assert.Equal (0, view1.OnMouseEnterCalled); @@ -385,7 +385,7 @@ public class ApplicationMouseEnterLeaveTests Application.RaiseMouseEnterLeaveEvents ( mousePosition, - Application.Current.GetViewsUnderLocation (mousePosition, ViewportSettingsFlags.TransparentMouse)); + Application.TopRunnable.GetViewsUnderLocation (mousePosition, ViewportSettingsFlags.TransparentMouse)); // Assert Assert.Equal (1, view1.OnMouseEnterCalled); @@ -398,7 +398,7 @@ public class ApplicationMouseEnterLeaveTests Application.RaiseMouseEnterLeaveEvents ( mousePosition, - Application.Current.GetViewsUnderLocation (mousePosition, ViewportSettingsFlags.TransparentMouse)); + Application.TopRunnable.GetViewsUnderLocation (mousePosition, ViewportSettingsFlags.TransparentMouse)); // Assert Assert.Equal (1, view1.OnMouseEnterCalled); @@ -411,7 +411,7 @@ public class ApplicationMouseEnterLeaveTests Application.RaiseMouseEnterLeaveEvents ( mousePosition, - Application.Current.GetViewsUnderLocation (mousePosition, ViewportSettingsFlags.TransparentMouse)); + Application.TopRunnable.GetViewsUnderLocation (mousePosition, ViewportSettingsFlags.TransparentMouse)); // Assert Assert.Equal (1, view1.OnMouseEnterCalled); @@ -424,7 +424,7 @@ public class ApplicationMouseEnterLeaveTests Application.RaiseMouseEnterLeaveEvents ( mousePosition, - Application.Current.GetViewsUnderLocation (mousePosition, ViewportSettingsFlags.TransparentMouse)); + Application.TopRunnable.GetViewsUnderLocation (mousePosition, ViewportSettingsFlags.TransparentMouse)); // Assert Assert.Equal (2, view1.OnMouseEnterCalled); @@ -437,7 +437,7 @@ public class ApplicationMouseEnterLeaveTests Application.RaiseMouseEnterLeaveEvents ( mousePosition, - Application.Current.GetViewsUnderLocation (mousePosition, ViewportSettingsFlags.TransparentMouse)); + Application.TopRunnable.GetViewsUnderLocation (mousePosition, ViewportSettingsFlags.TransparentMouse)); // Assert Assert.Equal (2, view1.OnMouseEnterCalled); @@ -450,7 +450,7 @@ public class ApplicationMouseEnterLeaveTests Application.RaiseMouseEnterLeaveEvents ( mousePosition, - Application.Current.GetViewsUnderLocation (mousePosition, ViewportSettingsFlags.TransparentMouse)); + Application.TopRunnable.GetViewsUnderLocation (mousePosition, ViewportSettingsFlags.TransparentMouse)); // Assert Assert.Equal (2, view1.OnMouseEnterCalled); @@ -463,7 +463,7 @@ public class ApplicationMouseEnterLeaveTests Application.RaiseMouseEnterLeaveEvents ( mousePosition, - Application.Current.GetViewsUnderLocation (mousePosition, ViewportSettingsFlags.TransparentMouse)); + Application.TopRunnable.GetViewsUnderLocation (mousePosition, ViewportSettingsFlags.TransparentMouse)); // Assert Assert.Equal (3, view1.OnMouseEnterCalled); @@ -474,7 +474,7 @@ public class ApplicationMouseEnterLeaveTests finally { // Cleanup - Application.Current?.Dispose (); + Application.TopRunnable?.Dispose (); Application.ResetState (); } } diff --git a/Tests/UnitTests/Application/Mouse/ApplicationMouseTests.cs b/Tests/UnitTests/Application/Mouse/ApplicationMouseTests.cs index 6116bcf63..08a97ea63 100644 --- a/Tests/UnitTests/Application/Mouse/ApplicationMouseTests.cs +++ b/Tests/UnitTests/Application/Mouse/ApplicationMouseTests.cs @@ -202,15 +202,15 @@ public class ApplicationMouseTests var clicked = false; - Application.Current = new Toplevel () + Application.TopRunnable = new Toplevel () { Id = "top", }; - Application.Current.X = 0; - Application.Current.Y = 0; - Application.Current.Width = size.Width * 2; - Application.Current.Height = size.Height * 2; - Application.Current.BorderStyle = LineStyle.None; + Application.TopRunnable.X = 0; + Application.TopRunnable.Y = 0; + Application.TopRunnable.Width = size.Width * 2; + Application.TopRunnable.Height = size.Height * 2; + Application.TopRunnable.BorderStyle = LineStyle.None; var view = new View { Id = "view", X = pos.X, Y = pos.Y, Width = size.Width, Height = size.Height }; @@ -218,7 +218,7 @@ public class ApplicationMouseTests view.BorderStyle = LineStyle.Single; view.CanFocus = true; - Application.Current.Add (view); + Application.TopRunnable.Add (view); var mouseEvent = new MouseEventArgs { Position = new (clickX, clickY), ScreenPosition = new (clickX, clickY), Flags = MouseFlags.Button1Clicked }; @@ -231,7 +231,7 @@ public class ApplicationMouseTests Application.RaiseMouseEvent (mouseEvent); Assert.Equal (expectedClicked, clicked); - Application.Current.Dispose (); + Application.TopRunnable.Dispose (); Application.ResetState (ignoreDisposed: true); } diff --git a/Tests/UnitTests/Application/SessionTokenTests.cs b/Tests/UnitTests/Application/SessionTokenTests.cs index 1e642d04d..f77aec9e9 100644 --- a/Tests/UnitTests/Application/SessionTokenTests.cs +++ b/Tests/UnitTests/Application/SessionTokenTests.cs @@ -29,7 +29,7 @@ public class SessionTokenTests Assert.NotNull (rs); Application.End (rs); - Assert.NotNull (Application.Current); + Assert.NotNull (Application.TopRunnable); // v2 does not use main loop, it uses MainLoop and its internal //Assert.NotNull (Application.MainLoop); diff --git a/Tests/UnitTests/Application/SynchronizatonContextTests.cs b/Tests/UnitTests/Application/SynchronizatonContextTests.cs index 915cb3024..7137389f7 100644 --- a/Tests/UnitTests/Application/SynchronizatonContextTests.cs +++ b/Tests/UnitTests/Application/SynchronizatonContextTests.cs @@ -39,7 +39,7 @@ public class SyncrhonizationContextTests Task.Run (() => { - while (Application.Current is null || Application.Current is { Running: false }) + while (Application.TopRunnable is null || Application.TopRunnable is { Running: false }) { Thread.Sleep (500); } @@ -56,7 +56,7 @@ public class SyncrhonizationContextTests null ); - if (Application.Current is { Running: true }) + if (Application.TopRunnable is { Running: true }) { Assert.False (success); } diff --git a/Tests/UnitTests/Dialogs/DialogTests.cs b/Tests/UnitTests/Dialogs/DialogTests.cs index a4ba9591a..72d479e1e 100644 --- a/Tests/UnitTests/Dialogs/DialogTests.cs +++ b/Tests/UnitTests/Dialogs/DialogTests.cs @@ -902,8 +902,8 @@ public class DialogTests (ITestOutputHelper output) #if DEBUG_IDISPOSABLE Assert.False (dlg.WasDisposed); - Assert.False (Application.Current!.WasDisposed); - Assert.Equal (dlg, Application.Current); + Assert.False (Application.TopRunnable!.WasDisposed); + Assert.Equal (dlg, Application.TopRunnable); #endif Assert.True (dlg.Canceled); @@ -925,8 +925,8 @@ public class DialogTests (ITestOutputHelper output) Application.Run (dlg2); Assert.True (dlg.WasDisposed); - Assert.False (Application.Current.WasDisposed); - Assert.Equal (dlg2, Application.Current); + Assert.False (Application.TopRunnable.WasDisposed); + Assert.Equal (dlg2, Application.TopRunnable); Assert.False (dlg2.WasDisposed); dlg2.Dispose (); @@ -937,10 +937,10 @@ public class DialogTests (ITestOutputHelper output) //Assert.NotNull (exception); //Assert.StartsWith ("Cannot access a disposed object.", exception.Message); - Assert.True (Application.Current.WasDisposed); + Assert.True (Application.TopRunnable.WasDisposed); Application.Shutdown (); Assert.True (dlg2.WasDisposed); - Assert.Null (Application.Current); + Assert.Null (Application.TopRunnable); #endif return; @@ -1174,8 +1174,8 @@ public class DialogTests (ITestOutputHelper output) switch (iterations) { case 0: - Application.Current!.SetNeedsLayout (); - Application.Current.SetNeedsDraw (); + Application.TopRunnable!.SetNeedsLayout (); + Application.TopRunnable.SetNeedsDraw (); break; @@ -1216,7 +1216,7 @@ public class DialogTests (ITestOutputHelper output) └───────────────────────┘", output); - Assert.False (Application.Current!.NewKeyDownEvent (Key.Enter)); + Assert.False (Application.TopRunnable!.NewKeyDownEvent (Key.Enter)); break; case 7: @@ -1410,9 +1410,9 @@ public class DialogTests (ITestOutputHelper output) #if DEBUG_IDISPOSABLE Assert.False (dlg.WasDisposed); - Assert.False (Application.Current!.WasDisposed); - Assert.NotEqual (top, Application.Current); - Assert.Equal (dlg, Application.Current); + Assert.False (Application.TopRunnable!.WasDisposed); + Assert.NotEqual (top, Application.TopRunnable); + Assert.Equal (dlg, Application.TopRunnable); #endif // dlg wasn't disposed yet and it's possible to access to his properties @@ -1426,11 +1426,11 @@ public class DialogTests (ITestOutputHelper output) top.Dispose (); #if DEBUG_IDISPOSABLE Assert.True (dlg.WasDisposed); - Assert.True (Application.Current.WasDisposed); - Assert.NotNull (Application.Current); + Assert.True (Application.TopRunnable.WasDisposed); + Assert.NotNull (Application.TopRunnable); #endif Application.Shutdown (); - Assert.Null (Application.Current); + Assert.Null (Application.TopRunnable); return; diff --git a/Tests/UnitTests/Dialogs/MessageBoxTests.cs b/Tests/UnitTests/Dialogs/MessageBoxTests.cs index 0699309b7..d602eef96 100644 --- a/Tests/UnitTests/Dialogs/MessageBoxTests.cs +++ b/Tests/UnitTests/Dialogs/MessageBoxTests.cs @@ -193,7 +193,7 @@ public class MessageBoxTests (ITestOutputHelper output) } else if (iterations == 1) { - mbFrame = Application.Current!.Frame; + mbFrame = Application.TopRunnable!.Frame; Application.RequestStop (); } } @@ -378,8 +378,8 @@ public class MessageBoxTests (ITestOutputHelper output) { AutoInitShutdownAttribute.RunIteration (); - Assert.IsType (Application.Current); - Assert.Equal (new (height, width), Application.Current.Frame.Size); + Assert.IsType (Application.TopRunnable); + Assert.Equal (new (height, width), Application.TopRunnable.Frame.Size); Application.RequestStop (); } @@ -415,8 +415,8 @@ public class MessageBoxTests (ITestOutputHelper output) { AutoInitShutdownAttribute.RunIteration (); - Assert.IsType (Application.Current); - Assert.Equal (new (height, width), Application.Current.Frame.Size); + Assert.IsType (Application.TopRunnable); + Assert.Equal (new (height, width), Application.TopRunnable.Frame.Size); Application.RequestStop (); } @@ -448,8 +448,8 @@ public class MessageBoxTests (ITestOutputHelper output) { AutoInitShutdownAttribute.RunIteration (); - Assert.IsType (Application.Current); - Assert.Equal (new (height, width), Application.Current.Frame.Size); + Assert.IsType (Application.TopRunnable); + Assert.Equal (new (height, width), Application.TopRunnable.Frame.Size); Application.RequestStop (); } diff --git a/Tests/UnitTests/View/Adornment/AdornmentSubViewTests.cs b/Tests/UnitTests/View/Adornment/AdornmentSubViewTests.cs index 7bfa4747a..d5015c7b4 100644 --- a/Tests/UnitTests/View/Adornment/AdornmentSubViewTests.cs +++ b/Tests/UnitTests/View/Adornment/AdornmentSubViewTests.cs @@ -14,14 +14,14 @@ public class AdornmentSubViewTests (ITestOutputHelper output) [InlineData (2, 1, true)] public void Adornment_WithSubView_Finds (int viewMargin, int subViewMargin, bool expectedFound) { - Application.Current = new Toplevel() + Application.TopRunnable = new Toplevel() { Width = 10, Height = 10 }; - Application.Current.Margin!.Thickness = new Thickness (viewMargin); + Application.TopRunnable.Margin!.Thickness = new Thickness (viewMargin); // Turn of TransparentMouse for the test - Application.Current.Margin!.ViewportSettings = ViewportSettingsFlags.None; + Application.TopRunnable.Margin!.ViewportSettings = ViewportSettingsFlags.None; var subView = new View () { @@ -34,26 +34,26 @@ public class AdornmentSubViewTests (ITestOutputHelper output) // Turn of TransparentMouse for the test subView.Margin!.ViewportSettings = ViewportSettingsFlags.None; - Application.Current.Margin!.Add (subView); - Application.Current.Layout (); + Application.TopRunnable.Margin!.Add (subView); + Application.TopRunnable.Layout (); - var foundView = Application.Current.GetViewsUnderLocation (new Point(0, 0), ViewportSettingsFlags.None).LastOrDefault (); + var foundView = Application.TopRunnable.GetViewsUnderLocation (new Point(0, 0), ViewportSettingsFlags.None).LastOrDefault (); bool found = foundView == subView || foundView == subView.Margin; Assert.Equal (expectedFound, found); - Application.Current.Dispose (); + Application.TopRunnable.Dispose (); Application.ResetState (ignoreDisposed: true); } [Fact] public void Adornment_WithNonVisibleSubView_Finds_Adornment () { - Application.Current = new Toplevel () + Application.TopRunnable = new Toplevel () { Width = 10, Height = 10 }; - Application.Current.Padding.Thickness = new Thickness (1); + Application.TopRunnable.Padding.Thickness = new Thickness (1); var subView = new View () { @@ -63,11 +63,11 @@ public class AdornmentSubViewTests (ITestOutputHelper output) Height = 1, Visible = false }; - Application.Current.Padding.Add (subView); - Application.Current.Layout (); + Application.TopRunnable.Padding.Add (subView); + Application.TopRunnable.Layout (); - Assert.Equal (Application.Current.Padding, Application.Current.GetViewsUnderLocation (new Point(0, 0), ViewportSettingsFlags.None).LastOrDefault ()); - Application.Current?.Dispose (); + Assert.Equal (Application.TopRunnable.Padding, Application.TopRunnable.GetViewsUnderLocation (new Point(0, 0), ViewportSettingsFlags.None).LastOrDefault ()); + Application.TopRunnable?.Dispose (); Application.ResetState (ignoreDisposed: true); } } diff --git a/Tests/UnitTests/View/Adornment/MarginTests.cs b/Tests/UnitTests/View/Adornment/MarginTests.cs index 3a4bc20ba..6a3cd0b8d 100644 --- a/Tests/UnitTests/View/Adornment/MarginTests.cs +++ b/Tests/UnitTests/View/Adornment/MarginTests.cs @@ -15,27 +15,27 @@ public class MarginTests (ITestOutputHelper output) view.Margin!.Diagnostics = ViewDiagnosticFlags.Thickness; view.Margin.Thickness = new (1); - Application.Current = new Toplevel (); - Application.SessionStack.Push (Application.Current); + Application.TopRunnable = new Toplevel (); + Application.SessionStack.Push (Application.TopRunnable); - Application.Current.SetScheme (new() + Application.TopRunnable.SetScheme (new() { Normal = new (Color.Red, Color.Green), Focus = new (Color.Green, Color.Red) }); - Application.Current.Add (view); + Application.TopRunnable.Add (view); Assert.Equal (ColorName16.Red, view.Margin.GetAttributeForRole (VisualRole.Normal).Foreground.GetClosestNamedColor16 ()); - Assert.Equal (ColorName16.Red, Application.Current.GetAttributeForRole (VisualRole.Normal).Foreground.GetClosestNamedColor16 ()); + Assert.Equal (ColorName16.Red, Application.TopRunnable.GetAttributeForRole (VisualRole.Normal).Foreground.GetClosestNamedColor16 ()); - Application.Current.BeginInit (); - Application.Current.EndInit (); + Application.TopRunnable.BeginInit (); + Application.TopRunnable.EndInit (); Application.LayoutAndDraw(); DriverAssert.AssertDriverContentsAre ( @"", output ); - DriverAssert.AssertDriverAttributesAre ("0", output, null, Application.Current.GetAttributeForRole (VisualRole.Normal)); + DriverAssert.AssertDriverAttributesAre ("0", output, null, Application.TopRunnable.GetAttributeForRole (VisualRole.Normal)); Application.ResetState (true); } @@ -51,20 +51,20 @@ public class MarginTests (ITestOutputHelper output) view.Margin.Thickness = new (1); view.Margin.ViewportSettings = ViewportSettingsFlags.None; - Application.Current = new Toplevel (); - Application.SessionStack.Push (Application.Current); + Application.TopRunnable = new Toplevel (); + Application.SessionStack.Push (Application.TopRunnable); - Application.Current.SetScheme (new () + Application.TopRunnable.SetScheme (new () { Normal = new (Color.Red, Color.Green), Focus = new (Color.Green, Color.Red) }); - Application.Current.Add (view); + Application.TopRunnable.Add (view); Assert.Equal (ColorName16.Red, view.Margin.GetAttributeForRole (VisualRole.Normal).Foreground.GetClosestNamedColor16 ()); - Assert.Equal (ColorName16.Red, Application.Current.GetAttributeForRole (VisualRole.Normal).Foreground.GetClosestNamedColor16 ()); + Assert.Equal (ColorName16.Red, Application.TopRunnable.GetAttributeForRole (VisualRole.Normal).Foreground.GetClosestNamedColor16 ()); - Application.Current.BeginInit (); - Application.Current.EndInit (); + Application.TopRunnable.BeginInit (); + Application.TopRunnable.EndInit (); Application.LayoutAndDraw (); DriverAssert.AssertDriverContentsAre ( @@ -74,7 +74,7 @@ M M MMM", output ); - DriverAssert.AssertDriverAttributesAre ("0", output, null, Application.Current.GetAttributeForRole (VisualRole.Normal)); + DriverAssert.AssertDriverAttributesAre ("0", output, null, Application.TopRunnable.GetAttributeForRole (VisualRole.Normal)); Application.ResetState (true); } diff --git a/Tests/UnitTests/View/Keyboard/KeyBindingsTests.cs b/Tests/UnitTests/View/Keyboard/KeyBindingsTests.cs index 236ba0600..eddee1293 100644 --- a/Tests/UnitTests/View/Keyboard/KeyBindingsTests.cs +++ b/Tests/UnitTests/View/Keyboard/KeyBindingsTests.cs @@ -160,14 +160,14 @@ public class KeyBindingsTests () var hotKeyRaised = false; var acceptRaised = false; var selectRaised = false; - Application.Current = new Toplevel (); + Application.TopRunnable = new Toplevel (); var view = new View { CanFocus = true, HotKeySpecifier = new Rune ('_'), Title = "_Test" }; - Application.Current.Add (view); + Application.TopRunnable.Add (view); view.HandlingHotKey += (s, e) => hotKeyRaised = true; view.Accepting += (s, e) => acceptRaised = true; view.Selecting += (s, e) => selectRaised = true; @@ -191,7 +191,7 @@ public class KeyBindingsTests () Assert.False (acceptRaised); Assert.False (selectRaised); - Application.Current.Dispose (); + Application.TopRunnable.Dispose (); Application.ResetState (true); } // tests that test KeyBindingScope.Focus and KeyBindingScope.HotKey (tests for KeyBindingScope.Application are in Application/KeyboardTests.cs) diff --git a/Tests/UnitTests/View/Layout/GetViewsUnderLocationTests.cs b/Tests/UnitTests/View/Layout/GetViewsUnderLocationTests.cs index 97a4fc19d..c19411ac6 100644 --- a/Tests/UnitTests/View/Layout/GetViewsUnderLocationTests.cs +++ b/Tests/UnitTests/View/Layout/GetViewsUnderLocationTests.cs @@ -70,22 +70,22 @@ public class GetViewsUnderLocationTests ) { // Arrange - Application.Current = new () + Application.TopRunnable = new () { Id = "Top", Frame = new (frameX, frameY, 10, 10) }; - Application.Current.Margin!.Thickness = new (marginThickness); - Application.Current.Margin!.Id = "Margin"; - Application.Current.Border!.Thickness = new (borderThickness); - Application.Current.Border!.Id = "Border"; - Application.Current.Padding!.Thickness = new (paddingThickness); - Application.Current.Padding.Id = "Padding"; + Application.TopRunnable.Margin!.Thickness = new (marginThickness); + Application.TopRunnable.Margin!.Id = "Margin"; + Application.TopRunnable.Border!.Thickness = new (borderThickness); + Application.TopRunnable.Border!.Id = "Border"; + Application.TopRunnable.Padding!.Thickness = new (paddingThickness); + Application.TopRunnable.Padding.Id = "Padding"; var location = new Point (testX, testY); // Act - List viewsUnderMouse = Application.Current.GetViewsUnderLocation (location, ViewportSettingsFlags.TransparentMouse); + List viewsUnderMouse = Application.TopRunnable.GetViewsUnderLocation (location, ViewportSettingsFlags.TransparentMouse); // Assert if (expectedViewsFound.Length == 0) @@ -98,7 +98,7 @@ public class GetViewsUnderLocationTests Assert.Equal (expectedViewsFound, foundIds); } - Application.Current.Dispose (); + Application.TopRunnable.Dispose (); Application.ResetState (true); } @@ -109,7 +109,7 @@ public class GetViewsUnderLocationTests public void Returns_Top_If_No_SubViews (int testX, int testY) { // Arrange - Application.Current = new () + Application.TopRunnable = new () { Frame = new (0, 0, 10, 10) }; @@ -117,11 +117,11 @@ public class GetViewsUnderLocationTests var location = new Point (testX, testY); // Act - List viewsUnderMouse = Application.Current.GetViewsUnderLocation (location, ViewportSettingsFlags.TransparentMouse); + List viewsUnderMouse = Application.TopRunnable.GetViewsUnderLocation (location, ViewportSettingsFlags.TransparentMouse); // Assert - Assert.Contains (viewsUnderMouse, v => v == Application.Current); - Application.Current.Dispose (); + Assert.Contains (viewsUnderMouse, v => v == Application.TopRunnable); + Application.TopRunnable.Dispose (); Application.ResetState (true); } @@ -134,13 +134,13 @@ public class GetViewsUnderLocationTests { Application.ResetState (true); - Application.Current = new () + Application.TopRunnable = new () { Width = 10, Height = 10 }; - Assert.Same (Application.Current, Application.Current.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse).LastOrDefault ()); - Application.Current.Dispose (); + Assert.Same (Application.TopRunnable, Application.TopRunnable.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse).LastOrDefault ()); + Application.TopRunnable.Dispose (); Application.ResetState (true); } @@ -155,7 +155,7 @@ public class GetViewsUnderLocationTests [InlineData (5, 6, true)] public void Returns_Correct_If_SubViews (int testX, int testY, bool expectedSubViewFound) { - Application.Current = new () + Application.TopRunnable = new () { Width = 10, Height = 10 }; @@ -165,12 +165,12 @@ public class GetViewsUnderLocationTests X = 1, Y = 2, Width = 5, Height = 5 }; - Application.Current.Add (subview); + Application.TopRunnable.Add (subview); - View? found = Application.Current.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse).LastOrDefault (); + View? found = Application.TopRunnable.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse).LastOrDefault (); Assert.Equal (expectedSubViewFound, found == subview); - Application.Current.Dispose (); + Application.TopRunnable.Dispose (); Application.ResetState (true); } @@ -184,7 +184,7 @@ public class GetViewsUnderLocationTests [InlineData (5, 6, false)] public void Returns_Null_If_SubView_NotVisible (int testX, int testY, bool expectedSubViewFound) { - Application.Current = new () + Application.TopRunnable = new () { Width = 10, Height = 10 }; @@ -195,12 +195,12 @@ public class GetViewsUnderLocationTests Width = 5, Height = 5, Visible = false }; - Application.Current.Add (subview); + Application.TopRunnable.Add (subview); - View? found = Application.Current.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse).LastOrDefault (); + View? found = Application.TopRunnable.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse).LastOrDefault (); Assert.Equal (expectedSubViewFound, found == subview); - Application.Current.Dispose (); + Application.TopRunnable.Dispose (); Application.ResetState (true); } @@ -214,7 +214,7 @@ public class GetViewsUnderLocationTests [InlineData (5, 6, false)] public void Returns_Null_If_Not_Visible_And_SubView_Visible (int testX, int testY, bool expectedSubViewFound) { - Application.Current = new () + Application.TopRunnable = new () { Width = 10, Height = 10, Visible = false @@ -225,14 +225,14 @@ public class GetViewsUnderLocationTests X = 1, Y = 2, Width = 5, Height = 5 }; - Application.Current.Add (subview); + Application.TopRunnable.Add (subview); subview.Visible = true; Assert.True (subview.Visible); - Assert.False (Application.Current.Visible); - View? found = Application.Current.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse).LastOrDefault (); + Assert.False (Application.TopRunnable.Visible); + View? found = Application.TopRunnable.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse).LastOrDefault (); Assert.Equal (expectedSubViewFound, found == subview); - Application.Current.Dispose (); + Application.TopRunnable.Dispose (); Application.ResetState (true); } @@ -249,23 +249,23 @@ public class GetViewsUnderLocationTests [InlineData (6, 7, true)] public void Returns_Correct_If_Start_Has_Adornments (int testX, int testY, bool expectedSubViewFound) { - Application.Current = new () + Application.TopRunnable = new () { Width = 10, Height = 10 }; - Application.Current.Margin!.Thickness = new (1); + Application.TopRunnable.Margin!.Thickness = new (1); var subview = new View { X = 1, Y = 2, Width = 5, Height = 5 }; - Application.Current.Add (subview); + Application.TopRunnable.Add (subview); - View? found = Application.Current.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse).LastOrDefault (); + View? found = Application.TopRunnable.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse).LastOrDefault (); Assert.Equal (expectedSubViewFound, found == subview); - Application.Current.Dispose (); + Application.TopRunnable.Dispose (); Application.ResetState (true); } @@ -280,24 +280,24 @@ public class GetViewsUnderLocationTests [InlineData (-1, 0, 0, false)] public void Returns_Correct_If_Start_Has_Offset_Viewport (int offset, int testX, int testY, bool expectedSubViewFound) { - Application.Current = new () + Application.TopRunnable = new () { Width = 10, Height = 10, ViewportSettings = ViewportSettingsFlags.AllowNegativeLocation }; - Application.Current.Viewport = new (offset, offset, 10, 10); + Application.TopRunnable.Viewport = new (offset, offset, 10, 10); var subview = new View { X = 1, Y = 1, Width = 2, Height = 2 }; - Application.Current.Add (subview); + Application.TopRunnable.Add (subview); - View? found = Application.Current.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse).LastOrDefault (); + View? found = Application.TopRunnable.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse).LastOrDefault (); Assert.Equal (expectedSubViewFound, found == subview); - Application.Current.Dispose (); + Application.TopRunnable.Dispose (); Application.ResetState (true); } @@ -313,25 +313,25 @@ public class GetViewsUnderLocationTests [InlineData (6, 7, false)] public void Returns_Correct_If_Start_Has_Adornment_WithSubView (int testX, int testY, bool expectedSubViewFound) { - Application.Current = new () + Application.TopRunnable = new () { Width = 10, Height = 10 }; - Application.Current.Padding!.Thickness = new (1); + Application.TopRunnable.Padding!.Thickness = new (1); var subview = new View { X = Pos.AnchorEnd (1), Y = Pos.AnchorEnd (1), Width = 1, Height = 1 }; - Application.Current.Padding.Add (subview); - Application.Current.BeginInit (); - Application.Current.EndInit (); + Application.TopRunnable.Padding.Add (subview); + Application.TopRunnable.BeginInit (); + Application.TopRunnable.EndInit (); - View? found = Application.Current.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse).LastOrDefault (); + View? found = Application.TopRunnable.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse).LastOrDefault (); Assert.Equal (expectedSubViewFound, found == subview); - Application.Current.Dispose (); + Application.TopRunnable.Dispose (); Application.ResetState (true); } @@ -347,17 +347,17 @@ public class GetViewsUnderLocationTests { Application.ResetState (true); - Application.Current = new () + Application.TopRunnable = new () { Id = "Top", Width = 10, Height = 10 }; - Application.Current.Margin!.Thickness = new (1); - Application.Current.Margin!.Id = "Margin"; - Application.Current.Border!.Thickness = new (1); - Application.Current.Border!.Id = "Border"; - Application.Current.Padding!.Thickness = new (1); - Application.Current.Padding.Id = "Padding"; + Application.TopRunnable.Margin!.Thickness = new (1); + Application.TopRunnable.Margin!.Id = "Margin"; + Application.TopRunnable.Border!.Thickness = new (1); + Application.TopRunnable.Border!.Id = "Border"; + Application.TopRunnable.Padding!.Thickness = new (1); + Application.TopRunnable.Padding.Id = "Padding"; var subview = new View { @@ -365,13 +365,13 @@ public class GetViewsUnderLocationTests X = 1, Y = 1, Width = 1, Height = 1 }; - Application.Current.Add (subview); + Application.TopRunnable.Add (subview); - List viewsUnderMouse = Application.Current.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse); + List viewsUnderMouse = Application.TopRunnable.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse); string [] foundIds = viewsUnderMouse.Select (v => v!.Id).ToArray (); Assert.Equal (expectedViewsFound, foundIds); - Application.Current.Dispose (); + Application.TopRunnable.Dispose (); Application.ResetState (true); } @@ -388,7 +388,7 @@ public class GetViewsUnderLocationTests [InlineData (2, 3, new [] { "Top", "subview" })] public void Returns_Correct_If_SubView_Has_Adornments (int testX, int testY, string [] expectedViewsFound) { - Application.Current = new () + Application.TopRunnable = new () { Id = "Top", Width = 10, Height = 10 @@ -402,13 +402,13 @@ public class GetViewsUnderLocationTests }; subview.Border!.Thickness = new (1); subview.Border!.Id = "border"; - Application.Current.Add (subview); + Application.TopRunnable.Add (subview); - List viewsUnderMouse = Application.Current.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse); + List viewsUnderMouse = Application.TopRunnable.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse); string [] foundIds = viewsUnderMouse.Select (v => v!.Id).ToArray (); Assert.Equal (expectedViewsFound, foundIds); - Application.Current.Dispose (); + Application.TopRunnable.Dispose (); Application.ResetState (true); } @@ -425,7 +425,7 @@ public class GetViewsUnderLocationTests [InlineData (2, 3, new [] { "Top", "subview" })] public void Returns_Correct_If_SubView_Has_Adornments_With_TransparentMouse (int testX, int testY, string [] expectedViewsFound) { - Application.Current = new () + Application.TopRunnable = new () { Id = "Top", Width = 10, Height = 10 @@ -440,13 +440,13 @@ public class GetViewsUnderLocationTests subview.Border!.Thickness = new (1); subview.Border!.ViewportSettings = ViewportSettingsFlags.TransparentMouse; subview.Border!.Id = "border"; - Application.Current.Add (subview); + Application.TopRunnable.Add (subview); - List viewsUnderMouse = Application.Current.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse); + List viewsUnderMouse = Application.TopRunnable.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse); string [] foundIds = viewsUnderMouse.Select (v => v!.Id).ToArray (); Assert.Equal (expectedViewsFound, foundIds); - Application.Current.Dispose (); + Application.TopRunnable.Dispose (); Application.ResetState (true); } @@ -463,7 +463,7 @@ public class GetViewsUnderLocationTests [InlineData (5, 5, true)] public void Returns_Correct_If_SubView_Has_Adornment_WithSubView (int testX, int testY, bool expectedSubViewFound) { - Application.Current = new () + Application.TopRunnable = new () { Width = 10, Height = 10 }; @@ -486,14 +486,14 @@ public class GetViewsUnderLocationTests Height = 1 }; subview.Padding.Add (paddingSubView); - Application.Current.Add (subview); - Application.Current.BeginInit (); - Application.Current.EndInit (); + Application.TopRunnable.Add (subview); + Application.TopRunnable.BeginInit (); + Application.TopRunnable.EndInit (); - View? found = Application.Current.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse).LastOrDefault (); + View? found = Application.TopRunnable.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse).LastOrDefault (); Assert.Equal (expectedSubViewFound, found == paddingSubView); - Application.Current.Dispose (); + Application.TopRunnable.Dispose (); Application.ResetState (true); } @@ -510,7 +510,7 @@ public class GetViewsUnderLocationTests [InlineData (5, 5, true)] public void Returns_Correct_If_SubView_Is_Scrolled_And_Has_Adornment_WithSubView (int testX, int testY, bool expectedSubViewFound) { - Application.Current = new () + Application.TopRunnable = new () { Width = 10, Height = 10 }; @@ -537,14 +537,14 @@ public class GetViewsUnderLocationTests Height = 1 }; subview.Padding.Add (paddingSubView); - Application.Current.Add (subview); - Application.Current.BeginInit (); - Application.Current.EndInit (); + Application.TopRunnable.Add (subview); + Application.TopRunnable.BeginInit (); + Application.TopRunnable.EndInit (); - View? found = Application.Current.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse).LastOrDefault (); + View? found = Application.TopRunnable.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse).LastOrDefault (); Assert.Equal (expectedSubViewFound, found == paddingSubView); - Application.Current.Dispose (); + Application.TopRunnable.Dispose (); Application.ResetState (true); } @@ -560,7 +560,7 @@ public class GetViewsUnderLocationTests [InlineData (5, 5, 2)] public void Returns_Correct_With_NestedSubViews (int testX, int testY, int expectedSubViewFound) { - Application.Current = new () + Application.TopRunnable = new () { Width = 10, Height = 10 }; @@ -583,11 +583,11 @@ public class GetViewsUnderLocationTests } } - Application.Current.Add (subviews [0]); + Application.TopRunnable.Add (subviews [0]); - View? found = Application.Current.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse).LastOrDefault (); + View? found = Application.TopRunnable.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse).LastOrDefault (); Assert.Equal (expectedSubViewFound, subviews.IndexOf (found!)); - Application.Current.Dispose (); + Application.TopRunnable.Dispose (); Application.ResetState (true); } @@ -604,7 +604,7 @@ public class GetViewsUnderLocationTests public void Tiled_SubViews (int mouseX, int mouseY, string [] viewIdStrings) { // Arrange - Application.Current = new () + Application.TopRunnable = new () { Frame = new (0, 0, 10, 10), Id = "top" @@ -630,15 +630,15 @@ public class GetViewsUnderLocationTests Arrangement = ViewArrangement.Overlapped }; // at 2,2 to 4,3 (screen) view.Add (subView); - Application.Current.Add (view); + Application.TopRunnable.Add (view); - List found = Application.Current.GetViewsUnderLocation (new (mouseX, mouseY), ViewportSettingsFlags.TransparentMouse); + List found = Application.TopRunnable.GetViewsUnderLocation (new (mouseX, mouseY), ViewportSettingsFlags.TransparentMouse); string [] foundIds = found.Select (v => v!.Id).ToArray (); Assert.Equal (viewIdStrings, foundIds); - Application.Current.Dispose (); + Application.TopRunnable.Dispose (); Application.ResetState (true); } @@ -656,7 +656,7 @@ public class GetViewsUnderLocationTests public void Popover (int mouseX, int mouseY, string [] viewIdStrings) { // Arrange - Application.Current = new () + Application.TopRunnable = new () { Frame = new (0, 0, 10, 10), Id = "top" @@ -683,15 +683,15 @@ public class GetViewsUnderLocationTests }; // at 2,2 to 4,3 (screen) view.Add (popOver); - Application.Current.Add (view); + Application.TopRunnable.Add (view); - List found = Application.Current.GetViewsUnderLocation (new (mouseX, mouseY), ViewportSettingsFlags.TransparentMouse); + List found = Application.TopRunnable.GetViewsUnderLocation (new (mouseX, mouseY), ViewportSettingsFlags.TransparentMouse); string [] foundIds = found.Select (v => v!.Id).ToArray (); Assert.Equal (viewIdStrings, foundIds); - Application.Current.Dispose (); + Application.TopRunnable.Dispose (); Application.ResetState (true); } @@ -717,9 +717,9 @@ public class GetViewsUnderLocationTests Application.SessionStack.Clear (); Application.SessionStack.Push (topToplevel); Application.SessionStack.Push (secondaryToplevel); - Application.Current = secondaryToplevel; + Application.TopRunnable = secondaryToplevel; - List found = Application.Current.GetViewsUnderLocation (new (2, 2), ViewportSettingsFlags.TransparentMouse); + List found = Application.TopRunnable.GetViewsUnderLocation (new (2, 2), ViewportSettingsFlags.TransparentMouse); Assert.Contains (found, v => v?.Id == topToplevel.Id); Assert.Contains (found, v => v == topToplevel); @@ -751,9 +751,9 @@ public class GetViewsUnderLocationTests Application.SessionStack.Clear (); Application.SessionStack.Push (topToplevel); Application.SessionStack.Push (secondaryToplevel); - Application.Current = secondaryToplevel; + Application.TopRunnable = secondaryToplevel; - List found = Application.Current.GetViewsUnderLocation (new (7, 7), ViewportSettingsFlags.TransparentMouse); + List found = Application.TopRunnable.GetViewsUnderLocation (new (7, 7), ViewportSettingsFlags.TransparentMouse); Assert.Contains (found, v => v?.Id == secondaryToplevel.Id); Assert.DoesNotContain (found, v => v?.Id == topToplevel.Id); @@ -784,17 +784,17 @@ public class GetViewsUnderLocationTests Application.SessionStack.Clear (); Application.SessionStack.Push (topToplevel); Application.SessionStack.Push (secondaryToplevel); - Application.Current = secondaryToplevel; + Application.TopRunnable = secondaryToplevel; secondaryToplevel.Margin!.ViewportSettings = ViewportSettingsFlags.None; - List found = Application.Current.GetViewsUnderLocation (new (5, 5), ViewportSettingsFlags.TransparentMouse); + List found = Application.TopRunnable.GetViewsUnderLocation (new (5, 5), ViewportSettingsFlags.TransparentMouse); Assert.Contains (found, v => v == secondaryToplevel); Assert.Contains (found, v => v == secondaryToplevel.Margin); Assert.DoesNotContain (found, v => v?.Id == topToplevel.Id); secondaryToplevel.Margin!.ViewportSettings = ViewportSettingsFlags.TransparentMouse; - found = Application.Current.GetViewsUnderLocation (new (5, 5), ViewportSettingsFlags.TransparentMouse); + found = Application.TopRunnable.GetViewsUnderLocation (new (5, 5), ViewportSettingsFlags.TransparentMouse); Assert.DoesNotContain (found, v => v == secondaryToplevel); Assert.DoesNotContain (found, v => v == secondaryToplevel.Margin); Assert.Contains (found, v => v?.Id == topToplevel.Id); @@ -827,9 +827,9 @@ public class GetViewsUnderLocationTests Application.SessionStack.Clear (); Application.SessionStack.Push (topToplevel); Application.SessionStack.Push (secondaryToplevel); - Application.Current = secondaryToplevel; + Application.TopRunnable = secondaryToplevel; - List found = Application.Current.GetViewsUnderLocation (new (20, 20), ViewportSettingsFlags.TransparentMouse); + List found = Application.TopRunnable.GetViewsUnderLocation (new (20, 20), ViewportSettingsFlags.TransparentMouse); Assert.Empty (found); topToplevel.Dispose (); diff --git a/Tests/UnitTests/View/Layout/Pos.CombineTests.cs b/Tests/UnitTests/View/Layout/Pos.CombineTests.cs index cbbf50da6..6a495968d 100644 --- a/Tests/UnitTests/View/Layout/Pos.CombineTests.cs +++ b/Tests/UnitTests/View/Layout/Pos.CombineTests.cs @@ -40,7 +40,7 @@ public class PosCombineTests (ITestOutputHelper output) [SetupFakeApplication] public void PosCombine_DimCombine_View_With_SubViews () { - Application.Current = new Toplevel () { Width = 80, Height = 25 }; + Application.TopRunnable = new Toplevel () { Width = 80, Height = 25 }; var win1 = new Window { Id = "win1", Width = 20, Height = 10 }; var view1 = new View { @@ -59,18 +59,18 @@ public class PosCombineTests (ITestOutputHelper output) view2.Add (view3); win2.Add (view2); win1.Add (view1, win2); - Application.Current.Add (win1); - Application.Current.Layout (); + Application.TopRunnable.Add (win1); + Application.TopRunnable.Layout (); - Assert.Equal (new Rectangle (0, 0, 80, 25), Application.Current.Frame); + Assert.Equal (new Rectangle (0, 0, 80, 25), Application.TopRunnable.Frame); Assert.Equal (new Rectangle (0, 0, 5, 1), view1.Frame); Assert.Equal (new Rectangle (0, 0, 20, 10), win1.Frame); Assert.Equal (new Rectangle (0, 2, 10, 3), win2.Frame); Assert.Equal (new Rectangle (0, 0, 8, 1), view2.Frame); Assert.Equal (new Rectangle (0, 0, 7, 1), view3.Frame); - var foundView = Application.Current.GetViewsUnderLocation (new Point(9, 4), ViewportSettingsFlags.None).LastOrDefault (); + var foundView = Application.TopRunnable.GetViewsUnderLocation (new Point(9, 4), ViewportSettingsFlags.None).LastOrDefault (); Assert.Equal (foundView, view2); - Application.Current.Dispose (); + Application.TopRunnable.Dispose (); } [Fact] @@ -89,13 +89,13 @@ public class PosCombineTests (ITestOutputHelper output) top.Add (w); Application.Begin (top); - f.X = Pos.X (Application.Current) + Pos.X (v2) - Pos.X (v1); - f.Y = Pos.Y (Application.Current) + Pos.Y (v2) - Pos.Y (v1); + f.X = Pos.X (Application.TopRunnable) + Pos.X (v2) - Pos.X (v1); + f.Y = Pos.Y (Application.TopRunnable) + Pos.Y (v2) - Pos.Y (v1); - Application.Current.SubViewsLaidOut += (s, e) => + Application.TopRunnable.SubViewsLaidOut += (s, e) => { - Assert.Equal (0, Application.Current.Frame.X); - Assert.Equal (0, Application.Current.Frame.Y); + Assert.Equal (0, Application.TopRunnable.Frame.X); + Assert.Equal (0, Application.TopRunnable.Frame.Y); Assert.Equal (2, w.Frame.X); Assert.Equal (2, w.Frame.Y); Assert.Equal (2, f.Frame.X); @@ -109,7 +109,7 @@ public class PosCombineTests (ITestOutputHelper output) Application.StopAfterFirstIteration = true; Assert.Throws (() => Application.Run ()); - Application.Current.Dispose (); + Application.TopRunnable.Dispose (); top.Dispose (); Application.Shutdown (); } diff --git a/Tests/UnitTests/View/Layout/SetLayoutTests.cs b/Tests/UnitTests/View/Layout/SetLayoutTests.cs index 7ccf52dca..e5eb6b027 100644 --- a/Tests/UnitTests/View/Layout/SetLayoutTests.cs +++ b/Tests/UnitTests/View/Layout/SetLayoutTests.cs @@ -12,7 +12,7 @@ public class SetLayoutTests (ITestOutputHelper output) [AutoInitShutdown] public void Screen_Size_Change_Causes_Layout () { - Application.Current = new (); + Application.TopRunnable = new (); var view = new View { @@ -22,21 +22,21 @@ public class SetLayoutTests (ITestOutputHelper output) Height = 1, Text = "0123456789" }; - Application.Current.Add (view); + Application.TopRunnable.Add (view); - var rs = Application.Begin (Application.Current); + var rs = Application.Begin (Application.TopRunnable); Application.Driver!.SetScreenSize (80, 25); Assert.Equal (new (0, 0, 80, 25), new Rectangle (0, 0, Application.Screen.Width, Application.Screen.Height)); - Assert.Equal (new (0, 0, Application.Screen.Width, Application.Screen.Height), Application.Current.Frame); - Assert.Equal (new (0, 0, 80, 25), Application.Current.Frame); + Assert.Equal (new (0, 0, Application.Screen.Width, Application.Screen.Height), Application.TopRunnable.Frame); + Assert.Equal (new (0, 0, 80, 25), Application.TopRunnable.Frame); Application.Driver!.SetScreenSize (20, 10); - Assert.Equal (new (0, 0, Application.Screen.Width, Application.Screen.Height), Application.Current.Frame); + Assert.Equal (new (0, 0, Application.Screen.Width, Application.Screen.Height), Application.TopRunnable.Frame); - Assert.Equal (new (0, 0, 20, 10), Application.Current.Frame); + Assert.Equal (new (0, 0, 20, 10), Application.TopRunnable.Frame); Application.End (rs); - Application.Current.Dispose (); + Application.TopRunnable.Dispose (); } } diff --git a/Tests/UnitTests/View/Navigation/CanFocusTests.cs b/Tests/UnitTests/View/Navigation/CanFocusTests.cs index 8a82c605d..09b71ef0d 100644 --- a/Tests/UnitTests/View/Navigation/CanFocusTests.cs +++ b/Tests/UnitTests/View/Navigation/CanFocusTests.cs @@ -89,13 +89,13 @@ public class CanFocusTests public void CanFocus_Set_True_Get_AdvanceFocus_Works () { IApplication app = Application.Create (); - app.Current = new () { App = app }; + app.TopRunnable = new () { App = app }; Label label = new () { Text = "label" }; View view = new () { Text = "view", CanFocus = true }; - app.Current.Add (label, view); + app.TopRunnable.Add (label, view); - app.Current.SetFocus (); + app.TopRunnable.SetFocus (); Assert.Equal (view, app.Navigation!.GetFocused ()); Assert.False (label.CanFocus); Assert.False (label.HasFocus); @@ -125,7 +125,7 @@ public class CanFocusTests Assert.True (label.HasFocus); Assert.False (view.HasFocus); - app.Current.Dispose (); + app.TopRunnable.Dispose (); app.ResetState (); } } diff --git a/Tests/UnitTests/View/Navigation/NavigationTests.cs b/Tests/UnitTests/View/Navigation/NavigationTests.cs index 466d6a1ca..d52d5a0ef 100644 --- a/Tests/UnitTests/View/Navigation/NavigationTests.cs +++ b/Tests/UnitTests/View/Navigation/NavigationTests.cs @@ -27,7 +27,7 @@ public class NavigationTests (ITestOutputHelper output) : TestsAllViews } Toplevel top = new (); - Application.Current = top; + Application.TopRunnable = top; View otherView = new () { @@ -117,7 +117,7 @@ public class NavigationTests (ITestOutputHelper output) : TestsAllViews } Toplevel top = new (); - Application.Current = top; + Application.TopRunnable = top; View otherView = new () { @@ -148,8 +148,8 @@ public class NavigationTests (ITestOutputHelper output) : TestsAllViews // Ensure the view is Visible view.Visible = true; - Application.Current.SetFocus (); - Assert.True (Application.Current!.HasFocus); + Application.TopRunnable.SetFocus (); + Assert.True (Application.TopRunnable!.HasFocus); Assert.True (top.HasFocus); // Start with the focus on our test view @@ -280,7 +280,7 @@ public class NavigationTests (ITestOutputHelper output) : TestsAllViews Toplevel top = new (); - Application.Current = top; + Application.TopRunnable = top; View otherView = new () { diff --git a/Tests/UnitTests/View/TextTests.cs b/Tests/UnitTests/View/TextTests.cs index dba01c151..53d882756 100644 --- a/Tests/UnitTests/View/TextTests.cs +++ b/Tests/UnitTests/View/TextTests.cs @@ -396,7 +396,7 @@ Y Assert.Equal (new (1, 5), view.TextFormatter.ConstrainToSize); Assert.Equal (new () { "Views" }, view.TextFormatter.GetLines ()); Assert.Equal (new (0, 0, 4, 10), win.Frame); - Assert.Equal (new (0, 0, 4, 10), Application.Current.Frame); + Assert.Equal (new (0, 0, 4, 10), Application.TopRunnable.Frame); var expected = @" ┌──┐ diff --git a/Tests/UnitTests/View/ViewCommandTests.cs b/Tests/UnitTests/View/ViewCommandTests.cs index cc48653eb..bb611ac03 100644 --- a/Tests/UnitTests/View/ViewCommandTests.cs +++ b/Tests/UnitTests/View/ViewCommandTests.cs @@ -46,9 +46,9 @@ public class ViewCommandTests w.LayoutSubViews (); - Application.Current = w; + Application.TopRunnable = w; Application.SessionStack.Push (w); - Assert.Same (Application.Current, w); + Assert.Same (Application.TopRunnable, w); // Click button 2 Rectangle btn2Frame = btnB.FrameToScreen (); @@ -121,9 +121,9 @@ public class ViewCommandTests w.Add (btn); - Application.Current = w; + Application.TopRunnable = w; Application.SessionStack.Push (w); - Assert.Same (Application.Current, w); + Assert.Same (Application.TopRunnable, w); w.LayoutSubViews (); diff --git a/Tests/UnitTests/View/Viewport/ViewportSettings.TransparentMouseTests.cs b/Tests/UnitTests/View/Viewport/ViewportSettings.TransparentMouseTests.cs index 2e66c4c9b..94082c3db 100644 --- a/Tests/UnitTests/View/Viewport/ViewportSettings.TransparentMouseTests.cs +++ b/Tests/UnitTests/View/Viewport/ViewportSettings.TransparentMouseTests.cs @@ -23,7 +23,7 @@ public class TransparentMouseTests { Id = "top", }; - Application.Current = top; + Application.TopRunnable = top; var underlying = new MouseTrackingView { Id = "underlying", X = 0, Y = 0, Width = 10, Height = 10 }; var overlay = new MouseTrackingView { Id = "overlay", X = 0, Y = 0, Width = 10, Height = 10, ViewportSettings = ViewportSettingsFlags.TransparentMouse }; @@ -56,7 +56,7 @@ public class TransparentMouseTests { // Arrange var top = new Toplevel (); - Application.Current = top; + Application.TopRunnable = top; var underlying = new MouseTrackingView { X = 0, Y = 0, Width = 10, Height = 10 }; var overlay = new MouseTrackingView { X = 0, Y = 0, Width = 10, Height = 10, ViewportSettings = ViewportSettingsFlags.None }; @@ -90,7 +90,7 @@ public class TransparentMouseTests { // Arrange var top = new Toplevel (); - Application.Current = top; + Application.TopRunnable = top; var underlying = new MouseTrackingView { X = 0, Y = 0, Width = 10, Height = 10, ViewportSettings = ViewportSettingsFlags.TransparentMouse }; var overlay = new MouseTrackingView { X = 0, Y = 0, Width = 10, Height = 10, ViewportSettings = ViewportSettingsFlags.TransparentMouse }; diff --git a/Tests/UnitTests/Views/AppendAutocompleteTests.cs b/Tests/UnitTests/Views/AppendAutocompleteTests.cs index 3fa75b7b8..ceb4f883a 100644 --- a/Tests/UnitTests/Views/AppendAutocompleteTests.cs +++ b/Tests/UnitTests/Views/AppendAutocompleteTests.cs @@ -30,12 +30,12 @@ public class AppendAutocompleteTests (ITestOutputHelper output) Assert.Equal ("f", tf.Text); // Still has focus though - Assert.Same (tf, Application.Current.Focused); + Assert.Same (tf, Application.TopRunnable.Focused); // But can tab away Application.RaiseKeyDownEvent ('\t'); - Assert.NotSame (tf, Application.Current.Focused); - Application.Current.Dispose (); + Assert.NotSame (tf, Application.TopRunnable.Focused); + Application.TopRunnable.Dispose (); } [Fact] @@ -69,7 +69,7 @@ public class AppendAutocompleteTests (ITestOutputHelper output) tf.PositionCursor (); DriverAssert.AssertDriverContentsAre ("fish", output); Assert.Equal ("fi", tf.Text); - Application.Current.Dispose (); + Application.TopRunnable.Dispose (); } [Theory] @@ -107,7 +107,7 @@ public class AppendAutocompleteTests (ITestOutputHelper output) tf.PositionCursor (); DriverAssert.AssertDriverContentsAre ("fish", output); Assert.Equal ("f", tf.Text); - Application.Current.Dispose (); + Application.TopRunnable.Dispose (); } [Fact] @@ -133,7 +133,7 @@ public class AppendAutocompleteTests (ITestOutputHelper output) tf.Draw (); DriverAssert.AssertDriverContentsAre ("f", output); Assert.Equal ("f ", tf.Text); - Application.Current.Dispose (); + Application.TopRunnable.Dispose (); } [Fact] @@ -157,7 +157,7 @@ public class AppendAutocompleteTests (ITestOutputHelper output) tf.Draw (); DriverAssert.AssertDriverContentsAre ("fx", output); Assert.Equal ("fx", tf.Text); - Application.Current.Dispose (); + Application.TopRunnable.Dispose (); } [Fact] @@ -195,7 +195,7 @@ public class AppendAutocompleteTests (ITestOutputHelper output) tf.Draw (); DriverAssert.AssertDriverContentsAre ("my FISH", output); Assert.Equal ("my FISH", tf.Text); - Application.Current.Dispose (); + Application.TopRunnable.Dispose (); } [Fact] @@ -231,12 +231,12 @@ public class AppendAutocompleteTests (ITestOutputHelper output) Assert.Equal ("fish", tf.Text); // Tab should autcomplete but not move focus - Assert.Same (tf, Application.Current.Focused); + Assert.Same (tf, Application.TopRunnable.Focused); // Second tab should move focus (nothing to autocomplete) Application.RaiseKeyDownEvent ('\t'); - Assert.NotSame (tf, Application.Current.Focused); - Application.Current.Dispose (); + Assert.NotSame (tf, Application.TopRunnable.Focused); + Application.TopRunnable.Dispose (); } [Theory] @@ -256,7 +256,7 @@ public class AppendAutocompleteTests (ITestOutputHelper output) tf.PositionCursor (); DriverAssert.AssertDriverContentsAre (expectRender, output); Assert.Equal ("f", tf.Text); - Application.Current.Dispose (); + Application.TopRunnable.Dispose (); } private TextField GetTextFieldsInView () diff --git a/Tests/UnitTests/Views/ButtonTests.cs b/Tests/UnitTests/Views/ButtonTests.cs index 83d8cc032..1f97316d7 100644 --- a/Tests/UnitTests/Views/ButtonTests.cs +++ b/Tests/UnitTests/Views/ButtonTests.cs @@ -209,7 +209,7 @@ public class ButtonTests (ITestOutputHelper output) clicked = false; // Toplevel does not handle Enter, so it should get passed on to button - Assert.False (Application.Current.NewKeyDownEvent (Key.Enter)); + Assert.False (Application.TopRunnable.NewKeyDownEvent (Key.Enter)); Assert.True (clicked); clicked = false; diff --git a/Tests/UnitTests/Views/CheckBoxTests.cs b/Tests/UnitTests/Views/CheckBoxTests.cs index 39fe5db91..0324e0fde 100644 --- a/Tests/UnitTests/Views/CheckBoxTests.cs +++ b/Tests/UnitTests/Views/CheckBoxTests.cs @@ -15,11 +15,11 @@ public class CheckBoxTests (ITestOutputHelper output) [Fact] public void Commands_Select () { - Application.Current = new (); + Application.TopRunnable = new (); View otherView = new () { CanFocus = true }; var ckb = new CheckBox (); - Application.Current.Add (ckb, otherView); - Application.Current.SetFocus (); + Application.TopRunnable.Add (ckb, otherView); + Application.TopRunnable.SetFocus (); Assert.True (ckb.HasFocus); var checkedStateChangingCount = 0; @@ -63,7 +63,7 @@ public class CheckBoxTests (ITestOutputHelper output) Assert.Equal (3, selectCount); Assert.Equal (1, acceptCount); - Application.Current.Dispose (); + Application.TopRunnable.Dispose (); Application.ResetState (); } diff --git a/Tests/UnitTests/Views/ColorPickerTests.cs b/Tests/UnitTests/Views/ColorPickerTests.cs index 8e454a289..7c960a18b 100644 --- a/Tests/UnitTests/Views/ColorPickerTests.cs +++ b/Tests/UnitTests/Views/ColorPickerTests.cs @@ -12,7 +12,7 @@ public class ColorPickerTests var otherView = new View { CanFocus = true }; - Application.Current?.Add (otherView); // thi sets focus to otherView + Application.TopRunnable?.Add (otherView); // thi sets focus to otherView Assert.True (otherView.HasFocus); cp.SetFocus (); @@ -772,11 +772,11 @@ public class ColorPickerTests cp.Style.ShowColorName = showName; cp.ApplyStyleChanges (); - Application.Current = new () { Width = 20, Height = 5 }; - Application.Current.Add (cp); + Application.TopRunnable = new () { Width = 20, Height = 5 }; + Application.TopRunnable.Add (cp); - Application.Current.LayoutSubViews (); - Application.Current.SetFocus (); + Application.TopRunnable.LayoutSubViews (); + Application.TopRunnable.SetFocus (); return cp; } diff --git a/Tests/UnitTests/Views/ComboBoxTests.cs b/Tests/UnitTests/Views/ComboBoxTests.cs index 260251659..43059f823 100644 --- a/Tests/UnitTests/Views/ComboBoxTests.cs +++ b/Tests/UnitTests/Views/ComboBoxTests.cs @@ -1015,7 +1015,7 @@ Three { var cb = new ComboBox (); var top = new Toplevel (); - Application.Current = top; + Application.TopRunnable = top; top.Add (cb); top.FocusDeepest (NavigationDirection.Forward, null); @@ -1054,7 +1054,7 @@ Three Assert.Equal (-1, cb.SelectedItem); Assert.Equal ("", cb.Text); - Application.Current.Dispose (); + Application.TopRunnable.Dispose (); Application.ResetState (true); } } diff --git a/Tests/UnitTests/Views/HexViewTests.cs b/Tests/UnitTests/Views/HexViewTests.cs index 63ea65cea..e2fe7e365 100644 --- a/Tests/UnitTests/Views/HexViewTests.cs +++ b/Tests/UnitTests/Views/HexViewTests.cs @@ -32,9 +32,9 @@ public class HexViewTests { var hv = new HexView (LoadStream (null, out _, true)) { Width = 20, Height = 20 }; - Application.Current = new (); - Application.Current.Add (hv); - Application.Current.SetFocus (); + Application.TopRunnable = new (); + Application.TopRunnable.Add (hv); + Application.TopRunnable.SetFocus (); // Needed because HexView relies on LayoutComplete to calc sizes hv.LayoutSubViews (); @@ -69,14 +69,14 @@ public class HexViewTests Assert.Empty (hv.Edits); Assert.Equal (127, hv.Source.Length); - Application.Current.Dispose (); + Application.TopRunnable.Dispose (); Application.ResetState (true); } [Fact] public void ApplyEdits_With_Argument () { - Application.Current = new (); + Application.TopRunnable = new (); byte [] buffer = Encoding.Default.GetBytes ("Fest"); var original = new MemoryStream (); @@ -87,8 +87,8 @@ public class HexViewTests original.CopyTo (copy); copy.Flush (); var hv = new HexView (copy) { Width = Dim.Fill (), Height = Dim.Fill () }; - Application.Current.Add (hv); - Application.Current.SetFocus (); + Application.TopRunnable.Add (hv); + Application.TopRunnable.SetFocus (); // Needed because HexView relies on LayoutComplete to calc sizes hv.LayoutSubViews (); @@ -119,7 +119,7 @@ public class HexViewTests Assert.Equal ("Zest", Encoding.Default.GetString (readBuffer)); Assert.Equal (Encoding.Default.GetString (buffer), Encoding.Default.GetString (readBuffer)); - Application.Current.Dispose (); + Application.TopRunnable.Dispose (); Application.ResetState (true); } @@ -143,10 +143,10 @@ public class HexViewTests public void Position_Encoding_Default () { var hv = new HexView (LoadStream (null, out _)) { Width = 100, Height = 100 }; - Application.Current = new (); - Application.Current.Add (hv); + Application.TopRunnable = new (); + Application.TopRunnable.Add (hv); - Application.Current.LayoutSubViews (); + Application.TopRunnable.LayoutSubViews (); Assert.Equal (63, hv.Source!.Length); Assert.Equal (20, hv.BytesPerLine); @@ -171,7 +171,7 @@ public class HexViewTests Assert.Equal (new (3, 3), hv.GetPosition (hv.Address)); Assert.Equal (hv.Source!.Length, hv.Address); - Application.Current.Dispose (); + Application.TopRunnable.Dispose (); Application.ResetState (true); } @@ -179,8 +179,8 @@ public class HexViewTests public void Position_Encoding_Unicode () { var hv = new HexView (LoadStream (null, out _, true)) { Width = 100, Height = 100 }; - Application.Current = new (); - Application.Current.Add (hv); + Application.TopRunnable = new (); + Application.TopRunnable.Add (hv); hv.LayoutSubViews (); @@ -206,7 +206,7 @@ public class HexViewTests Assert.Equal (new (6, 6), hv.GetPosition (hv.Address)); Assert.Equal (hv.Source!.Length, hv.Address); - Application.Current.Dispose (); + Application.TopRunnable.Dispose (); Application.ResetState (true); } @@ -258,9 +258,9 @@ public class HexViewTests [Fact] public void KeyBindings_Test_Movement_LeftSide () { - Application.Current = new (); + Application.TopRunnable = new (); var hv = new HexView (LoadStream (null, out _)) { Width = 20, Height = 10 }; - Application.Current.Add (hv); + Application.TopRunnable.Add (hv); hv.LayoutSubViews (); @@ -306,7 +306,7 @@ public class HexViewTests Assert.True (Application.RaiseKeyDownEvent (Key.CursorUp.WithCtrl)); Assert.Equal (0, hv.Address); - Application.Current.Dispose (); + Application.TopRunnable.Dispose (); Application.ResetState (true); } @@ -314,10 +314,10 @@ public class HexViewTests public void PositionChanged_Event () { var hv = new HexView (LoadStream (null, out _)) { Width = 20, Height = 10 }; - Application.Current = new (); - Application.Current.Add (hv); + Application.TopRunnable = new (); + Application.TopRunnable.Add (hv); - Application.Current.LayoutSubViews (); + Application.TopRunnable.LayoutSubViews (); HexViewEventArgs hexViewEventArgs = null!; hv.PositionChanged += (s, e) => hexViewEventArgs = e; @@ -331,7 +331,7 @@ public class HexViewTests Assert.Equal (4, hexViewEventArgs.BytesPerLine); Assert.Equal (new (1, 1), hexViewEventArgs.Position); Assert.Equal (5, hexViewEventArgs.Address); - Application.Current.Dispose (); + Application.TopRunnable.Dispose (); Application.ResetState (true); } @@ -339,32 +339,32 @@ public class HexViewTests public void Source_Sets_Address_To_Zero_If_Greater_Than_Source_Length () { var hv = new HexView (LoadStream (null, out _)) { Width = 10, Height = 5 }; - Application.Current = new (); - Application.Current.Add (hv); + Application.TopRunnable = new (); + Application.TopRunnable.Add (hv); - Application.Current.Layout (); + Application.TopRunnable.Layout (); Assert.True (hv.NewKeyDownEvent (Key.End)); Assert.Equal (MEM_STRING_LENGTH, hv.Address); hv.Source = new MemoryStream (); - Application.Current.Layout (); + Application.TopRunnable.Layout (); Assert.Equal (0, hv.Address); hv.Source = LoadStream (null, out _); hv.Width = Dim.Fill (); hv.Height = Dim.Fill (); - Application.Current.Layout (); + Application.TopRunnable.Layout (); Assert.Equal (0, hv.Address); Assert.True (hv.NewKeyDownEvent (Key.End)); Assert.Equal (MEM_STRING_LENGTH, hv.Address); hv.Source = new MemoryStream (); - Application.Current.Layout (); + Application.TopRunnable.Layout (); Assert.Equal (0, hv.Address); - Application.Current.Dispose (); + Application.TopRunnable.Dispose (); Application.ResetState (true); } diff --git a/Tests/UnitTests/Views/LabelTests.cs b/Tests/UnitTests/Views/LabelTests.cs index bdda95498..56b701668 100644 --- a/Tests/UnitTests/Views/LabelTests.cs +++ b/Tests/UnitTests/Views/LabelTests.cs @@ -1098,7 +1098,7 @@ t Assert.Equal (new (5, 1), label.TextFormatter.ConstrainToSize); Assert.Equal (["Label"], label.TextFormatter.GetLines ()); Assert.Equal (new (0, 0, 10, 4), win.Frame); - Assert.Equal (new (0, 0, 10, 4), Application.Current.Frame); + Assert.Equal (new (0, 0, 10, 4), Application.TopRunnable.Frame); var expected = @" ┌────────┐ @@ -1157,7 +1157,7 @@ t Assert.Equal (new (5, 1), label.TextFormatter.ConstrainToSize); Assert.Equal (["Label"], label.TextFormatter.GetLines ()); Assert.Equal (new (0, 0, 10, 4), win.Frame); - Assert.Equal (new (0, 0, 10, 4), Application.Current.Frame); + Assert.Equal (new (0, 0, 10, 4), Application.TopRunnable.Frame); var expected = @" ┌────────┐ @@ -1230,10 +1230,10 @@ t CanFocus = true }; - Application.Current = new (); - Application.Current.Add (otherView, label, nextView); + Application.TopRunnable = new (); + Application.TopRunnable.Add (otherView, label, nextView); - Application.Current.SetFocus (); + Application.TopRunnable.SetFocus (); Assert.True (otherView.HasFocus); Assert.True (Application.RaiseKeyDownEvent (label.HotKey)); @@ -1241,7 +1241,7 @@ t Assert.False (label.HasFocus); Assert.True (nextView.HasFocus); - Application.Current.Dispose (); + Application.TopRunnable.Dispose (); Application.ResetState (); } @@ -1251,18 +1251,18 @@ t View otherView = new () { X = 0, Y = 0, Width = 1, Height = 1, Id = "otherView", CanFocus = true }; Label label = new () { X = 0, Y = 1, Text = "_label" }; View nextView = new () { X = Pos.Right (label), Y = Pos.Top (label), Width = 1, Height = 1, Id = "nextView", CanFocus = true }; - Application.Current = new (); - Application.Current.Add (otherView, label, nextView); - Application.Current.Layout (); + Application.TopRunnable = new (); + Application.TopRunnable.Add (otherView, label, nextView); + Application.TopRunnable.Layout (); - Application.Current.SetFocus (); + Application.TopRunnable.SetFocus (); // click on label Application.RaiseMouseEvent (new () { ScreenPosition = label.Frame.Location, Flags = MouseFlags.Button1Clicked }); Assert.False (label.HasFocus); Assert.True (nextView.HasFocus); - Application.Current.Dispose (); + Application.TopRunnable.Dispose (); Application.ResetState (); } @@ -1281,8 +1281,8 @@ t CanFocus = true }; - Application.Current = new (); - Application.Current.Add (label, view); + Application.TopRunnable = new (); + Application.TopRunnable.Add (label, view); view.SetFocus (); Assert.True (label.CanFocus); @@ -1295,7 +1295,7 @@ t Assert.True (label.HasFocus); Assert.False (view.HasFocus); - Application.Current.Dispose (); + Application.TopRunnable.Dispose (); Application.ResetState (); } @@ -1320,14 +1320,14 @@ t CanFocus = true }; - Application.Current = new () + Application.TopRunnable = new () { Width = 10, Height = 10 }; - Application.Current.Add (label, otherView); - Application.Current.SetFocus (); - Application.Current.Layout (); + Application.TopRunnable.Add (label, otherView); + Application.TopRunnable.SetFocus (); + Application.TopRunnable.Layout (); Assert.True (label.CanFocus); Assert.True (label.HasFocus); @@ -1347,7 +1347,7 @@ t Assert.False (label.HasFocus); Assert.True (otherView.HasFocus); - Application.Current.Dispose (); + Application.TopRunnable.Dispose (); Application.ResetState (); } diff --git a/Tests/UnitTests/Views/Menuv1/MenuBarv1Tests.cs b/Tests/UnitTests/Views/Menuv1/MenuBarv1Tests.cs index 1241716ca..c51389bbc 100644 --- a/Tests/UnitTests/Views/Menuv1/MenuBarv1Tests.cs +++ b/Tests/UnitTests/Views/Menuv1/MenuBarv1Tests.cs @@ -698,7 +698,7 @@ public class MenuBarv1Tests (ITestOutputHelper output) Dialog.DefaultShadow = ShadowStyle.None; Button.DefaultShadow = ShadowStyle.None; - Assert.Equal (new (0, 0, 40, 15), Application.Current!.GetClip ()!.GetBounds ()); + Assert.Equal (new (0, 0, 40, 15), Application.TopRunnable!.GetClip ()!.GetBounds ()); DriverAssert.AssertDriverContentsWithFrameAre (@"", output); List items = new () @@ -1100,11 +1100,11 @@ wo Assert.False (copyAction); #if SUPPORT_ALT_TO_ACTIVATE_MENU - Assert.False (Application.Current.ProcessKeyDown (new KeyEventArgs (Key.AltMask))); - Assert.False (Application.Current.ProcessKeyDown (new KeyEventArgs (Key.AltMask))); - Assert.True (Application.Current.ProcessKeyUp (new KeyEventArgs (Key.AltMask))); + Assert.False (Application.TopRunnable.ProcessKeyDown (new KeyEventArgs (Key.AltMask))); + Assert.False (Application.TopRunnable.ProcessKeyDown (new KeyEventArgs (Key.AltMask))); + Assert.True (Application.TopRunnable.ProcessKeyUp (new KeyEventArgs (Key.AltMask))); Assert.True (menu.IsMenuOpen); - Application.Current.Draw (); + Application.TopRunnable.Draw (); string expected = @" File Edit @@ -1113,26 +1113,26 @@ wo var pos = DriverAsserts.AssertDriverContentsWithFrameAre (expected, output); Assert.Equal (new (1, 0, 11, 1), pos); - Assert.True (Application.Current.ProcessKeyDown (new KeyEventArgs (Key.N))); + Assert.True (Application.TopRunnable.ProcessKeyDown (new KeyEventArgs (Key.N))); AutoInitShutdownAttribute.RunIteration (); Assert.False (newAction); // not yet, hot keys don't work if the item is not visible - Assert.True (Application.Current.ProcessKeyDown (new KeyEventArgs (Key.F))); + Assert.True (Application.TopRunnable.ProcessKeyDown (new KeyEventArgs (Key.F))); AutoInitShutdownAttribute.RunIteration (); - Assert.True (Application.Current.ProcessKeyDown (new KeyEventArgs (Key.N))); + Assert.True (Application.TopRunnable.ProcessKeyDown (new KeyEventArgs (Key.N))); AutoInitShutdownAttribute.RunIteration (); Assert.True (newAction); - Application.Current.Draw (); + Application.TopRunnable.Draw (); expected = @" File Edit "; - Assert.False (Application.Current.ProcessKeyDown (new KeyEventArgs (Key.AltMask))); - Assert.True (Application.Current.ProcessKeyUp (new KeyEventArgs (Key.AltMask))); - Assert.True (Application.Current.ProcessKeyUp (new KeyEventArgs (Key.AltMask))); + Assert.False (Application.TopRunnable.ProcessKeyDown (new KeyEventArgs (Key.AltMask))); + Assert.True (Application.TopRunnable.ProcessKeyUp (new KeyEventArgs (Key.AltMask))); + Assert.True (Application.TopRunnable.ProcessKeyUp (new KeyEventArgs (Key.AltMask))); Assert.True (menu.IsMenuOpen); - Application.Current.Draw (); + Application.TopRunnable.Draw (); expected = @" File Edit @@ -1141,8 +1141,8 @@ wo pos = DriverAsserts.AssertDriverContentsWithFrameAre (expected, output); Assert.Equal (new (1, 0, 11, 1), pos); - Assert.True (Application.Current.ProcessKeyDown (new KeyEventArgs (Key.CursorRight))); - Assert.True (Application.Current.ProcessKeyDown (new KeyEventArgs (Key.C))); + Assert.True (Application.TopRunnable.ProcessKeyDown (new KeyEventArgs (Key.CursorRight))); + Assert.True (Application.TopRunnable.ProcessKeyDown (new KeyEventArgs (Key.C))); AutoInitShutdownAttribute.RunIteration (); Assert.True (copyAction); #endif @@ -1211,19 +1211,19 @@ wo Assert.True (menu.NewKeyDownEvent (Key.F.WithAlt)); Assert.True (menu.IsMenuOpen); - Application.Current.Draw (); + Application.TopRunnable.Draw (); DriverAssert.AssertDriverContentsAre (expectedMenu.ExpectedSubMenuOpen (0), output); - Assert.True (Application.Current.SubViews.ElementAt (1).NewKeyDownEvent (Key.N)); + Assert.True (Application.TopRunnable.SubViews.ElementAt (1).NewKeyDownEvent (Key.N)); AutoInitShutdownAttribute.RunIteration (); Assert.True (newAction); Assert.True (menu.NewKeyDownEvent (Key.E.WithAlt)); Assert.True (menu.IsMenuOpen); - Application.Current.Draw (); + Application.TopRunnable.Draw (); DriverAssert.AssertDriverContentsAre (expectedMenu.ExpectedSubMenuOpen (1), output); - Assert.True (Application.Current.SubViews.ElementAt (1).NewKeyDownEvent (Key.C)); + Assert.True (Application.TopRunnable.SubViews.ElementAt (1).NewKeyDownEvent (Key.C)); AutoInitShutdownAttribute.RunIteration (); Assert.True (copyAction); top.Dispose (); @@ -1945,7 +1945,7 @@ wo Application.AddTimeout (TimeSpan.Zero, () => { - Toplevel top = Application.Current; + Toplevel top = Application.TopRunnable; AutoInitShutdownAttribute.RunIteration (); @@ -2090,7 +2090,7 @@ wo DriverAssert.AssertDriverContentsAre (expectedMenu.ExpectedSubMenuOpen (0), output); // Open second - Assert.True (Application.Current.SubViews.ElementAt (1).NewKeyDownEvent (Key.CursorRight)); + Assert.True (Application.TopRunnable.SubViews.ElementAt (1).NewKeyDownEvent (Key.CursorRight)); Assert.True (menu.IsMenuOpen); top.SetClipToScreen (); top.Draw (); @@ -2141,7 +2141,7 @@ wo Assert.True (top.SubViews.ElementAt (1).NewKeyDownEvent (Key.CursorRight)); Assert.True (menu.IsMenuOpen); top.SetClipToScreen (); - Application.Current.Draw (); + Application.TopRunnable.Draw (); DriverAssert.AssertDriverContentsAre (expectedMenu.ExpectedSubMenuOpen (1), output); // Close menu @@ -3075,7 +3075,7 @@ Edit pos = DriverAssert.AssertDriverContentsWithFrameAre (expected, output); - Assert.True (Application.Current.SubViews.ElementAt (1).NewKeyDownEvent (Key.CursorDown)); + Assert.True (Application.TopRunnable.SubViews.ElementAt (1).NewKeyDownEvent (Key.CursorDown)); top.Draw (); expected = @" @@ -3090,7 +3090,7 @@ Edit pos = DriverAssert.AssertDriverContentsWithFrameAre (expected, output); - Assert.True (Application.Current.SubViews.ElementAt (2).NewKeyDownEvent (Key.CursorLeft)); + Assert.True (Application.TopRunnable.SubViews.ElementAt (2).NewKeyDownEvent (Key.CursorLeft)); top.Draw (); expected = @" @@ -3104,7 +3104,7 @@ Edit pos = DriverAssert.AssertDriverContentsWithFrameAre (expected, output); - Assert.True (Application.Current.SubViews.ElementAt (1).NewKeyDownEvent (Key.Esc)); + Assert.True (Application.TopRunnable.SubViews.ElementAt (1).NewKeyDownEvent (Key.Esc)); top.Draw (); expected = @" @@ -3186,7 +3186,7 @@ Edit menu.NewMouseEvent ( new () { - Position = new (1, 2), Flags = MouseFlags.ReportMousePosition, View = Application.Current.SubViews.ElementAt (1) + Position = new (1, 2), Flags = MouseFlags.ReportMousePosition, View = Application.TopRunnable.SubViews.ElementAt (1) } ); top.Draw (); @@ -3208,7 +3208,7 @@ Edit menu.NewMouseEvent ( new () { - Position = new (1, 1), Flags = MouseFlags.ReportMousePosition, View = Application.Current.SubViews.ElementAt (1) + Position = new (1, 1), Flags = MouseFlags.ReportMousePosition, View = Application.TopRunnable.SubViews.ElementAt (1) } ) ); @@ -3227,7 +3227,7 @@ Edit Assert.Equal (new (1, 0, 10, 6), pos); menu.NewMouseEvent ( - new () { Position = new (70, 2), Flags = MouseFlags.Button1Clicked, View = Application.Current } + new () { Position = new (70, 2), Flags = MouseFlags.Button1Clicked, View = Application.TopRunnable } ); top.Draw (); diff --git a/Tests/UnitTests/Views/ShortcutTests.cs b/Tests/UnitTests/Views/ShortcutTests.cs index 79da2dbc6..df5dac215 100644 --- a/Tests/UnitTests/Views/ShortcutTests.cs +++ b/Tests/UnitTests/Views/ShortcutTests.cs @@ -23,7 +23,7 @@ public class ShortcutTests [InlineData (9, 0)] public void MouseClick_Raises_Accepted (int x, int expectedAccepted) { - Application.Current = new (); + Application.TopRunnable = new (); var shortcut = new Shortcut { @@ -31,8 +31,8 @@ public class ShortcutTests Text = "0", Title = "C" }; - Application.Current.Add (shortcut); - Application.Current.Layout (); + Application.TopRunnable.Add (shortcut); + Application.TopRunnable.Layout (); var accepted = 0; shortcut.Accepting += (s, e) => accepted++; @@ -46,7 +46,7 @@ public class ShortcutTests Assert.Equal (expectedAccepted, accepted); - Application.Current.Dispose (); + Application.TopRunnable.Dispose (); Application.ResetState (true); } @@ -74,7 +74,7 @@ public class ShortcutTests int expectedShortcutSelected ) { - Application.Current = new (); + Application.TopRunnable = new (); var shortcut = new Shortcut { @@ -93,9 +93,9 @@ public class ShortcutTests var shortcutSelectCount = 0; shortcut.Selecting += (s, e) => { shortcutSelectCount++; }; - Application.Current.Add (shortcut); - Application.Current.SetRelativeLayout (new (100, 100)); - Application.Current.LayoutSubViews (); + Application.TopRunnable.Add (shortcut); + Application.TopRunnable.SetRelativeLayout (new (100, 100)); + Application.TopRunnable.LayoutSubViews (); Application.RaiseMouseEvent ( new () @@ -109,7 +109,7 @@ public class ShortcutTests Assert.Equal (expectedCommandViewAccepted, commandViewAcceptCount); Assert.Equal (expectedCommandViewSelected, commandViewSelectCount); - Application.Current.Dispose (); + Application.TopRunnable.Dispose (); Application.ResetState (true); } @@ -130,7 +130,7 @@ public class ShortcutTests [InlineData (9, 0, 0)] public void MouseClick_Button_CommandView_Raises_Shortcut_Accepted (int mouseX, int expectedAccept, int expectedButtonAccept) { - Application.Current = new (); + Application.TopRunnable = new (); var shortcut = new Shortcut { @@ -147,9 +147,9 @@ public class ShortcutTests }; var buttonAccepted = 0; shortcut.CommandView.Accepting += (s, e) => { buttonAccepted++; }; - Application.Current.Add (shortcut); - Application.Current.SetRelativeLayout (new (100, 100)); - Application.Current.LayoutSubViews (); + Application.TopRunnable.Add (shortcut); + Application.TopRunnable.SetRelativeLayout (new (100, 100)); + Application.TopRunnable.LayoutSubViews (); var accepted = 0; shortcut.Accepting += (s, e) => { accepted++; }; @@ -164,7 +164,7 @@ public class ShortcutTests Assert.Equal (expectedAccept, accepted); Assert.Equal (expectedButtonAccept, buttonAccepted); - Application.Current.Dispose (); + Application.TopRunnable.Dispose (); Application.ResetState (true); } @@ -186,7 +186,7 @@ public class ShortcutTests [InlineData (10, 1, 0)] public void MouseClick_CheckBox_CommandView_Raises_Shortcut_Accepted_Selected_Correctly (int mouseX, int expectedAccepted, int expectedCheckboxAccepted) { - Application.Current = new (); + Application.TopRunnable = new (); var shortcut = new Shortcut { @@ -212,9 +212,9 @@ public class ShortcutTests checkboxSelected++; }; - Application.Current.Add (shortcut); - Application.Current.SetRelativeLayout (new (100, 100)); - Application.Current.LayoutSubViews (); + Application.TopRunnable.Add (shortcut); + Application.TopRunnable.SetRelativeLayout (new (100, 100)); + Application.TopRunnable.LayoutSubViews (); var selected = 0; shortcut.Selecting += (s, e) => @@ -241,7 +241,7 @@ public class ShortcutTests Assert.Equal (expectedCheckboxAccepted, checkboxAccepted); Assert.Equal (expectedCheckboxAccepted, checkboxSelected); - Application.Current.Dispose (); + Application.TopRunnable.Dispose (); Application.ResetState (true); } @@ -260,7 +260,7 @@ public class ShortcutTests [InlineData (false, KeyCode.F1, 0, 0)] public void KeyDown_Raises_Accepted_Selected (bool canFocus, KeyCode key, int expectedAccept, int expectedSelect) { - Application.Current = new (); + Application.TopRunnable = new (); var shortcut = new Shortcut { @@ -269,7 +269,7 @@ public class ShortcutTests Title = "_C", CanFocus = canFocus }; - Application.Current.Add (shortcut); + Application.TopRunnable.Add (shortcut); shortcut.SetFocus (); Assert.Equal (canFocus, shortcut.HasFocus); @@ -285,7 +285,7 @@ public class ShortcutTests Assert.Equal (expectedAccept, accepted); Assert.Equal (expectedSelect, selected); - Application.Current.Dispose (); + Application.TopRunnable.Dispose (); Application.ResetState (true); } @@ -305,7 +305,7 @@ public class ShortcutTests [InlineData (false, KeyCode.F1, 0, 0)] public void KeyDown_CheckBox_Raises_Accepted_Selected (bool canFocus, KeyCode key, int expectedAccept, int expectedSelect) { - Application.Current = new (); + Application.TopRunnable = new (); var shortcut = new Shortcut { @@ -317,7 +317,7 @@ public class ShortcutTests }, CanFocus = canFocus }; - Application.Current.Add (shortcut); + Application.TopRunnable.Add (shortcut); shortcut.SetFocus (); Assert.Equal (canFocus, shortcut.HasFocus); @@ -337,7 +337,7 @@ public class ShortcutTests Assert.Equal (expectedAccept, accepted); Assert.Equal (expectedSelect, selected); - Application.Current.Dispose (); + Application.TopRunnable.Dispose (); Application.ResetState (true); } [Theory] @@ -349,7 +349,7 @@ public class ShortcutTests [InlineData (KeyCode.F1, 0)] public void KeyDown_App_Scope_Invokes_Accept (KeyCode key, int expectedAccept) { - Application.Current = new () { App = Application.Create () }; + Application.TopRunnable = new () { App = Application.Create () }; var shortcut = new Shortcut { @@ -357,9 +357,9 @@ public class ShortcutTests Text = "0", Title = "_C" }; - Application.Current.Add (shortcut); + Application.TopRunnable.Add (shortcut); shortcut.BindKeyToApplication = true; - Application.Current.SetFocus (); + Application.TopRunnable.SetFocus (); var accepted = 0; shortcut.Accepting += (s, e) => accepted++; @@ -368,7 +368,7 @@ public class ShortcutTests Assert.Equal (expectedAccept, accepted); - Application.Current.Dispose (); + Application.TopRunnable.Dispose (); Application.ResetState (true); } @@ -427,7 +427,7 @@ public class ShortcutTests [InlineData (false, KeyCode.F1, 0)] public void KeyDown_App_Scope_Invokes_Action (bool canFocus, KeyCode key, int expectedAction) { - Application.Current = new (); + Application.TopRunnable = new (); var shortcut = new Shortcut { @@ -438,13 +438,13 @@ public class ShortcutTests CanFocus = canFocus }; - Application.Current.Add (shortcut); + Application.TopRunnable.Add (shortcut); // Shortcut requires Init for App scoped hotkeys to work - Application.Current.BeginInit (); - Application.Current.EndInit (); + Application.TopRunnable.BeginInit (); + Application.TopRunnable.EndInit (); - Application.Current.SetFocus (); + Application.TopRunnable.SetFocus (); var action = 0; shortcut.Action += () => action++; @@ -453,7 +453,7 @@ public class ShortcutTests Assert.Equal (expectedAction, action); - Application.Current.Dispose (); + Application.TopRunnable.Dispose (); Application.ResetState (true); } @@ -461,11 +461,11 @@ public class ShortcutTests [Fact] public void Scheme_SetScheme_Does_Not_Fault_3664 () { - Application.Current = new (); + Application.TopRunnable = new (); var shortcut = new Shortcut (); - Application.Current.SetScheme (null); + Application.TopRunnable.SetScheme (null); Assert.False (shortcut.HasScheme); Assert.NotNull (shortcut.GetScheme ()); @@ -475,7 +475,7 @@ public class ShortcutTests Assert.False (shortcut.HasScheme); Assert.NotNull (shortcut.GetScheme ()); - Application.Current.Dispose (); + Application.TopRunnable.Dispose (); Application.ResetState (); } } diff --git a/Tests/UnitTests/Views/SpinnerViewTests.cs b/Tests/UnitTests/Views/SpinnerViewTests.cs index 35b25e039..1a74d5514 100644 --- a/Tests/UnitTests/Views/SpinnerViewTests.cs +++ b/Tests/UnitTests/Views/SpinnerViewTests.cs @@ -40,7 +40,7 @@ public class SpinnerViewTests (ITestOutputHelper output) // Dispose clears timeout view.Dispose (); Assert.Empty (Application.TimedEvents.Timeouts); - Application.Current.Dispose (); + Application.TopRunnable.Dispose (); } [Fact] @@ -62,7 +62,7 @@ public class SpinnerViewTests (ITestOutputHelper output) expected = "/"; DriverAssert.AssertDriverContentsWithFrameAre (expected, output); - Application.Current.Dispose (); + Application.TopRunnable.Dispose (); } [Fact] @@ -95,7 +95,7 @@ public class SpinnerViewTests (ITestOutputHelper output) //expected = "|"; //DriverAsserts.AssertDriverContentsWithFrameAre (expected, output); - Application.Current.Dispose (); + Application.TopRunnable.Dispose (); } private SpinnerView GetSpinnerView () diff --git a/Tests/UnitTests/Views/TableViewTests.cs b/Tests/UnitTests/Views/TableViewTests.cs index 4c162a037..7e103b591 100644 --- a/Tests/UnitTests/Views/TableViewTests.cs +++ b/Tests/UnitTests/Views/TableViewTests.cs @@ -3257,19 +3257,19 @@ A B C // Pressing left should move us to the first column without changing focus Application.RaiseKeyDownEvent (Key.CursorLeft); - Assert.Same (tableView, Application.Current!.MostFocused); + Assert.Same (tableView, Application.TopRunnable!.MostFocused); Assert.True (tableView.HasFocus); // Because we are now on the leftmost cell a further left press should move focus Application.RaiseKeyDownEvent (Key.CursorLeft); - Assert.NotSame (tableView, Application.Current.MostFocused); + Assert.NotSame (tableView, Application.TopRunnable.MostFocused); Assert.False (tableView.HasFocus); - Assert.Same (tf1, Application.Current.MostFocused); + Assert.Same (tf1, Application.TopRunnable.MostFocused); Assert.True (tf1.HasFocus); - Application.Current.Dispose (); + Application.TopRunnable.Dispose (); } [Fact] @@ -3282,19 +3282,19 @@ A B C // First press should move us up Application.RaiseKeyDownEvent (Key.CursorUp); - Assert.Same (tableView, Application.Current!.MostFocused); + Assert.Same (tableView, Application.TopRunnable!.MostFocused); Assert.True (tableView.HasFocus); // Because we are now on the top row a further press should move focus Application.RaiseKeyDownEvent (Key.CursorUp); - Assert.NotSame (tableView, Application.Current.MostFocused); + Assert.NotSame (tableView, Application.TopRunnable.MostFocused); Assert.False (tableView.HasFocus); - Assert.Same (tf1, Application.Current.MostFocused); + Assert.Same (tf1, Application.TopRunnable.MostFocused); Assert.True (tf1.HasFocus); - Application.Current.Dispose (); + Application.TopRunnable.Dispose (); } [Fact] @@ -3307,19 +3307,19 @@ A B C // First press should move us to the rightmost column without changing focus Application.RaiseKeyDownEvent (Key.CursorRight); - Assert.Same (tableView, Application.Current!.MostFocused); + Assert.Same (tableView, Application.TopRunnable!.MostFocused); Assert.True (tableView.HasFocus); // Because we are now on the rightmost cell, a further right press should move focus Application.RaiseKeyDownEvent (Key.CursorRight); - Assert.NotSame (tableView, Application.Current.MostFocused); + Assert.NotSame (tableView, Application.TopRunnable.MostFocused); Assert.False (tableView.HasFocus); - Assert.Same (tf2, Application.Current.MostFocused); + Assert.Same (tf2, Application.TopRunnable.MostFocused); Assert.True (tf2.HasFocus); - Application.Current.Dispose (); + Application.TopRunnable.Dispose (); } [Fact] @@ -3332,19 +3332,19 @@ A B C // First press should move us to the bottommost row without changing focus Application.RaiseKeyDownEvent (Key.CursorDown); - Assert.Same (tableView, Application.Current!.MostFocused); + Assert.Same (tableView, Application.TopRunnable!.MostFocused); Assert.True (tableView.HasFocus); // Because we are now on the bottommost cell, a further down press should move focus Application.RaiseKeyDownEvent (Key.CursorDown); - Assert.NotSame (tableView, Application.Current.MostFocused); + Assert.NotSame (tableView, Application.TopRunnable.MostFocused); Assert.False (tableView.HasFocus); - Assert.Same (tf2, Application.Current.MostFocused); + Assert.Same (tf2, Application.TopRunnable.MostFocused); Assert.True (tf2.HasFocus); - Application.Current.Dispose (); + Application.TopRunnable.Dispose (); } [Fact] @@ -3357,7 +3357,7 @@ A B C // Pressing shift-left should give us a multi selection Application.RaiseKeyDownEvent (Key.CursorLeft.WithShift); - Assert.Same (tableView, Application.Current!.MostFocused); + Assert.Same (tableView, Application.TopRunnable!.MostFocused); Assert.True (tableView.HasFocus); Assert.Equal (2, tableView.GetAllSelectedCells ().Count ()); @@ -3368,19 +3368,19 @@ A B C // Selection 'clears' just to the single cell and we remain focused Assert.Single (tableView.GetAllSelectedCells ()); - Assert.Same (tableView, Application.Current.MostFocused); + Assert.Same (tableView, Application.TopRunnable.MostFocused); Assert.True (tableView.HasFocus); // A further left will switch focus Application.RaiseKeyDownEvent (Key.CursorLeft); - Assert.NotSame (tableView, Application.Current.MostFocused); + Assert.NotSame (tableView, Application.TopRunnable.MostFocused); Assert.False (tableView.HasFocus); - Assert.Same (tf1, Application.Current.MostFocused); + Assert.Same (tf1, Application.TopRunnable.MostFocused); Assert.True (tf1.HasFocus); - Application.Current.Dispose (); + Application.TopRunnable.Dispose (); } [Theory] @@ -3407,7 +3407,7 @@ A B C } /// - /// Creates 3 views on with the focus in the + /// Creates 3 views on with the focus in the /// . This is a helper method to setup tests that want to /// explore moving input focus out of a tableview. /// @@ -3421,16 +3421,16 @@ A B C tableView.EndInit (); - Application.Current = new (); + Application.TopRunnable = new (); tf1 = new (); tf2 = new (); - Application.Current.Add (tf1); - Application.Current.Add (tableView); - Application.Current.Add (tf2); + Application.TopRunnable.Add (tf1); + Application.TopRunnable.Add (tableView); + Application.TopRunnable.Add (tf2); tableView.SetFocus (); - Assert.Same (tableView, Application.Current.MostFocused); + Assert.Same (tableView, Application.TopRunnable.MostFocused); Assert.True (tableView.HasFocus); // Set big table diff --git a/Tests/UnitTests/Views/TextFieldTests.cs b/Tests/UnitTests/Views/TextFieldTests.cs index d41de3152..66ad798bd 100644 --- a/Tests/UnitTests/Views/TextFieldTests.cs +++ b/Tests/UnitTests/Views/TextFieldTests.cs @@ -84,7 +84,7 @@ public class TextFieldTests (ITestOutputHelper output) tf.Draw (); DriverAssert.AssertDriverContentsAre (expectedRender, output); - Application.Current.Dispose (); + Application.TopRunnable.Dispose (); } [Fact] @@ -105,7 +105,7 @@ public class TextFieldTests (ITestOutputHelper output) tf.Draw (); DriverAssert.AssertDriverContentsAre ("Misérables", output); - Application.Current.Dispose (); + Application.TopRunnable.Dispose (); } [Theory (Skip = "Broke with ContextMenuv2")] @@ -133,7 +133,7 @@ public class TextFieldTests (ITestOutputHelper output) tf.SetClipToScreen (); tf.Draw (); DriverAssert.AssertDriverContentsAre (content, output); - Application.Current.Dispose (); + Application.TopRunnable.Dispose (); } [Fact] @@ -158,7 +158,7 @@ public class TextFieldTests (ITestOutputHelper output) tf.SetClipToScreen (); tf.Draw (); DriverAssert.AssertDriverContentsAre ("Enter txt", output); - Application.Current.Dispose (); + Application.TopRunnable.Dispose (); } [Fact] @@ -188,7 +188,7 @@ public class TextFieldTests (ITestOutputHelper output) // All characters in "Enter text" should have the caption attribute DriverAssert.AssertDriverAttributesAre ("0000000000", output, Application.Driver, captionAttr); - Application.Current.Dispose (); + Application.TopRunnable.Dispose (); } [Fact] @@ -222,7 +222,7 @@ public class TextFieldTests (ITestOutputHelper output) // F is underlined (index 1), remaining characters use normal caption attribute (index 0) DriverAssert.AssertDriverAttributesAre ("1000", output, Application.Driver, captionAttr, hotkeyAttr); - Application.Current.Dispose (); + Application.TopRunnable.Dispose (); } [Fact] @@ -256,7 +256,7 @@ public class TextFieldTests (ITestOutputHelper output) // "Enter " (6 chars) + "T" (underlined) + "ext" (3 chars) DriverAssert.AssertDriverAttributesAre ("0000001000", output, Application.Driver, captionAttr, hotkeyAttr); - Application.Current.Dispose (); + Application.TopRunnable.Dispose (); } [Fact] @@ -1691,7 +1691,7 @@ Les Miśerables", { base.Before (methodUnderTest); - //Application.Current.Scheme = Colors.Schemes ["Base"]; + //Application.TopRunnable.Scheme = Colors.Schemes ["Base"]; _textField = new () { // 1 2 3 diff --git a/Tests/UnitTests/Views/TextViewTests.cs b/Tests/UnitTests/Views/TextViewTests.cs index 80f185fb4..10764cf4c 100644 --- a/Tests/UnitTests/Views/TextViewTests.cs +++ b/Tests/UnitTests/Views/TextViewTests.cs @@ -109,7 +109,7 @@ public class TextViewTests Assert.Equal (leftCol, _textView.LeftColumn); } - Application.Current.Remove (_textView); + Application.TopRunnable.Remove (_textView); Application.RequestStop (); } } diff --git a/Tests/UnitTests/Views/ToplevelTests.cs b/Tests/UnitTests/Views/ToplevelTests.cs index 365ebd8bf..f01ad988e 100644 --- a/Tests/UnitTests/Views/ToplevelTests.cs +++ b/Tests/UnitTests/Views/ToplevelTests.cs @@ -69,11 +69,11 @@ public class ToplevelTests #endif Application.Begin (top); - Assert.Equal (top, Application.Current); + Assert.Equal (top, Application.TopRunnable); - // Application.Current without menu and status bar. + // Application.TopRunnable without menu and status bar. View supView = View.GetLocationEnsuringFullVisibility (top, 2, 2, out int nx, out int ny /*, out StatusBar sb*/); - Assert.Equal (Application.Current, supView); + Assert.Equal (Application.TopRunnable, supView); Assert.Equal (0, nx); Assert.Equal (0, ny); @@ -82,7 +82,7 @@ public class ToplevelTests top.Add (new MenuBar ()); Assert.NotNull (top.MenuBar); - // Application.Current with a menu and without status bar. + // Application.TopRunnable with a menu and without status bar. View.GetLocationEnsuringFullVisibility (top, 2, 2, out nx, out ny /*, out sb*/); Assert.Equal (0, nx); Assert.Equal (1, ny); @@ -92,11 +92,11 @@ public class ToplevelTests //top.Add (new StatusBar ()); //Assert.NotNull (top.StatusBar); - // Application.Current with a menu and status bar. + // Application.TopRunnable with a menu and status bar. View.GetLocationEnsuringFullVisibility (top, 2, 2, out nx, out ny /*, out sb*/); Assert.Equal (0, nx); - // The available height is lower than the Application.Current height minus + // The available height is lower than the Application.TopRunnable height minus // the menu bar and status bar, then the top can go beyond the bottom // Assert.Equal (2, ny); //Assert.NotNull (sb); @@ -106,11 +106,11 @@ public class ToplevelTests Assert.Null (top.MenuBar); Assert.NotNull (menuBar); - // Application.Current without a menu and with a status bar. + // Application.TopRunnable without a menu and with a status bar. View.GetLocationEnsuringFullVisibility (top, 2, 2, out nx, out ny /*, out sb*/); Assert.Equal (0, nx); - // The available height is lower than the Application.Current height minus + // The available height is lower than the Application.TopRunnable height minus // the status bar, then the top can go beyond the bottom // Assert.Equal (2, ny); //Assert.NotNull (sb); @@ -127,11 +127,11 @@ public class ToplevelTests // The SuperView is always the same regardless of the caller. supView = View.GetLocationEnsuringFullVisibility (win, 0, 0, out nx, out ny /*, out sb*/); - Assert.Equal (Application.Current, supView); + Assert.Equal (Application.TopRunnable, supView); supView = View.GetLocationEnsuringFullVisibility (win, 0, 0, out nx, out ny /*, out sb*/); - Assert.Equal (Application.Current, supView); + Assert.Equal (Application.TopRunnable, supView); - // Application.Current without menu and status bar. + // Application.TopRunnable without menu and status bar. View.GetLocationEnsuringFullVisibility (win, 0, 0, out nx, out ny /*, out sb*/); Assert.Equal (0, nx); Assert.Equal (0, ny); @@ -141,7 +141,7 @@ public class ToplevelTests top.Add (new MenuBar ()); Assert.NotNull (top.MenuBar); - // Application.Current with a menu and without status bar. + // Application.TopRunnable with a menu and without status bar. View.GetLocationEnsuringFullVisibility (win, 2, 2, out nx, out ny /*, out sb*/); Assert.Equal (0, nx); Assert.Equal (1, ny); @@ -152,11 +152,11 @@ public class ToplevelTests //Assert.NotNull (top.StatusBar); - // Application.Current with a menu and status bar. + // Application.TopRunnable with a menu and status bar. View.GetLocationEnsuringFullVisibility (win, 30, 20, out nx, out ny /*, out sb*/); Assert.Equal (0, nx); - // The available height is lower than the Application.Current height minus + // The available height is lower than the Application.TopRunnable height minus // the menu bar and status bar, then the top can go beyond the bottom //Assert.Equal (20, ny); //Assert.NotNull (sb); @@ -177,7 +177,7 @@ public class ToplevelTests win = new () { Width = 60, Height = 15 }; top.Add (win); - // Application.Current without menu and status bar. + // Application.TopRunnable without menu and status bar. View.GetLocationEnsuringFullVisibility (win, 0, 0, out nx, out ny /*, out sb*/); Assert.Equal (0, nx); Assert.Equal (0, ny); @@ -187,7 +187,7 @@ public class ToplevelTests top.Add (new MenuBar ()); Assert.NotNull (top.MenuBar); - // Application.Current with a menu and without status bar. + // Application.TopRunnable with a menu and without status bar. View.GetLocationEnsuringFullVisibility (win, 2, 2, out nx, out ny /*, out sb*/); Assert.Equal (2, nx); Assert.Equal (2, ny); @@ -198,7 +198,7 @@ public class ToplevelTests //Assert.NotNull (top.StatusBar); - // Application.Current with a menu and status bar. + // Application.TopRunnable with a menu and status bar. View.GetLocationEnsuringFullVisibility (win, 30, 20, out nx, out ny /*, out sb*/); Assert.Equal (20, nx); // 20+60=80 @@ -307,7 +307,7 @@ public class ToplevelTests } else if (iterations == 1) { - Assert.Equal (new (2, 2), Application.Current!.Frame.Location); + Assert.Equal (new (2, 2), Application.TopRunnable!.Frame.Location); } else if (iterations == 2) { @@ -316,12 +316,12 @@ public class ToplevelTests // Grab the mouse Application.RaiseMouseEvent (new () { ScreenPosition = new (3, 2), Flags = MouseFlags.Button1Pressed }); - Assert.Equal (Application.Current!.Border, Application.Mouse.MouseGrabView); - Assert.Equal (new (2, 2, 10, 3), Application.Current.Frame); + Assert.Equal (Application.TopRunnable!.Border, Application.Mouse.MouseGrabView); + Assert.Equal (new (2, 2, 10, 3), Application.TopRunnable.Frame); } else if (iterations == 3) { - Assert.Equal (Application.Current!.Border, Application.Mouse.MouseGrabView); + Assert.Equal (Application.TopRunnable!.Border, Application.Mouse.MouseGrabView); // Drag to left Application.RaiseMouseEvent ( @@ -333,38 +333,38 @@ public class ToplevelTests }); AutoInitShutdownAttribute.RunIteration (); - Assert.Equal (Application.Current.Border, Application.Mouse.MouseGrabView); - Assert.Equal (new (1, 2, 10, 3), Application.Current.Frame); + Assert.Equal (Application.TopRunnable.Border, Application.Mouse.MouseGrabView); + Assert.Equal (new (1, 2, 10, 3), Application.TopRunnable.Frame); } else if (iterations == 4) { - Assert.Equal (Application.Current!.Border, Application.Mouse.MouseGrabView); - Assert.Equal (new (1, 2), Application.Current.Frame.Location); + Assert.Equal (Application.TopRunnable!.Border, Application.Mouse.MouseGrabView); + Assert.Equal (new (1, 2), Application.TopRunnable.Frame.Location); - Assert.Equal (Application.Current.Border, Application.Mouse.MouseGrabView); + Assert.Equal (Application.TopRunnable.Border, Application.Mouse.MouseGrabView); } else if (iterations == 5) { - Assert.Equal (Application.Current!.Border, Application.Mouse.MouseGrabView); + Assert.Equal (Application.TopRunnable!.Border, Application.Mouse.MouseGrabView); // Drag up Application.RaiseMouseEvent (new () { ScreenPosition = new (2, 1), Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition }); AutoInitShutdownAttribute.RunIteration (); - Assert.Equal (Application.Current!.Border, Application.Mouse.MouseGrabView); - Assert.Equal (new (1, 1, 10, 3), Application.Current.Frame); + Assert.Equal (Application.TopRunnable!.Border, Application.Mouse.MouseGrabView); + Assert.Equal (new (1, 1, 10, 3), Application.TopRunnable.Frame); } else if (iterations == 6) { - Assert.Equal (Application.Current!.Border, Application.Mouse.MouseGrabView); - Assert.Equal (new (1, 1), Application.Current.Frame.Location); + Assert.Equal (Application.TopRunnable!.Border, Application.Mouse.MouseGrabView); + Assert.Equal (new (1, 1), Application.TopRunnable.Frame.Location); - Assert.Equal (Application.Current.Border, Application.Mouse.MouseGrabView); - Assert.Equal (new (1, 1, 10, 3), Application.Current.Frame); + Assert.Equal (Application.TopRunnable.Border, Application.Mouse.MouseGrabView); + Assert.Equal (new (1, 1, 10, 3), Application.TopRunnable.Frame); } else if (iterations == 7) { - Assert.Equal (Application.Current!.Border, Application.Mouse.MouseGrabView); + Assert.Equal (Application.TopRunnable!.Border, Application.Mouse.MouseGrabView); // Ungrab the mouse Application.RaiseMouseEvent (new () { ScreenPosition = new (2, 1), Flags = MouseFlags.Button1Released }); diff --git a/Tests/UnitTestsParallelizable/TestSetup.cs b/Tests/UnitTestsParallelizable/TestSetup.cs index 178a0d4de..47fdeeb25 100644 --- a/Tests/UnitTestsParallelizable/TestSetup.cs +++ b/Tests/UnitTestsParallelizable/TestSetup.cs @@ -39,7 +39,7 @@ public class GlobalTestSetup : IDisposable // Check that all Application fields and properties are set to their default values // Public Properties - Assert.Null (Application.Current); + Assert.Null (Application.TopRunnable); Assert.Null (Application.Mouse.MouseGrabView); // Don't check Application.ForceDriver diff --git a/docfx/docs/application.md b/docfx/docs/application.md index 298cf6ff5..530f53dc5 100644 --- a/docfx/docs/application.md +++ b/docfx/docs/application.md @@ -192,22 +192,22 @@ public interface IApplication Terminal.Gui v2 modernized its terminology for clarity: -### Application.Current (formerly "Top") +### Application.TopRunnable (formerly "Current", and before that "Top") -The `Current` property represents the currently running Toplevel (the active session): +The `TopRunnable` property represents the Toplevel on the top of the session stack (the active runnable session): ```csharp -// Access the current session -Toplevel? current = app.Current; +// Access the top runnable session +Toplevel? topRunnable = app.TopRunnable; // From within a view -Toplevel? current = App?.Current; +Toplevel? topRunnable = App?.TopRunnable; ``` -**Why "Current" instead of "Top"?** -- Follows .NET patterns (`Thread.CurrentThread`, `HttpContext.Current`) -- Self-documenting: immediately clear it's the "current" active view -- Less confusing than "Top" which could mean "topmost in Z-order" +**Why "TopRunnable"?** +- Clearly indicates it's the top of the runnable session stack +- Aligns with the IRunnable architecture proposal +- Distinguishes from other concepts like "Current" which could be ambiguous ### Application.SessionStack (formerly "TopLevels") @@ -256,7 +256,7 @@ public static partial class Application // OLD: void MyMethod() { - Application.Current?.SetNeedsDraw(); + Application.TopRunnable?.SetNeedsDraw(); } // NEW: @@ -467,7 +467,7 @@ public void Refresh() ❌ AVOID: public void Refresh() { - Application.Current?.SetNeedsDraw(); // Obsolete! + Application.TopRunnable?.SetNeedsDraw(); // Obsolete! } ``` @@ -487,7 +487,7 @@ public class Service ❌ AVOID (obsolete pattern): public void Refresh() { - Application.Current?.SetNeedsDraw(); // Obsolete static access + Application.TopRunnable?.SetNeedsDraw(); // Obsolete static access } ✅ PREFERRED: diff --git a/docfx/docs/migratingfromv1.md b/docfx/docs/migratingfromv1.md index d7fd2c0b0..527301a73 100644 --- a/docfx/docs/migratingfromv1.md +++ b/docfx/docs/migratingfromv1.md @@ -85,12 +85,12 @@ When measuring the screen space taken up by a `string` you can use the extension In v1, @Terminal.Gui.View was derived from `Responder` which supported `IDisposable`. In v2, `Responder` has been removed and @Terminal.Gui.View is the base-class supporting `IDisposable`. -In v1, @Terminal.Gui./Terminal.Gui.Application.Init) automatically created a toplevel view and set [Application.Current](~/api/Terminal.Gui.Application.Current. In v2, @Terminal.Gui.App.Application.Init no longer automatically creates a toplevel or sets @Terminal.Gui.App.Application.Current; app developers must explicitly create the toplevel view and pass it to @Terminal.Gui.App.Application.Run (or use `Application.Run`). Developers are responsible for calling `Dispose` on any toplevel they create before exiting. +In v1, @Terminal.Gui./Terminal.Gui.Application.Init) automatically created a toplevel view and set [Application.TopRunnable](~/api/Terminal.Gui.Application.TopRunnable. In v2, @Terminal.Gui.App.Application.Init no longer automatically creates a toplevel or sets @Terminal.Gui.App.Application.TopRunnable; app developers must explicitly create the toplevel view and pass it to @Terminal.Gui.App.Application.Run (or use `Application.Run`). Developers are responsible for calling `Dispose` on any toplevel they create before exiting. ### How to Fix * Replace `Responder` with @Terminal.Gui.View -* Update any code that assumes `Application.Init` automatically created a toplevel view and set `Application.Current`. +* Update any code that assumes `Application.Init` automatically created a toplevel view and set `Application.TopRunnable`. * Update any code that assumes `Application.Init` automatically disposed of the toplevel view when the application exited. ## Instance-Based Application Architecture @@ -144,7 +144,7 @@ When accessing application services from within views, use the `App` property in // OLD (v1 / obsolete static): public void Refresh() { - Application.Current?.SetNeedsDraw(); + Application.TopRunnable?.SetNeedsDraw(); } // NEW (v2 - use View.App): @@ -591,6 +591,6 @@ new ( * To simplify programming, any `View` added as a SubView another `View` will have it's lifecycle owned by the Superview; when a `View` is disposed, it will call `Dispose` on all the items in the `SubViews` property. Note this behavior is the same as it was in v1, just clarified. -* In v1, `Application.End` called `Dispose ()` on @Terminal.Gui.App.Application.Current (via `Runstate.Toplevel`). This was incorrect as it meant that after `Application.Run` returned, `Application.Current` had been disposed, and any code that wanted to interrogate the results of `Run` by accessing `Application.Current` only worked by accident. This is because GC had not actually happened; if it had the application would have crashed. In v2 `Application.End` does NOT call `Dispose`, and it is the caller to `Application.Run` who is responsible for disposing the `Toplevel` that was either passed to `Application.Run (View)` or created by `Application.Run ()`. +* In v1, `Application.End` called `Dispose ()` on @Terminal.Gui.App.Application.TopRunnable (via `Runstate.Toplevel`). This was incorrect as it meant that after `Application.Run` returned, `Application.TopRunnable` had been disposed, and any code that wanted to interrogate the results of `Run` by accessing `Application.TopRunnable` only worked by accident. This is because GC had not actually happened; if it had the application would have crashed. In v2 `Application.End` does NOT call `Dispose`, and it is the caller to `Application.Run` who is responsible for disposing the `Toplevel` that was either passed to `Application.Run (View)` or created by `Application.Run ()`. * Any code that creates a `Toplevel`, either by using `top = new()` or by calling either `top = Application.Run ()` or `top = ApplicationRun()` must call `top.Dispose` when complete. The exception to this is if `top` is passed to `myView.Add(top)` making it a subview of `myView`. This is because the semantics of `Add` are that the `myView` takes over responsibility for the subviews lifetimes. Of course, if someone calls `myView.Remove(top)` to remove said subview, they then re-take responsbility for `top`'s lifetime and they must call `top.Dispose`. diff --git a/docfx/docs/navigation.md b/docfx/docs/navigation.md index 2c5c2391a..f217ace2c 100644 --- a/docfx/docs/navigation.md +++ b/docfx/docs/navigation.md @@ -181,7 +181,7 @@ return app.Current?.AdvanceFocus (direction, behavior); This method is called from the `Command` handlers bound to the application-scoped keybindings created during `app.Init()`. It is `public` as a convenience. -**Note:** When accessing from within a View, use `App?.Current` instead of `Application.Current` (which is obsolete). +**Note:** When accessing from within a View, use `App?.Current` instead of `Application.TopRunnable` (which is obsolete). This method replaces about a dozen functions in v1 (scattered across `Application` and `Toplevel`). @@ -379,7 +379,7 @@ In v1 `View` had `MostFocused` property that traversed up the view-hierarchy ret var focused = Application.Navigation.GetFocused(); // This replaces the v1 pattern: -// var focused = Application.Current.MostFocused; +// var focused = Application.TopRunnable.MostFocused; ``` ## How Does `View.Add/Remove` Work? diff --git a/docfx/docs/runnable-architecture-proposal.md b/docfx/docs/runnable-architecture-proposal.md new file mode 100644 index 000000000..e9ee14663 --- /dev/null +++ b/docfx/docs/runnable-architecture-proposal.md @@ -0,0 +1,95 @@ +# IRunnable Architecture Proposal + +**Status**: Proposal + +**Version**: 1.6 (Property-Based Architecture) + +**Date**: 2025-01-20 + +## Summary + +This proposal recommends decoupling Terminal.Gui's "Runnable" concept from `Toplevel` and `ViewArrangement.Overlapped`, elevating it to a first-class interface-based abstraction. + +**Key Insight**: Analysis of the codebase reveals that **all runnable sessions are effectively modal** - they block in `Application.Run()` until stopped and capture input. The distinction between "modal" and "non-modal" in the current design is artificial: + +- The `Modal` property only affects input propagation and Z-order, not the fundamental run loop behavior +- All `Toplevel`s block in `Run()` - there's no "background" runnable concept +- Non-modal `Toplevel`s (like `WizardAsView`) are just embedded views with `Modal = false`, not true sessions +- Overlapped windows are managed by `ViewArrangement.Overlapped`, not runnability + +By introducing `IRunnable`, we create a clean separation where: + +- **Runnable** = Can be run as a **UI**-blocking session with `Application.Run()` and returns a result +- **Overlapped** = `ViewArrangement.Overlapped` for window management (orthogonal to runnability) +- **Embedded** = Just views, not runnable at all + +## Terminology + +This proposal introduces new terminology to clarify the architecture: + +| Term | Definition | +|------|------------| +| **`IRunnable`** | Base interface for Views capable of running as an independent session with `Application.Run()` without returning a result. Replaces `Toplevel` as the contract for runnable views. When an `IRunnable` is passed to `IApplication.Run`, `Run` blocks until the `IRunnable` `Stops`. | +| **`IRunnable`** | Generic interface derived from `IRunnable` that can return a typed result. | +| **`Runnable`** | Optional base class that implements `IRunnable` and derives from `View`, providing default lifecycle behavior. Views can derive from this or implement `IRunnable` directly. | +| **`TResult`** | Type parameter specifying the type of result data returned when the runnable completes (e.g., `int` for button index, `string` for file path, enum, or other complex type). `Result` is `null` if the runnable stopped without the user explicitly accepting it (ESC pressed, window closed, etc.). | +| **`Result`** | Property on `IRunnable` that holds the typed result data. Should be set in `IsRunningChanging` handler (when `newValue = false`) **before** the runnable is popped from `RunnableSessionStack`. This allows subscribers to inspect results and optionally cancel the stop. Available after `IApplication.Run` returns. `null` indicates cancellation/non-acceptance. | +| **RunnableSession** | A running instance of an `IRunnable`. Managed by `IApplication` via `Begin()`, `Run()`, `RequestStop()`, and `End()` methods. Represented by a `RunnableSessionToken` on the `RunnableSessionStack`. | +| **`RunnableSessionToken`** | Object returned by `Begin()` that represents a running session. Wraps an `IRunnable` instance (via a `Runnable` property) and is stored in `RunnableSessionStack`. Disposed when session ends. | +| **`RunnableSessionStack`** | A stack of `RunnableSessionToken` instances, each wrapping an `IRunnable`. Tracks all running runnables in the application. Literally a `ConcurrentStack`. Replaces `SessionStack` (formerly `Toplevels`). | +| **`IsRunning`** | Boolean property on `IRunnable` indicating whether the runnable is currently on the `RunnableSessionStack` (i.e., `RunnableSessionStack.Any(token => token.Runnable == this)`). Read-only, derived from stack state. Runnables are added during `IApplication.Begin` and removed in `IApplication.End`. Replaces `Toplevel.Running`. | +| **`IsRunningChanging`** | Cancellable event raised **before** an `IRunnable` is added to or removed from `RunnableSessionStack`. When transitioning to `IsRunning = true`, can be canceled to prevent starting. When transitioning to `IsRunning = false`, allows code to prevent closure (e.g., prompt to save changes) AND is the ideal place to extract `Result` before the runnable is removed from the stack. Event args (`CancelEventArgs`) provide the new state in `NewValue`. Replaces `Toplevel.Closing` and partially `Toplevel.Activate`. | +| **`IsRunningChanged`** | Non-cancellable event raised **after** a runnable has been added to or removed from `RunnableSessionStack`. Fired after `IsRunning` has changed to the new value (true = started, false = stopped). For post-state-change logic (e.g., setting focus after start, cleanup after stop). Replaces `Toplevel.Activated` and `Toplevel.Closed`. | +| **`IsInitialized`** (`View` property) | Boolean property (on `View`) indicating whether a view has completed two-phase initialization (`View.BeginInit/View.EndInit`). From .NET's `ISupportInitialize` pattern. If the `IRunnable.IsInitialized == false`, `BeginInit` is called from `IApplication.Begin` after `IsRunning` has changed to `true`. `EndInit` is called immediately after `BeginInit`. | +| **`Initialized`** (`View` event) | Non-cancellable event raised as `View.EndInit()` completes. | +| **`TopRunnable`** (`IApplication` property) | The `IRunnable` that is on the top of the `RunnableSessionStack` stack. By definition and per-implementation, this `IRunnable` is capturing all mouse and keyboard input and is thus "Modal". Note: any other `IRunnable` instances on `RunnableSessionStack` continue to be laid out, drawn, and receive iteration events; they just don't get any user input. **Renamed from `Current`** to better reflect its purpose as the top runnable in the stack. Synonymous with the runnable having `IsModal = true`. | +| **`IsModal`** | Boolean property on `IRunnable` indicating whether the `IRunnable` is at the top of the `RunnableSessionStack` (i.e., `this == app.TopRunnable` or `app.RunnableSessionStack.Peek().Runnable == this`). The `IRunnable` at the top of the stack gets all mouse/keyboard input and thus is running "modally". Read-only, derived from stack state. `IsModal` represents the concept from the end-user's perspective. | +| **`IsModalChanging`** | Cancellable event raised **before** an `IRunnable` transitions to/from the top of the `RunnableSessionStack`. When becoming modal (`newValue = true`), can be canceled to prevent activation. Event args (`CancelEventArgs`) provide the new state. Replaces `Toplevel.Activate` and `Toplevel.Deactivate`. | +| **`IsModalChanged`** | Non-cancellable event raised **after** an `IRunnable` has transitioned to/from the top of the `RunnableSessionStack`. Fired after `IsModal` has changed to the new value (true = became modal, false = no longer modal). For post-activation logic (e.g., setting focus, updating UI state). Replaces `Toplevel.Activated` and `Toplevel.Deactivated`. | +| **`End`** (`IApplication` method) | Ends a running `IRunnable` instance by removing its `RunnableSessionToken` from the `RunnableSessionStack`. `IsRunningChanging` with `newValue = false` is raised **before** the token is popped from the stack (allowing result extraction and cancellation). `IsRunningChanged` is raised **after** the `Pop` operation. Then, `RunnableSessionStack.Peek()` is called to see if another `IRunnable` instance can transition to `IApplication.TopRunnable`/`IRunnable.IsModal = true`. | +| **`ViewArrangement.Overlapped`** | Layout mode for windows that can overlap with Z-order management. Orthogonal to runnability - overlapped windows can be embedded views (not runnable) or runnable sessions. | + +**Key Architectural Changes:** +- **Simplified**: One interface `IRunnable` replaces both `Toplevel` and the artificial `Modal` property distinction +- **All sessions block**: No concept of "non-modal runnable" - if it's runnable, `Run()` blocks until `RequestStop()` +- **Type-safe results**: Generic `TResult` parameter provides compile-time type safety +- **Decoupled from layout**: Being runnable is independent of `ViewArrangement.Overlapped` +- **Consistent patterns**: All lifecycle events follow Terminal.Gui's Cancellable Work Pattern +- **Result extraction in `Stopping`**: `OnStopping()` is the correct place to extract `Result` before disposal + +## Implementation Status + +### Completed Work + +- [x] **2025-11-20**: Renamed `IApplication.Current` to `IApplication.TopRunnable` to better reflect its role as the top runnable in the session stack + - Updated interface definition in `IApplication.cs` + - Updated implementation in `ApplicationImpl.cs` + - Updated static property in `Application.Current.cs` + - Updated all references in library code (28 occurrences) + - Updated all references in examples (50+ occurrences) + - Updated all references in tests (607 occurrences) + - Updated `View.IsCurrentTop` to use the renamed property + - Updated API documentation comments + - All tests pass + - No new warnings introduced + +### Remaining Work + +The following items from the original proposal are still pending: + +- [ ] Implement `IRunnable` non-generic base interface +- [ ] Implement `IRunnable` generic interface +- [ ] Create optional `Runnable` base class +- [ ] Replace `SessionToken` with `RunnableSessionToken` +- [ ] Replace `SessionStack` (ConcurrentStack) with `RunnableSessionStack` (ConcurrentStack) +- [ ] Add lifecycle events: `IsRunningChanging`, `IsRunningChanged`, `IsModalChanging`, `IsModalChanged` +- [ ] Migrate `Toplevel` to implement `IRunnable` +- [ ] Update all view classes to use new pattern +- [ ] Add comprehensive tests for new architecture +- [ ] Update all documentation + +## See Also + +- [Original Issue #4148](https://github.com/gui-cs/Terminal.Gui/issues/4148) +- [Application Lifecycle Documentation](application.md) +- [View Documentation](View.md)