瀏覽代碼

Convert TopLevel.Ready into event

Artyom 4 年之前
父節點
當前提交
7da46a8f69
共有 3 個文件被更改,包括 11 次插入12 次删除
  1. 1 1
      Terminal.Gui/Core/Toplevel.cs
  2. 7 3
      UICatalog/UICatalog.cs
  3. 3 8
      UnitTests/ViewTests.cs

+ 1 - 1
Terminal.Gui/Core/Toplevel.cs

@@ -53,7 +53,7 @@ namespace Terminal.Gui {
 		/// Subscribe to this event to perform tasks when the <see cref="Toplevel"/> has been laid out and focus has been set.
 		/// changes. A Ready event handler is a good place to finalize initialization after calling `<see cref="Application.Run()"/>(topLevel)`. 
 		/// </summary>
-		public Action Ready;
+		public event Action Ready;
 
 		/// <summary>
 		/// Called from <see cref="Application.RunLoop"/> after the <see cref="Toplevel"/> has entered it's first iteration of the loop. 

+ 7 - 3
UICatalog/UICatalog.cs

@@ -96,10 +96,14 @@ namespace UICatalog {
 				scenario.Init (Application.Top, _baseColorScheme);
 				scenario.Setup ();
 				scenario.Run ();
-				_top.Ready += () => {
+
+				static void ReadyHandler ()
+				{
 					_rightPane.SetFocus ();
-					_top.Ready = null;
-				};
+					_top.Ready -= ReadyHandler;
+				}
+				
+				_top.Ready += ReadyHandler;
 
 #if DEBUG_IDISPOSABLE
 				// After the scenario runs, validate all Responder-based instances

+ 3 - 8
UnitTests/ViewTests.cs

@@ -966,17 +966,12 @@ namespace Terminal.Gui {
 				return true;
 			});
 
-			t.Ready = () => {
-				FirstDialogToplevel ();
-			};
+			t.Ready += FirstDialogToplevel;
 
 			void FirstDialogToplevel ()
 			{
-				var od = new OpenDialog {
-					Ready = () => {
-						SecoundDialogToplevel ();
-					}
-				};
+				var od = new OpenDialog();
+				od.Ready += SecoundDialogToplevel;
 
 				Application.MainLoop.AddTimeout (TimeSpan.FromMilliseconds (100), (_) => {
 					count1++;