/// <inheritdoc/> public bool Close(Document document, bool force) { if (document == null) { throw new ArgumentNullException(nameof(document)); } if (document.IsDisposed) { return(true); } Debug.Assert(_documents.Contains(document), "Document already closed."); Logger.Info(CultureInfo.InvariantCulture, "Closing document \"{0}\".", document.GetName()); bool canClose = force || PromptSaveChanges(document); if (canClose) { if (!document.IsUntitled) { RememberRecentFile(document.Uri); } document.Dispose(); foreach (var viewModel in document.ViewModels.ToArray()) { var task = viewModel.Conductor?.DeactivateItemAsync(viewModel, true); Debug.Assert(task.IsCompleted, "DeactivateItem expected to be synchronous operation."); Debug.Assert(task.Result, "DeactivateItem failed."); } Debug.Assert(!document.ViewModels.Any(), "One or more view models found. All document view models expected to be closed."); Debug.Assert(Editor.Items.OfType <DocumentViewModel>().All(vm => vm.Document != document), "Open view model is still referencing the closed document."); return(true); } return(false); }
/// <inheritdoc/> public bool Close(Document document, bool force) { if (document == null) throw new ArgumentNullException(nameof(document)); if (document.IsDisposed) return true; Debug.Assert(_documents.Contains(document), "Document already closed."); Logger.Info(CultureInfo.InvariantCulture, "Closing document \"{0}\".", document.GetName()); bool canClose = force || PromptSaveChanges(document); if (canClose) { if (!document.IsUntitled) RememberRecentFile(document.Uri); document.Dispose(); foreach (var viewModel in document.ViewModels.ToArray()) { var task = viewModel.Conductor?.DeactivateItemAsync(viewModel, true); Debug.Assert(task.IsCompleted, "DeactivateItem expected to be synchronous operation."); Debug.Assert(task.Result, "DeactivateItem failed."); } Debug.Assert(!document.ViewModels.Any(), "One or more view models found. All document view models expected to be closed."); Debug.Assert(Editor.Items.OfType<DocumentViewModel>().All(vm => vm.Document != document), "Open view model is still referencing the closed document."); return true; } return false; }