From 8e70756cd857f5f273d9471e35a98caae83769ae Mon Sep 17 00:00:00 2001 From: Charlie Kindel Date: Fri, 17 Jun 2022 10:22:10 -0700 Subject: [PATCH] merge fix --- Terminal.Gui/Windows/Wizard.cs | 42 ++++++++++++++++++++++------------ UnitTests/WizardTests.cs | 10 ++++---- 2 files changed, 32 insertions(+), 20 deletions(-) diff --git a/Terminal.Gui/Windows/Wizard.cs b/Terminal.Gui/Windows/Wizard.cs index 4777fcd81..31bddc899 100644 --- a/Terminal.Gui/Windows/Wizard.cs +++ b/Terminal.Gui/Windows/Wizard.cs @@ -36,15 +36,16 @@ namespace Terminal.Gui { public ustring Title { get => title; set { - if (!OnTitleChanging (value)) { + if (!OnTitleChanging (title, value)) { + var old = title; title = value; - OnTitleChanged (title); + OnTitleChanged (old, title); } SetNeedsDisplay (); } } - private ustring title; + private ustring title = ustring.Empty; /// /// An which allows passing a cancelable new value event. @@ -56,47 +57,58 @@ namespace Terminal.Gui { public ustring NewTitle { get; set; } /// - /// Flag which allows cancelling changing to the new TItle value. + /// The old Window Title. + /// + public ustring OldTitle { get; set; } + + /// + /// Flag which allows cancelling the Title change. /// public bool Cancel { get; set; } /// /// Initializes a new instance of /// - /// The new to be replaced. - public TitleEventArgs (ustring newTitle) + /// The that is/has been replaced. + /// The new to be replaced. + public TitleEventArgs (ustring oldTitle, ustring newTitle) { + OldTitle = oldTitle; NewTitle = newTitle; } } /// - /// Called before the changes. Invokes the event, which can be cancelled. + /// Called before the changes. Invokes the event, which can be cancelled. /// + /// The that is/has been replaced. + /// The new to be replaced. /// `true` if an event handler cancelled the Title change. - public virtual bool OnTitleChanging (ustring newTitle) + public virtual bool OnTitleChanging (ustring oldTitle, ustring newTitle) { - var args = new TitleEventArgs (newTitle); + var args = new TitleEventArgs (oldTitle, newTitle); TitleChanging?.Invoke (args); return args.Cancel; } /// - /// Event fired when the is changing. Set to + /// Event fired when the is changing. Set to /// `true` to cancel the Title change. /// public event Action TitleChanging; /// - /// Called when the has been changed. Invokes the event. + /// Called when the has been changed. Invokes the event. /// - public virtual void OnTitleChanged (ustring newTitle) + /// The that is/has been replaced. + /// The new to be replaced. + public virtual void OnTitleChanged (ustring oldTitle, ustring newTitle) { - var args = new TitleEventArgs (title); + var args = new TitleEventArgs (oldTitle, newTitle); TitleChanged?.Invoke (args); } /// - /// Event fired after the has been changed. + /// Event fired after the has been changed. /// public event Action TitleChanged; @@ -509,7 +521,7 @@ namespace Terminal.Gui { steps.AddLast (newStep); this.Add (newStep); newStep.EnabledChanged += UpdateButtonsAndTitle; - newStep.TitleChanged += (args) => UpdateButtonsAndTitle(); + newStep.TitleChanged += (args) => UpdateButtonsAndTitle (); UpdateButtonsAndTitle (); } diff --git a/UnitTests/WizardTests.cs b/UnitTests/WizardTests.cs index a4ebc6855..db246dc4b 100644 --- a/UnitTests/WizardTests.cs +++ b/UnitTests/WizardTests.cs @@ -42,10 +42,10 @@ namespace Terminal.Gui.Views { public void WizardStep_Set_Title_Fires_TitleChanging () { var r = new Window (); - Assert.Null (r.Title); + Assert.Equal (ustring.Empty, r.Title); - string expectedAfter = null; - string expectedDuring = null; + string expectedAfter = string.Empty; + string expectedDuring = string.Empty; bool cancel = false; r.TitleChanging += (args) => { Assert.Equal (expectedDuring, args.NewTitle); @@ -70,9 +70,9 @@ namespace Terminal.Gui.Views { public void WizardStep_Set_Title_Fires_TitleChanged () { var r = new Window (); - Assert.Null (r.Title); + Assert.Equal (ustring.Empty, r.Title); - string expected = null; + string expected = string.Empty; r.TitleChanged += (args) => { Assert.Equal (r.Title, args.NewTitle); };