Commit 9e56781b authored by Leandro Melo's avatar Leandro Melo

Proj. explorer: Adjust order of load/unload signals

This tries to fix inconsistencies concerning the order of some signals
and the corresponding state of the sessions. In particular, it now emittes
aboutToLoadSession *after* aboutToUnloadSession. Also, retrieving the
active session name gives the correct result when updating project files.
In addition, there's a new parameter to aboutToLoadSession which describes
the session being loaded.

Change-Id: Iab5fb21080a7ee9bbf9f4d8958499cbc5549e81e
Reviewed-by: default avatarDaniel Teske <daniel.teske@nokia.com>
parent 21efc233
......@@ -149,7 +149,7 @@ ProjectTreeWidget::ProjectTreeWidget(QWidget *parent)
connect(m_explorer->session(), SIGNAL(startupProjectChanged(ProjectExplorer::Project *)),
this, SLOT(startupProjectChanged(ProjectExplorer::Project *)));
connect(m_explorer->session(), SIGNAL(aboutToLoadSession()),
connect(m_explorer->session(), SIGNAL(aboutToLoadSession(QString)),
this, SLOT(disableAutoExpand()));
connect(m_explorer->session(), SIGNAL(sessionLoaded()),
this, SLOT(loadExpandData()));
......
......@@ -554,6 +554,9 @@ bool SessionManager::createImpl(const QString &fileName)
emit aboutToUnloadSession();
delete m_file;
m_file = new SessionFile;
const QString &sessionName = sessionNameFromFileName(fileName);
emit aboutToLoadSession(sessionName);
updateName(sessionName);
m_file->setFileName(fileName);
setStartupProject(0);
......@@ -561,6 +564,8 @@ bool SessionManager::createImpl(const QString &fileName)
ModeManager::instance()->activateMode(Core::Constants::MODE_EDIT);
ModeManager::instance()->setFocusToCurrentMode();
}
emit sessionLoaded();
}
m_virginSession = true;
......@@ -594,6 +599,9 @@ bool SessionManager::loadImpl(const QString &fileName)
emit aboutToUnloadSession();
delete m_file;
m_file = new SessionFile;
const QString &sessionName = sessionNameFromFileName(fileName);
emit aboutToLoadSession(sessionName);
updateName(sessionName);
if (!m_file->load(fileName)) {
QMessageBox::warning(0, tr("Error while restoring session"),
tr("Could not restore session %1").arg(fileName));
......@@ -631,6 +639,8 @@ bool SessionManager::loadImpl(const QString &fileName)
ModeManager::instance()->activateMode(modeIdentifier);
ModeManager::instance()->setFocusToCurrentMode();
emit sessionLoaded();
}
if (debug)
......@@ -972,16 +982,20 @@ QString SessionManager::sessionNameToFileName(const QString &session) const
return m_core->userResourcePath() + '/' + session + ".qws";
}
QString SessionManager::sessionNameFromFileName(const QString &fileName) const
{
const int slash = fileName.lastIndexOf('/');
Q_ASSERT(slash != -1 && fileName.endsWith(".qws"));
return fileName.mid(slash + 1, fileName.length() - slash - 5); // Exclude .qws
}
/*!
\brief Creates a new default session and switches to it.
*/
void SessionManager::createAndLoadNewDefaultSession()
{
emit aboutToLoadSession();
updateName("default");
createImpl(sessionNameToFileName(m_sessionName));
emit sessionLoaded();
createImpl(sessionNameToFileName("default"));
}
/*!
......@@ -1050,23 +1064,13 @@ bool SessionManager::loadSession(const QString &session)
if (!sessions().contains(session))
return false;
emit aboutToLoadSession();
QString fileName = sessionNameToFileName(session);
if (QFileInfo(fileName).exists()) {
if (loadImpl(fileName)) {
updateName(session);
emit sessionLoaded();
return true;
}
} else {
// Create a new session with that name
if (!createImpl(sessionNameToFileName(session)))
return false;
updateName(session);
emit sessionLoaded();
return true;
}
return false;
if (QFileInfo(fileName).exists())
return loadImpl(fileName);
// Create a new session with that name
return createImpl(sessionNameToFileName(session));
}
QString SessionManager::lastSession() const
......
......@@ -105,6 +105,7 @@ public:
QString currentSession() const;
QString sessionNameToFileName(const QString &session) const;
QString sessionNameFromFileName(const QString &fileName) const;
Project *startupProject() const;
const QList<Project *> &projects() const;
......@@ -138,7 +139,7 @@ signals:
void startupProjectChanged(ProjectExplorer::Project *project);
void aboutToLoadSession();
void aboutToLoadSession(QString sessionName);
void sessionLoaded();
void aboutToUnloadSession();
void aboutToSaveSession();
......
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