diff --git a/src/plugins/projectexplorer/projecttreewidget.cpp b/src/plugins/projectexplorer/projecttreewidget.cpp index 8d40b7a05f5a3f57cbda2ed8be9233b348ef5d23..7f5e826ddfe3819d2cb4fd8ecd665826d0b3026a 100644 --- a/src/plugins/projectexplorer/projecttreewidget.cpp +++ b/src/plugins/projectexplorer/projecttreewidget.cpp @@ -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())); diff --git a/src/plugins/projectexplorer/session.cpp b/src/plugins/projectexplorer/session.cpp index ebe84fd1ab4bbbdb15697e685a15f1ab6ad4b7bb..4e3b7f210e7cef5352ab6dfebf8158d581dbe04c 100644 --- a/src/plugins/projectexplorer/session.cpp +++ b/src/plugins/projectexplorer/session.cpp @@ -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 diff --git a/src/plugins/projectexplorer/session.h b/src/plugins/projectexplorer/session.h index bafb627e17736c670d392b6a3bb38ad79473f7ec..f00008a4d281b791a9302dd05bf0c0e2cd7cc5a5 100644 --- a/src/plugins/projectexplorer/session.h +++ b/src/plugins/projectexplorer/session.h @@ -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();