From eca3b98c56afc1e86f3ffc4e378e3cb16cdb6405 Mon Sep 17 00:00:00 2001
From: mae <qt-info@nokia.com>
Date: Wed, 3 Jun 2009 17:19:26 +0200
Subject: [PATCH] Use editor manager standard closing facilities for session
 switching

---
 src/plugins/projectexplorer/session.cpp | 43 +++----------------------
 src/plugins/projectexplorer/session.h   |  2 --
 2 files changed, 4 insertions(+), 41 deletions(-)

diff --git a/src/plugins/projectexplorer/session.cpp b/src/plugins/projectexplorer/session.cpp
index 79ba761d1cb..c4a11d07e75 100644
--- a/src/plugins/projectexplorer/session.cpp
+++ b/src/plugins/projectexplorer/session.cpp
@@ -112,7 +112,7 @@ private:
 } // namespace ProjectExplorer
 
 using namespace ProjectExplorer;
-using Internal::SessionFile;
+using namespace ProjectExplorer::Internal;
 
 
 void SessionFile::sessionLoadingProgress()
@@ -215,7 +215,6 @@ bool SessionFile::load(const QString &fileName)
             qWarning() << "Could not find startup project" << startupProjectPath;
     }
 
-
     const QVariant &editorsettings = reader.restoreValue(QLatin1String("EditorSettings"));
     if (editorsettings.isValid()) {
         connect(m_core->editorManager(), SIGNAL(editorOpened(Core::IEditor *)),
@@ -272,6 +271,7 @@ bool SessionFile::save(const QString &fileName)
     }
     writer.saveValue(QLatin1String("ProjectDependencies"), QVariant(depMap));
 
+
     writer.saveValue(QLatin1String("OpenEditors"),
                      m_core->editorManager()->openedEditors().count());
     writer.saveValue(QLatin1String("EditorSettings"),
@@ -694,28 +694,16 @@ bool SessionManager::clear()
     if (debug)
         qDebug() << "SessionManager - clearing session ...";
 
-    bool cancelled;
-    QList<Project *> notClosed = requestCloseOfAllFiles(&cancelled);
-
-    bool success = !cancelled;
+    bool success = m_core->editorManager()->closeAllEditors();
 
     if (success) {
         if (debug)
             qDebug() << "SessionManager - Removing projects ...";
 
-        QList<Project *> toClose;
-        foreach (Project *pro, projects()) {
-            if (!notClosed.contains(pro))
-                toClose << pro;
-        }
-
         setStartupProject(0);
-        removeProjects(toClose);
+        removeProjects(projects());
     }
 
-    if (!notClosed.isEmpty())
-        success = false;
-
     if (debug)
         qDebug() << "SessionManager - clearing session result is " << success;
 
@@ -883,29 +871,6 @@ void SessionManager::setEditorCodec(Core::IEditor *editor, const QString &fileNa
             textEditor->setTextCodec(project->editorConfiguration()->defaultTextCodec());
 }
 
-QList<Project *> SessionManager::requestCloseOfAllFiles(bool *cancelled)
-{
-    *cancelled = false;
-    QList<Core::IFile*> filesToClose;
-    foreach (Project *pro, projects())
-        filesToClose << pro->file();
-    foreach (Core::IEditor *editor, m_core->editorManager()->openedEditors())
-        filesToClose << editor->file();
-    QList<Core::IFile*> notClosed;
-    if (!filesToClose.isEmpty())
-        notClosed = m_core->fileManager()->saveModifiedFiles(filesToClose, cancelled);
-    // close editors here by hand
-    if (!*cancelled) {
-        QList<Core::IEditor*> editorsToClose;
-        foreach (Core::IEditor *editor, m_core->editorManager()->openedEditors())
-            if (!notClosed.contains(editor->file()))
-                editorsToClose << editor;
-        m_core->editorManager()->closeEditors(editorsToClose, false);
-        // project files are closed/removed later (in this::clear)
-    }
-    return Core::Utils::qwConvertList<Project*>(notClosed);
-}
-
 Core::IFile *SessionManager::file() const
 {
     return m_file;
diff --git a/src/plugins/projectexplorer/session.h b/src/plugins/projectexplorer/session.h
index b2131595219..c0099b591f9 100644
--- a/src/plugins/projectexplorer/session.h
+++ b/src/plugins/projectexplorer/session.h
@@ -180,8 +180,6 @@ private:
     QStringList dependenciesOrder() const;
     Project *defaultStartupProject() const;
 
-    QList<Project *> requestCloseOfAllFiles(bool *cancelled);
-
     void updateName(const QString &session);
 
     Core::ICore *m_core;
-- 
GitLab