示例#1
0
        /// <summary>
        /// Closes the document</summary>
        /// <param name="document">Document to close</param>
        /// <returns>True iff close was not cancelled by user</returns>
        public virtual bool Close(IDocument document)
        {
            if (document == null)
            {
                return(true);
            }

            var args = new DocumentClosingEventArgs(document);

            DocumentClosing.Raise(this, args);

            bool closeConfirmed = args.Cancel == false && ConfirmClose(document);

            if (closeConfirmed)
            {
                IDocumentClient client = GetClient(document);
                OnDocumentClosing(document);

                client.Close(document);

                DocumentRegistry.Remove(document);
                m_untitledDocuments.Remove(document);              // in case it was untitled
                m_newDocumentPaths.Remove(document.Uri.LocalPath); // probably not necessary, but seems like a good idea to clean-up

                OnDocumentClosed(document);
                DocumentClosed.Raise(this, new DocumentEventArgs(document, DocumentEventType.Closed));
            }

            return(closeConfirmed);
        }