Commit eca3b98c authored by mae's avatar mae
Browse files

Use editor manager standard closing facilities for session switching

parent dddb965f
......@@ -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;
......
......@@ -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;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment