From 47a2020bf434c8ddff09e3ea00a164156b9119a6 Mon Sep 17 00:00:00 2001 From: Artyom Date: Wed, 23 Sep 2020 01:19:31 +0300 Subject: [PATCH] Convert TopLevel.Ready into event --- Terminal.Gui/Core/Toplevel.cs | 2 +- UICatalog/UICatalog.cs | 10 +++++++--- UnitTests/ViewTests.cs | 11 +++-------- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/Terminal.Gui/Core/Toplevel.cs b/Terminal.Gui/Core/Toplevel.cs index 5d8914374..9741f5d8a 100644 --- a/Terminal.Gui/Core/Toplevel.cs +++ b/Terminal.Gui/Core/Toplevel.cs @@ -53,7 +53,7 @@ namespace Terminal.Gui { /// Subscribe to this event to perform tasks when the has been laid out and focus has been set. /// changes. A Ready event handler is a good place to finalize initialization after calling `(topLevel)`. /// - public Action Ready; + public event Action Ready; /// /// Called from after the has entered it's first iteration of the loop. diff --git a/UICatalog/UICatalog.cs b/UICatalog/UICatalog.cs index 144b2bb56..95f9b711b 100644 --- a/UICatalog/UICatalog.cs +++ b/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 diff --git a/UnitTests/ViewTests.cs b/UnitTests/ViewTests.cs index 66a20fb01..581cdc267 100644 --- a/UnitTests/ViewTests.cs +++ b/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++;