From f30627b48e9da7ff39f36580572f58ca0a6aeefc Mon Sep 17 00:00:00 2001
From: mae <qt-info@nokia.com>
Date: Mon, 15 Mar 2010 13:16:40 +0100
Subject: [PATCH] Make persistent code folding and auto-collapse of the license
 header work together

---
 .../coreplugin/editormanager/editormanager.cpp       |  3 +--
 src/plugins/texteditor/basetexteditor.cpp            | 12 ++++++++----
 2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/src/plugins/coreplugin/editormanager/editormanager.cpp b/src/plugins/coreplugin/editormanager/editormanager.cpp
index 94473ab1323..11e397bf4bf 100644
--- a/src/plugins/coreplugin/editormanager/editormanager.cpp
+++ b/src/plugins/coreplugin/editormanager/editormanager.cpp
@@ -1282,8 +1282,7 @@ void EditorManager::restoreEditorState(IEditor *editor)
 {
     QTC_ASSERT(editor, return);
     QString fileName = editor->file()->fileName();
-    if (m_d->m_editorStates.contains(fileName))
-        editor->restoreState(m_d->m_editorStates.value(fileName).toByteArray());
+    editor->restoreState(m_d->m_editorStates.value(fileName).toByteArray());
 }
 
 bool EditorManager::saveEditor(IEditor *editor)
diff --git a/src/plugins/texteditor/basetexteditor.cpp b/src/plugins/texteditor/basetexteditor.cpp
index e4788adfc3f..9034469a456 100644
--- a/src/plugins/texteditor/basetexteditor.cpp
+++ b/src/plugins/texteditor/basetexteditor.cpp
@@ -609,8 +609,6 @@ bool BaseTextEditor::open(const QString &fileName)
 {
     if (d->m_document->open(fileName)) {
         moveCursor(QTextCursor::Start);
-        if (d->m_displaySettings.m_autoFoldFirstComment)
-            d->collapseLicenseHeader();
         setReadOnly(d->m_document->hasDecodingError());
         return true;
     }
@@ -1531,8 +1529,6 @@ void BaseTextEditor::memorizeCursorPosition()
 void BaseTextEditor::restoreCursorPosition()
 {
     restoreState(d->m_tempState);
-    if (d->m_displaySettings.m_autoFoldFirstComment)
-        d->collapseLicenseHeader();
 }
 
 QByteArray BaseTextEditor::saveState() const
@@ -1567,6 +1563,11 @@ QByteArray BaseTextEditor::saveState() const
 
 bool BaseTextEditor::restoreState(const QByteArray &state)
 {
+    if (state.isEmpty()) {
+        if (d->m_displaySettings.m_autoFoldFirstComment)
+            d->collapseLicenseHeader();
+        return false;
+    }
     int version;
     int vval;
     int hval;
@@ -1588,6 +1589,9 @@ bool BaseTextEditor::restoreState(const QByteArray &state)
             if (block.isValid())
                 TextBlockUserData::doCollapse(block, false);
         }
+    } else {
+        if (d->m_displaySettings.m_autoFoldFirstComment)
+            d->collapseLicenseHeader();
     }
 
     d->m_lastCursorChangeWasInteresting = false; // avoid adding last position to history
-- 
GitLab