SessionManager: Be smarter about loading/unloading projects

On switching sessions don't unload projects that are in both
sessions.

Change-Id: Iceceea262677ab523f8c3c9d2dda64faa34d6e0d
Reviewed-by: Tobias Hunger <tobias.hunger@theqtcompany.com>
This commit is contained in:
Daniel Teske
2015-08-20 16:27:19 +02:00
parent 8bef635980
commit bce3335365

View File

@@ -890,6 +890,8 @@ bool SessionManager::loadSession(const QString &session)
if (!sessions().contains(session)) if (!sessions().contains(session))
return false; return false;
QStringList fileList;
// Try loading the file // Try loading the file
FileName fileName = sessionNameToFileName(session); FileName fileName = sessionNameToFileName(session);
PersistentSettingsReader reader; PersistentSettingsReader reader;
@@ -897,8 +899,10 @@ bool SessionManager::loadSession(const QString &session)
if (!reader.load(fileName)) { if (!reader.load(fileName)) {
QMessageBox::warning(ICore::dialogParent(), tr("Error while restoring session"), QMessageBox::warning(ICore::dialogParent(), tr("Error while restoring session"),
tr("Could not restore session %1").arg(fileName.toUserOutput())); tr("Could not restore session %1").arg(fileName.toUserOutput()));
return false; return false;
} }
fileList = reader.restoreValue(QLatin1String("ProjectList")).toStringList();
} }
d->m_loadingSession = true; d->m_loadingSession = true;
@@ -920,7 +924,22 @@ bool SessionManager::loadSession(const QString &session)
} }
setStartupProject(0); setStartupProject(0);
removeProjects(projects());
QList<Project *> oldProjects = projects();
auto it = oldProjects.begin();
auto end = oldProjects.end();
while (it != end) {
int index = fileList.indexOf((*it)->document()->filePath().toString());
if (index != -1) {
fileList.removeAt(index);
it = oldProjects.erase(it);
} else {
++it;
}
}
removeProjects(oldProjects);
d->m_failedProjects.clear(); d->m_failedProjects.clear();
d->m_depMap.clear(); d->m_depMap.clear();
@@ -950,9 +969,6 @@ bool SessionManager::loadSession(const QString &session)
if (c.isValid()) if (c.isValid())
StyleHelper::setBaseColor(c); StyleHelper::setBaseColor(c);
QStringList fileList =
reader.restoreValue(QLatin1String("ProjectList")).toStringList();
d->m_future.setProgressRange(0, fileList.count() + 1/*initialization above*/ + 1/*editors*/); d->m_future.setProgressRange(0, fileList.count() + 1/*initialization above*/ + 1/*editors*/);
d->m_future.setProgressValue(1); d->m_future.setProgressValue(1);