示例#1
0
        /// <summary>
        /// Closes all the opened documents
        /// </summary>
        /// <returns>True if closed successfully, false if user hit 'cancel'.</returns>
        public bool CloseAll()
        {
            // Get dirty documents
            var unsaved = DocumentManager.Editors
                          .Select(editor => editor.AttachedDocument)
                          .Where(document => document.IsDirty);

            // There are unsaved documents? Display save dialog
            if (unsaved.Any())
            {
                switch (CloseUnsavedDialog.ShowDialog(OwnerWindow, unsaved))
                {
                case CloseUnsavedDialogResult.Save:
                    SaveAll();
                    break;

                case CloseUnsavedDialogResult.Cancel:
                    return(false);
                }
            }

            // Close all documents
            // To array is used because DocumentManager.Editors is modified when closing a document.
            DocumentManager.Editors.ToArray().ForEach(DocumentManager.Close);

            // Done
            return(true);
        }
示例#2
0
        /// <summary>
        /// Closes an active document.
        /// </summary>
        /// <param name="editor">The document editor attached</param>
        /// <returns>True if closed successfully</returns>
        /// <remarks>Shows the 'are you sure' prompt if there are unsaved edits.</remarks>
        public bool Close(IDocumentEditor editor)
        {
            // Show the 'are you sure' prompt if necesary
            if (editor.AttachedDocument.IsDirty)
            {
                switch (CloseUnsavedDialog.ShowDialog(OwnerWindow, editor.AttachedDocument))
                {
                case CloseUnsavedDialogResult.Save:
                    Save();
                    break;

                case CloseUnsavedDialogResult.Cancel:
                    return(false);
                }
            }

            // Close
            DocumentManager.Close(editor);

            // Update ActiveDocument
            if (editor == ActiveDocumentEditor)
            {
                ActiveDocumentEditor = null;
            }

            return(true);
        }