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: Daniel Teske <daniel.teske@nokia.com>
This commit is contained in:
Leandro Melo
2011-11-09 17:03:00 +01:00
parent 21efc23373
commit 9e56781b5b
3 changed files with 27 additions and 22 deletions

View File

@@ -149,7 +149,7 @@ ProjectTreeWidget::ProjectTreeWidget(QWidget *parent)
connect(m_explorer->session(), SIGNAL(startupProjectChanged(ProjectExplorer::Project *)), connect(m_explorer->session(), SIGNAL(startupProjectChanged(ProjectExplorer::Project *)),
this, SLOT(startupProjectChanged(ProjectExplorer::Project *))); this, SLOT(startupProjectChanged(ProjectExplorer::Project *)));
connect(m_explorer->session(), SIGNAL(aboutToLoadSession()), connect(m_explorer->session(), SIGNAL(aboutToLoadSession(QString)),
this, SLOT(disableAutoExpand())); this, SLOT(disableAutoExpand()));
connect(m_explorer->session(), SIGNAL(sessionLoaded()), connect(m_explorer->session(), SIGNAL(sessionLoaded()),
this, SLOT(loadExpandData())); this, SLOT(loadExpandData()));

View File

@@ -554,6 +554,9 @@ bool SessionManager::createImpl(const QString &fileName)
emit aboutToUnloadSession(); emit aboutToUnloadSession();
delete m_file; delete m_file;
m_file = new SessionFile; m_file = new SessionFile;
const QString &sessionName = sessionNameFromFileName(fileName);
emit aboutToLoadSession(sessionName);
updateName(sessionName);
m_file->setFileName(fileName); m_file->setFileName(fileName);
setStartupProject(0); setStartupProject(0);
@@ -561,6 +564,8 @@ bool SessionManager::createImpl(const QString &fileName)
ModeManager::instance()->activateMode(Core::Constants::MODE_EDIT); ModeManager::instance()->activateMode(Core::Constants::MODE_EDIT);
ModeManager::instance()->setFocusToCurrentMode(); ModeManager::instance()->setFocusToCurrentMode();
} }
emit sessionLoaded();
} }
m_virginSession = true; m_virginSession = true;
@@ -594,6 +599,9 @@ bool SessionManager::loadImpl(const QString &fileName)
emit aboutToUnloadSession(); emit aboutToUnloadSession();
delete m_file; delete m_file;
m_file = new SessionFile; m_file = new SessionFile;
const QString &sessionName = sessionNameFromFileName(fileName);
emit aboutToLoadSession(sessionName);
updateName(sessionName);
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));
@@ -631,6 +639,8 @@ bool SessionManager::loadImpl(const QString &fileName)
ModeManager::instance()->activateMode(modeIdentifier); ModeManager::instance()->activateMode(modeIdentifier);
ModeManager::instance()->setFocusToCurrentMode(); ModeManager::instance()->setFocusToCurrentMode();
emit sessionLoaded();
} }
if (debug) if (debug)
@@ -972,16 +982,20 @@ QString SessionManager::sessionNameToFileName(const QString &session) const
return m_core->userResourcePath() + '/' + session + ".qws"; 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. \brief Creates a new default session and switches to it.
*/ */
void SessionManager::createAndLoadNewDefaultSession() void SessionManager::createAndLoadNewDefaultSession()
{ {
emit aboutToLoadSession(); createImpl(sessionNameToFileName("default"));
updateName("default");
createImpl(sessionNameToFileName(m_sessionName));
emit sessionLoaded();
} }
/*! /*!
@@ -1050,23 +1064,13 @@ bool SessionManager::loadSession(const QString &session)
if (!sessions().contains(session)) if (!sessions().contains(session))
return false; return false;
emit aboutToLoadSession();
QString fileName = sessionNameToFileName(session); QString fileName = sessionNameToFileName(session);
if (QFileInfo(fileName).exists()) { if (QFileInfo(fileName).exists())
if (loadImpl(fileName)) { return loadImpl(fileName);
updateName(session);
emit sessionLoaded();
return true;
}
} else {
// Create a new session with that name // Create a new session with that name
if (!createImpl(sessionNameToFileName(session))) return createImpl(sessionNameToFileName(session));
return false;
updateName(session);
emit sessionLoaded();
return true;
}
return false;
} }
QString SessionManager::lastSession() const QString SessionManager::lastSession() const

View File

@@ -105,6 +105,7 @@ public:
QString currentSession() const; QString currentSession() const;
QString sessionNameToFileName(const QString &session) const; QString sessionNameToFileName(const QString &session) const;
QString sessionNameFromFileName(const QString &fileName) const;
Project *startupProject() const; Project *startupProject() const;
const QList<Project *> &projects() const; const QList<Project *> &projects() const;
@@ -138,7 +139,7 @@ signals:
void startupProjectChanged(ProjectExplorer::Project *project); void startupProjectChanged(ProjectExplorer::Project *project);
void aboutToLoadSession(); void aboutToLoadSession(QString sessionName);
void sessionLoaded(); void sessionLoaded();
void aboutToUnloadSession(); void aboutToUnloadSession();
void aboutToSaveSession(); void aboutToSaveSession();