/// <summary> /// Request to close a document. The document will be closed /// (if possible) before returning. /// </summary> /// <param name="document">The document to close</param> /// <returns>True if the document was closed</returns> public async Task <bool> RequestCloseDocument(IDocument document) { var canClose = await document.RequestClose(); var msg = new DocumentCloseMessage(document); await Oy.Publish("Document:RequestClose", msg); if (msg.Cancelled) { canClose = false; } if (canClose) { ForceCloseDocument(document); } return(canClose); }
/// <summary> /// A request to close a document has been made, prompt the user to save changes /// or cancel the request. /// </summary> private async Task DocumentRequestClose(DocumentCloseMessage msg) { var doc = msg.Document; if (doc.HasUnsavedChanges) { var r = MessageBox.Show(this, String.Format(SaveChangesToFile, doc.Name), UnsavedChanges, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (r == DialogResult.Cancel) { msg.Cancel(); return; } if (r == DialogResult.Yes) { if (!await SaveDocument(doc)) { msg.Cancel(); } } } }