From 561d671746add2c920d0ff28e16f3a837e0f48a2 Mon Sep 17 00:00:00 2001 From: Tig Date: Mon, 25 Mar 2024 14:18:43 -0600 Subject: [PATCH] Removed un-needed and un-used RequestStop override from Scenario --- Example/Example.cs | 6 ++++-- Terminal.Gui/Application.cs | 4 ++-- UICatalog/Scenario.cs | 7 ++----- UICatalog/Scenarios/BackgroundWorkerCollection.cs | 3 ++- UICatalog/Scenarios/ChineseUI.cs | 2 +- UICatalog/UICatalog.cs | 4 ---- 6 files changed, 11 insertions(+), 15 deletions(-) diff --git a/Example/Example.cs b/Example/Example.cs index 406675ad4..630e6560f 100644 --- a/Example/Example.cs +++ b/Example/Example.cs @@ -6,9 +6,11 @@ using System; using Terminal.Gui; -Application.Run (); +var app = Application.Run (); -Console.WriteLine ($"Username: {((ExampleWindow)Application.Top).UserNameText.Text}"); +Console.WriteLine ($"Username: {app.UserNameText.Text}"); + +app.Dispose (); // Before the application exits, reset Terminal.Gui for clean shutdown Application.Shutdown (); diff --git a/Terminal.Gui/Application.cs b/Terminal.Gui/Application.cs index cce9ffcc5..1afbfb5b5 100644 --- a/Terminal.Gui/Application.cs +++ b/Terminal.Gui/Application.cs @@ -587,10 +587,10 @@ public static partial class Application /// if has already been called. /// /// The created T object. The caller is responsible for disposing this object. - public static Toplevel Run (Func errorHandler = null, ConsoleDriver driver = null) + public static T Run (Func errorHandler = null, ConsoleDriver driver = null) where T : Toplevel, new() { - var top = new T () as Toplevel; + var top = new T (); EnsureValidInitialization (top, driver); diff --git a/UICatalog/Scenario.cs b/UICatalog/Scenario.cs index e0bebed68..ab6a7c333 100644 --- a/UICatalog/Scenario.cs +++ b/UICatalog/Scenario.cs @@ -45,7 +45,7 @@ namespace UICatalog; /// /// /// The UI Catalog program uses reflection to find all scenarios and adds them to the ListViews. Press ENTER to -/// run the selected scenario. Press the default quit key to quit. / +/// run the selected scenario. Press the default quit key to quit. /// /// /// @@ -141,7 +141,7 @@ public class Scenario : IDisposable } /// - /// Helper that provides the default implementation with a frame and label + /// Helper that calls and creates the default implementation with a frame and label /// showing the name of the and logic to exit back to the Scenario picker UI. Override /// to provide any behavior needed. /// @@ -176,9 +176,6 @@ public class Scenario : IDisposable Top.Add (Win); } - /// Stops the scenario. Override to change shutdown behavior for the . - public virtual void RequestStop () { Application.RequestStop (); } - /// /// Runs the . Override to start the using a /// different than `Top`. diff --git a/UICatalog/Scenarios/BackgroundWorkerCollection.cs b/UICatalog/Scenarios/BackgroundWorkerCollection.cs index 4f30630fd..ea51bece2 100644 --- a/UICatalog/Scenarios/BackgroundWorkerCollection.cs +++ b/UICatalog/Scenarios/BackgroundWorkerCollection.cs @@ -15,8 +15,9 @@ public class BackgroundWorkerCollection : Scenario { public override void Init () { - Application.Run (); + var main = Application.Run (); + //main.Dispose (); Application.Top.Dispose (); } diff --git a/UICatalog/Scenarios/ChineseUI.cs b/UICatalog/Scenarios/ChineseUI.cs index dbe819dbb..05183e1c7 100644 --- a/UICatalog/Scenarios/ChineseUI.cs +++ b/UICatalog/Scenarios/ChineseUI.cs @@ -46,7 +46,7 @@ public class ChineseUI : Scenario if (result == 0) { - RequestStop (); + Application.RequestStop (); } }; diff --git a/UICatalog/UICatalog.cs b/UICatalog/UICatalog.cs index 028b2fbae..92079c39a 100644 --- a/UICatalog/UICatalog.cs +++ b/UICatalog/UICatalog.cs @@ -464,10 +464,6 @@ internal class UICatalogApp _selectedScenario = null; RequestStop (); } - else - { - _selectedScenario.RequestStop (); - } } ), new (