From 3b2614c6976ff1b201855893a811702376721eb9 Mon Sep 17 00:00:00 2001
From: con <qtc-committer@nokia.com>
Date: Fri, 22 Oct 2010 16:25:19 +0200
Subject: [PATCH] Fix closing and restoring editors in presence of temporary
 editors.

* Editor manager should abort closing core, if there's a ICoreListener
that aborts closing of a editor.
* Don't save state of temporary editors, and don't save them as open in
  a splitter. So restoring the editor manager state won't try to reopen
  temporary editors.

Task-number: QTCREATORBUG-2845
Task-number: QTCREATORBUG-2841
Reviewed-by: Tobias Hunger
---
 .../editormanager/editormanager.cpp           |  5 +++--
 .../coreplugin/editormanager/editorview.cpp   | 20 +++++++++++++++----
 2 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/src/plugins/coreplugin/editormanager/editormanager.cpp b/src/plugins/coreplugin/editormanager/editormanager.cpp
index a3bce5276fe..de7ada34f0d 100644
--- a/src/plugins/coreplugin/editormanager/editormanager.cpp
+++ b/src/plugins/coreplugin/editormanager/editormanager.cpp
@@ -768,7 +768,7 @@ bool EditorManager::closeEditors(const QList<IEditor*> &editorsToClose, bool ask
         foreach (ICoreListener *listener, listeners) {
             if (!listener->editorAboutToClose(editor)) {
                 editorAccepted = false;
-                closingFailed = false;
+                closingFailed = true;
                 break;
             }
         }
@@ -802,7 +802,8 @@ bool EditorManager::closeEditors(const QList<IEditor*> &editorsToClose, bool ask
     // remove the editors
     foreach (IEditor *editor, acceptedEditors) {
         emit editorAboutToClose(editor);
-        if (!editor->file()->fileName().isEmpty()) {
+        if (!editor->file()->fileName().isEmpty()
+                && !editor->isTemporary()) {
             QByteArray state = editor->saveState();
             if (!state.isEmpty())
                 m_d->m_editorStates.insert(editor->file()->fileName(), QVariant(state));
diff --git a/src/plugins/coreplugin/editormanager/editorview.cpp b/src/plugins/coreplugin/editormanager/editorview.cpp
index ea165c02a83..75db54bcdef 100644
--- a/src/plugins/coreplugin/editormanager/editorview.cpp
+++ b/src/plugins/coreplugin/editormanager/editorview.cpp
@@ -803,14 +803,26 @@ QByteArray SplitterOrView::saveState() const
         IEditor* e = editor();
         EditorManager *em = CoreImpl::instance()->editorManager();
 
-        if (e && e == em->currentEditor()) {
+        // don't save state of temporary or ad-hoc editors
+        if (e && (e->isTemporary() || e->file()->fileName().isEmpty())) {
+            // look for another editor that is more suited
+            e = 0;
+            foreach (IEditor *otherEditor, editors()) {
+                if (!otherEditor->isTemporary() && !otherEditor->file()->fileName().isEmpty()) {
+                    e = otherEditor;
+                    break;
+                }
+            }
+        }
+
+        if (!e) {
+            stream << QByteArray("empty");
+        } else if (e == em->currentEditor()) {
             stream << QByteArray("currenteditor")
                     << e->file()->fileName() << e->id() << e->saveState();
-        } else if (e) {
+        } else {
             stream << QByteArray("editor")
                     << e->file()->fileName() << e->id() << e->saveState();
-        } else {
-            stream << QByteArray("empty");
         }
     }
     return bytes;
-- 
GitLab