forked from qt-creator/qt-creator
Simplfy logic in SessionManager::loadImpl
Removing the bool success makes later refactorings easier to do. The code flow is the same, except that the block handling failedProjects after load was always run, even if SessionFile::load returned false. The only place SessionFile::load returns false failedProjects didn't yet change, so the code was wrong before. Change-Id: I8ce565791d67ece7ab8fc7c4a799ed365153e34b Reviewed-by: Tobias Hunger <tobias.hunger@nokia.com>
This commit is contained in:
@@ -500,68 +500,69 @@ bool SessionManager::loadImpl(const QString &fileName)
|
|||||||
if (debug)
|
if (debug)
|
||||||
qDebug() << "SessionManager - restoring session " << fileName << " ...";
|
qDebug() << "SessionManager - restoring session " << fileName << " ...";
|
||||||
|
|
||||||
bool success = true;
|
|
||||||
if (isDefaultVirgin()) {
|
if (isDefaultVirgin()) {
|
||||||
// do not save initial and virgin default session
|
// do not save initial and virgin default session
|
||||||
} else if (!save() || !clear()) {
|
} else if (!save() || !clear()) {
|
||||||
success = false;
|
m_virginSession = false;
|
||||||
|
if (debug)
|
||||||
|
qDebug() << "SessionManager - restoring session returned " << false;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_virginSession = false;
|
m_virginSession = false;
|
||||||
|
|
||||||
if (success) {
|
emit aboutToUnloadSession();
|
||||||
emit aboutToUnloadSession();
|
delete m_file;
|
||||||
delete m_file;
|
m_file = new SessionFile;
|
||||||
m_file = new SessionFile;
|
const QString &sessionName = sessionNameFromFileName(fileName);
|
||||||
const QString &sessionName = sessionNameFromFileName(fileName);
|
emit aboutToLoadSession(sessionName);
|
||||||
emit aboutToLoadSession(sessionName);
|
m_sessionName = sessionName;
|
||||||
m_sessionName = sessionName;
|
updateWindowTitle();
|
||||||
updateWindowTitle();
|
if (!m_file->load(fileName)) {
|
||||||
if (!m_file->load(fileName)) {
|
QMessageBox::warning(0, tr("Error while restoring session"),
|
||||||
QMessageBox::warning(0, tr("Error while restoring session"),
|
tr("Could not restore session %1").arg(fileName));
|
||||||
tr("Could not restore session %1").arg(fileName));
|
if (debug)
|
||||||
success = false;
|
qDebug() << "SessionManager - restoring session returned " << false;
|
||||||
}
|
|
||||||
// m_file->load() sets the m_file->startupProject
|
|
||||||
// but doesn't emit this signal, so we do it here
|
|
||||||
emit startupProjectChanged(m_file->m_startupProject);
|
|
||||||
|
|
||||||
QStringList failedProjects = m_file->failedProjectFileNames();
|
return false;
|
||||||
if (!failedProjects.isEmpty()) {
|
}
|
||||||
QString fileList =
|
// m_file->load() sets the m_file->startupProject
|
||||||
QDir::toNativeSeparators(failedProjects.join(QLatin1String("<br>")));
|
// but doesn't emit this signal, so we do it here
|
||||||
QMessageBox * box = new QMessageBox(QMessageBox::Warning,
|
emit startupProjectChanged(m_file->m_startupProject);
|
||||||
tr("Failed to restore project files"),
|
|
||||||
tr("Could not restore the following project files:<br><b>%1</b>").
|
|
||||||
arg(fileList));
|
|
||||||
QPushButton * keepButton = new QPushButton(tr("Keep projects in Session"), box);
|
|
||||||
QPushButton * removeButton = new QPushButton(tr("Remove projects from Session"), box);
|
|
||||||
box->addButton(keepButton, QMessageBox::AcceptRole);
|
|
||||||
box->addButton(removeButton, QMessageBox::DestructiveRole);
|
|
||||||
|
|
||||||
box->exec();
|
QStringList failedProjects = m_file->failedProjectFileNames();
|
||||||
|
if (!failedProjects.isEmpty()) {
|
||||||
|
QString fileList =
|
||||||
|
QDir::toNativeSeparators(failedProjects.join(QLatin1String("<br>")));
|
||||||
|
QMessageBox * box = new QMessageBox(QMessageBox::Warning,
|
||||||
|
tr("Failed to restore project files"),
|
||||||
|
tr("Could not restore the following project files:<br><b>%1</b>").
|
||||||
|
arg(fileList));
|
||||||
|
QPushButton * keepButton = new QPushButton(tr("Keep projects in Session"), box);
|
||||||
|
QPushButton * removeButton = new QPushButton(tr("Remove projects from Session"), box);
|
||||||
|
box->addButton(keepButton, QMessageBox::AcceptRole);
|
||||||
|
box->addButton(removeButton, QMessageBox::DestructiveRole);
|
||||||
|
|
||||||
if (box->clickedButton() == removeButton)
|
box->exec();
|
||||||
m_file->clearFailedProjectFileNames();
|
|
||||||
}
|
if (box->clickedButton() == removeButton)
|
||||||
|
m_file->clearFailedProjectFileNames();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (success) {
|
// restore the active mode
|
||||||
// restore the active mode
|
QString modeIdentifier = value(QLatin1String("ActiveMode")).toString();
|
||||||
QString modeIdentifier = value(QLatin1String("ActiveMode")).toString();
|
if (modeIdentifier.isEmpty())
|
||||||
if (modeIdentifier.isEmpty())
|
modeIdentifier = QLatin1String(Core::Constants::MODE_EDIT);
|
||||||
modeIdentifier = QLatin1String(Core::Constants::MODE_EDIT);
|
|
||||||
|
|
||||||
ModeManager::activateMode(modeIdentifier);
|
ModeManager::activateMode(modeIdentifier);
|
||||||
ModeManager::setFocusToCurrentMode();
|
ModeManager::setFocusToCurrentMode();
|
||||||
|
|
||||||
emit sessionLoaded();
|
emit sessionLoaded();
|
||||||
}
|
|
||||||
|
|
||||||
if (debug)
|
if (debug)
|
||||||
qDebug() << "SessionManager - restoring session returned " << success;
|
qDebug() << "SessionManager - restoring session returned " << true;
|
||||||
|
|
||||||
return success;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SessionManager::save()
|
bool SessionManager::save()
|
||||||
|
|||||||
Reference in New Issue
Block a user