Rename TryClose to RequestClose, and put in IRequestClose

This commit is contained in:
Antony Male 2015-01-14 20:25:01 +00:00
parent be88aed936
commit b4b24441aa
6 changed files with 37 additions and 11 deletions

View File

@ -105,10 +105,22 @@ namespace Stylet
Task<bool> CanCloseAsync();
}
/// <summary>
/// Get the object to request that its parent close it
/// </summary>
public interface IRequestClose
{
/// <summary>
/// Request that the conductor responsible for this screen close it
/// </summary>
/// <param name="dialogResult">DialogResult to return, if this is a dialog</param>
void RequestClose(bool? dialogResult = null);
}
/// <summary>
/// Generalised 'screen' composing all the behaviours expected of a screen
/// </summary>
public interface IScreen : IViewAware, IHaveDisplayName, IActivate, IDeactivate, IChild, IClose, IGuardClose
public interface IScreen : IViewAware, IHaveDisplayName, IActivate, IDeactivate, IChild, IClose, IGuardClose, IRequestClose
{
}

View File

@ -229,7 +229,7 @@ namespace Stylet
public void ButtonClicked(MessageBoxResult button)
{
this.ClickedButton = button;
this.TryClose(true);
this.RequestClose(true);
}
}
}

View File

@ -208,7 +208,7 @@ namespace Stylet
private object _parent;
/// <summary>
/// Gets or sets the parent conductor of this screen. Used to TryClose to request a closure
/// Gets or sets the parent conductor of this screen. Used to RequestClose to request a closure
/// </summary>
public object Parent
{
@ -241,16 +241,18 @@ namespace Stylet
#endregion
#region IRequestClose
/// <summary>
/// Request that the conductor responsible for this screen close it
/// </summary>
/// <param name="dialogResult">DialogResult to return, if this is a dialog</param>
public virtual void TryClose(bool? dialogResult = null)
public virtual void RequestClose(bool? dialogResult = null)
{
var conductor = this.Parent as IChildDelegate;
if (conductor != null)
{
this.logger.Info("TryClose called. Conductor: {0}; DialogResult: {1}", conductor, dialogResult);
this.logger.Info("RequstClose called. Conductor: {0}; DialogResult: {1}", conductor, dialogResult);
conductor.CloseItem(this, dialogResult);
}
else
@ -260,5 +262,17 @@ namespace Stylet
throw e;
}
}
#endregion
/// <summary>
/// Obselete - use RequestClose
/// </summary>
/// <param name="dialogResult">DialogResult to return, if this is a dialog</param>
[Obsolete("Obseleted by RequestClose", true)]
public virtual void TryClose(bool? dialogResult = null)
{
this.RequestClose(dialogResult);
}
}
}

View File

@ -285,7 +285,7 @@ namespace Stylet
return;
}
logger.Info("ViewModel {0} close requested with DialogResult {1} because it called TryClose", this.viewModel, dialogResult);
logger.Info("ViewModel {0} close requested with DialogResult {1} because it called RequestClose", this.viewModel, dialogResult);
this.window.StateChanged -= this.WindowStateChanged;
this.window.Closed -= this.WindowClosed;

View File

@ -26,7 +26,7 @@ namespace StyletIntegrationTests.ShowDialogAndDialogResult
public void Close()
{
this.TryClose(this.SelectedDesiredResult.Value);
this.RequestClose(this.SelectedDesiredResult.Value);
}
}
}

View File

@ -264,18 +264,18 @@ namespace StyletUnitTests
}
[Test]
public void TryCloseThrowsIfParentIsNotIChildDelegate()
public void RequestCloseThrowsIfParentIsNotIChildDelegate()
{
this.screen.Parent = new object();
Assert.Throws<InvalidOperationException>(() => this.screen.TryClose());
Assert.Throws<InvalidOperationException>(() => this.screen.RequestClose());
}
[Test]
public void TryCloseCallsParentCloseItemPassingDialogResult()
public void RequestCloseCallsParentCloseItemPassingDialogResult()
{
var parent = new Mock<IChildDelegate>();
screen.Parent = parent.Object;
this.screen.TryClose(true);
this.screen.RequestClose(true);
parent.Verify(x => x.CloseItem(this.screen, true));
}