diff --git a/Stylet/IScreen.cs b/Stylet/IScreen.cs index 8f418ae..be3361c 100644 --- a/Stylet/IScreen.cs +++ b/Stylet/IScreen.cs @@ -105,10 +105,22 @@ namespace Stylet Task CanCloseAsync(); } + /// + /// Get the object to request that its parent close it + /// + public interface IRequestClose + { + /// + /// Request that the conductor responsible for this screen close it + /// + /// DialogResult to return, if this is a dialog + void RequestClose(bool? dialogResult = null); + } + /// /// Generalised 'screen' composing all the behaviours expected of a screen /// - public interface IScreen : IViewAware, IHaveDisplayName, IActivate, IDeactivate, IChild, IClose, IGuardClose + public interface IScreen : IViewAware, IHaveDisplayName, IActivate, IDeactivate, IChild, IClose, IGuardClose, IRequestClose { } diff --git a/Stylet/MessageBoxViewModel.cs b/Stylet/MessageBoxViewModel.cs index 8f1fcd1..b08e8af 100644 --- a/Stylet/MessageBoxViewModel.cs +++ b/Stylet/MessageBoxViewModel.cs @@ -229,7 +229,7 @@ namespace Stylet public void ButtonClicked(MessageBoxResult button) { this.ClickedButton = button; - this.TryClose(true); + this.RequestClose(true); } } } diff --git a/Stylet/Screen.cs b/Stylet/Screen.cs index cf63ee4..2f25589 100644 --- a/Stylet/Screen.cs +++ b/Stylet/Screen.cs @@ -208,7 +208,7 @@ namespace Stylet private object _parent; /// - /// 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 /// public object Parent { @@ -241,16 +241,18 @@ namespace Stylet #endregion + #region IRequestClose + /// /// Request that the conductor responsible for this screen close it /// /// DialogResult to return, if this is a dialog - 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 + + /// + /// Obselete - use RequestClose + /// + /// DialogResult to return, if this is a dialog + [Obsolete("Obseleted by RequestClose", true)] + public virtual void TryClose(bool? dialogResult = null) + { + this.RequestClose(dialogResult); + } } } diff --git a/Stylet/WindowManager.cs b/Stylet/WindowManager.cs index f03bfe4..5d3baf0 100644 --- a/Stylet/WindowManager.cs +++ b/Stylet/WindowManager.cs @@ -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; diff --git a/StyletIntegrationTests/ShowDialogAndDialogResult/DialogViewModel.cs b/StyletIntegrationTests/ShowDialogAndDialogResult/DialogViewModel.cs index 3b2ba05..1efa41e 100644 --- a/StyletIntegrationTests/ShowDialogAndDialogResult/DialogViewModel.cs +++ b/StyletIntegrationTests/ShowDialogAndDialogResult/DialogViewModel.cs @@ -26,7 +26,7 @@ namespace StyletIntegrationTests.ShowDialogAndDialogResult public void Close() { - this.TryClose(this.SelectedDesiredResult.Value); + this.RequestClose(this.SelectedDesiredResult.Value); } } } diff --git a/StyletUnitTests/ScreenTests.cs b/StyletUnitTests/ScreenTests.cs index bb46ea5..a36f5e1 100644 --- a/StyletUnitTests/ScreenTests.cs +++ b/StyletUnitTests/ScreenTests.cs @@ -264,18 +264,18 @@ namespace StyletUnitTests } [Test] - public void TryCloseThrowsIfParentIsNotIChildDelegate() + public void RequestCloseThrowsIfParentIsNotIChildDelegate() { this.screen.Parent = new object(); - Assert.Throws(() => this.screen.TryClose()); + Assert.Throws(() => this.screen.RequestClose()); } [Test] - public void TryCloseCallsParentCloseItemPassingDialogResult() + public void RequestCloseCallsParentCloseItemPassingDialogResult() { var parent = new Mock(); screen.Parent = parent.Object; - this.screen.TryClose(true); + this.screen.RequestClose(true); parent.Verify(x => x.CloseItem(this.screen, true)); }