merge fix

This commit is contained in:
Charlie Kindel
2022-06-17 10:22:10 -07:00
committed by Tig Kindel
parent 59577feecf
commit 8e70756cd8
2 changed files with 32 additions and 20 deletions

View File

@@ -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;
/// <summary>
/// An <see cref="EventArgs"/> which allows passing a cancelable new <see cref="Title"/> value event.
@@ -56,47 +57,58 @@ namespace Terminal.Gui {
public ustring NewTitle { get; set; }
/// <summary>
/// Flag which allows cancelling changing to the new TItle value.
/// The old Window Title.
/// </summary>
public ustring OldTitle { get; set; }
/// <summary>
/// Flag which allows cancelling the Title change.
/// </summary>
public bool Cancel { get; set; }
/// <summary>
/// Initializes a new instance of <see cref="TitleEventArgs"/>
/// </summary>
/// <param name="newTitle">The new <see cref="Window.Title"/> to be replaced.</param>
public TitleEventArgs (ustring newTitle)
/// <param name="oldTitle">The <see cref="Title"/> that is/has been replaced.</param>
/// <param name="newTitle">The new <see cref="Title"/> to be replaced.</param>
public TitleEventArgs (ustring oldTitle, ustring newTitle)
{
OldTitle = oldTitle;
NewTitle = newTitle;
}
}
/// <summary>
/// Called before the <see cref="Window.Title"/> changes. Invokes the <see cref="TitleChanging"/> event, which can be cancelled.
/// Called before the <see cref="Title"/> changes. Invokes the <see cref="TitleChanging"/> event, which can be cancelled.
/// </summary>
/// <param name="oldTitle">The <see cref="Title"/> that is/has been replaced.</param>
/// <param name="newTitle">The new <see cref="Title"/> to be replaced.</param>
/// <returns>`true` if an event handler cancelled the Title change.</returns>
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;
}
/// <summary>
/// Event fired when the <see cref="Window.Title"/> is changing. Set <see cref="TitleEventArgs.Cancel"/> to
/// Event fired when the <see cref="Title"/> is changing. Set <see cref="TitleEventArgs.Cancel"/> to
/// `true` to cancel the Title change.
/// </summary>
public event Action<TitleEventArgs> TitleChanging;
/// <summary>
/// Called when the <see cref="Window.Title"/> has been changed. Invokes the <see cref="TitleChanged"/> event.
/// Called when the <see cref="Title"/> has been changed. Invokes the <see cref="TitleChanged"/> event.
/// </summary>
public virtual void OnTitleChanged (ustring newTitle)
/// <param name="oldTitle">The <see cref="Title"/> that is/has been replaced.</param>
/// <param name="newTitle">The new <see cref="Title"/> to be replaced.</param>
public virtual void OnTitleChanged (ustring oldTitle, ustring newTitle)
{
var args = new TitleEventArgs (title);
var args = new TitleEventArgs (oldTitle, newTitle);
TitleChanged?.Invoke (args);
}
/// <summary>
/// Event fired after the <see cref="Window.Title"/> has been changed.
/// Event fired after the <see cref="Title"/> has been changed.
/// </summary>
public event Action<TitleEventArgs> 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 ();
}

View File

@@ -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);
};