Browse Source

Removed un-needed and un-used RequestStop override from Scenario

Tig 1 year ago
parent
commit
561d671746

+ 4 - 2
Example/Example.cs

@@ -6,9 +6,11 @@
 using System;
 using Terminal.Gui;
 
-Application.Run<ExampleWindow> ();
+var app = Application.Run<ExampleWindow> ();
 
-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 ();

+ 2 - 2
Terminal.Gui/Application.cs

@@ -587,10 +587,10 @@ public static partial class Application
     ///     <see langword="null"/> if <see cref="Init"/> has already been called.
     /// </param>
     /// <returns>The created T object. The caller is responsible for disposing this object.</returns>
-    public static Toplevel Run<T> (Func<Exception, bool> errorHandler = null, ConsoleDriver driver = null)
+    public static T Run<T> (Func<Exception, bool> errorHandler = null, ConsoleDriver driver = null)
         where T : Toplevel, new()
     {
-        var top = new T () as Toplevel;
+        var top = new T ();
 
         EnsureValidInitialization (top, driver);
 

+ 2 - 5
UICatalog/Scenario.cs

@@ -45,7 +45,7 @@ namespace UICatalog;
 ///     </para>
 ///     <para>
 ///         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.
 ///     </para>
 /// </summary>
 /// <example>
@@ -141,7 +141,7 @@ public class Scenario : IDisposable
     }
 
     /// <summary>
-    ///     Helper that provides the default <see cref="Terminal.Gui.Window"/> implementation with a frame and label
+    ///     Helper that calls <see cref="Application.Init"/> and creates the default <see cref="Terminal.Gui.Window"/> implementation with a frame and label
     ///     showing the name of the <see cref="Scenario"/> and logic to exit back to the Scenario picker UI. Override
     ///     <see cref="Init"/> to provide any <see cref="Terminal.Gui.Toplevel"/> behavior needed.
     /// </summary>
@@ -176,9 +176,6 @@ public class Scenario : IDisposable
         Top.Add (Win);
     }
 
-    /// <summary>Stops the scenario. Override to change shutdown behavior for the <see cref="Scenario"/>.</summary>
-    public virtual void RequestStop () { Application.RequestStop (); }
-
     /// <summary>
     ///     Runs the <see cref="Scenario"/>. Override to start the <see cref="Scenario"/> using a <see cref="Toplevel"/>
     ///     different than `Top`.

+ 2 - 1
UICatalog/Scenarios/BackgroundWorkerCollection.cs

@@ -15,8 +15,9 @@ public class BackgroundWorkerCollection : Scenario
 {
     public override void Init ()
     {
-        Application.Run<OverlappedMain> ();
+        var main = Application.Run<OverlappedMain> ();
 
+        //main.Dispose ();
         Application.Top.Dispose ();
     }
 

+ 1 - 1
UICatalog/Scenarios/ChineseUI.cs

@@ -46,7 +46,7 @@ public class ChineseUI : Scenario
 
                            if (result == 0)
                            {
-                               RequestStop ();
+                               Application.RequestStop ();
                            }
                        };
 

+ 0 - 4
UICatalog/UICatalog.cs

@@ -464,10 +464,6 @@ internal class UICatalogApp
                              _selectedScenario = null;
                              RequestStop ();
                          }
-                         else
-                         {
-                             _selectedScenario.RequestStop ();
-                         }
                      }
                     ),
                 new (