diff --git a/src/plugins/projectexplorer/sessionmodel.cpp b/src/plugins/projectexplorer/sessionmodel.cpp index 19793c33579..eadacf4d718 100644 --- a/src/plugins/projectexplorer/sessionmodel.cpp +++ b/src/plugins/projectexplorer/sessionmodel.cpp @@ -122,23 +122,16 @@ void SessionModel::resetSessions() endResetModel(); } +void SessionModel::newSession() +{ + runNewSessionDialog("", &SessionManager::createSession); +} + void SessionModel::cloneSession(const QString &session) { - SessionNameInputDialog newSessionInputDialog(SessionManager::sessions(), nullptr); - newSessionInputDialog.setWindowTitle(tr("New Session Name")); - newSessionInputDialog.setValue(session + QLatin1String(" (2)")); - - if (newSessionInputDialog.exec() == QDialog::Accepted) { - QString newSession = newSessionInputDialog.value(); - if (newSession.isEmpty() || SessionManager::sessions().contains(newSession)) - return; - beginResetModel(); - SessionManager::cloneSession(session, newSession); - endResetModel(); - - if (newSessionInputDialog.isSwitchToRequested()) - SessionManager::loadSession(newSession); - } + runNewSessionDialog(session + " (2)", [session](const QString &newName) { + SessionManager::cloneSession(session, newName); + }); } void SessionModel::deleteSession(const QString &session) @@ -151,21 +144,34 @@ void SessionModel::deleteSession(const QString &session) } void SessionModel::renameSession(const QString &session) +{ + runNewSessionDialog(session, [session](const QString &newName) { + SessionManager::cloneSession(session, newName); + }); +} + +void SessionModel::switchToSession(const QString &session) +{ + SessionManager::loadSession(session); + emit sessionSwitched(); +} + +void SessionModel::runNewSessionDialog(const QString &suggestedName, std::function createSession) { SessionNameInputDialog newSessionInputDialog(SessionManager::sessions(), nullptr); newSessionInputDialog.setWindowTitle(tr("New Session Name")); - newSessionInputDialog.setValue(session); + newSessionInputDialog.setValue(suggestedName); if (newSessionInputDialog.exec() == QDialog::Accepted) { QString newSession = newSessionInputDialog.value(); if (newSession.isEmpty() || SessionManager::sessions().contains(newSession)) return; beginResetModel(); - SessionManager::renameSession(session, newSession); + createSession(newSession); endResetModel(); if (newSessionInputDialog.isSwitchToRequested()) - SessionManager::loadSession(newSession); + switchToSession(newSession); } } } // namespace Internal diff --git a/src/plugins/projectexplorer/sessionmodel.h b/src/plugins/projectexplorer/sessionmodel.h index 9534077f5ac..0d1f597351c 100644 --- a/src/plugins/projectexplorer/sessionmodel.h +++ b/src/plugins/projectexplorer/sessionmodel.h @@ -27,6 +27,8 @@ #include +#include + namespace ProjectExplorer { namespace Internal { @@ -45,11 +47,19 @@ public: Q_SCRIPTABLE bool isDefaultVirgin() const; +signals: + void sessionSwitched(); + public slots: void resetSessions(); + void newSession(); void cloneSession(const QString &session); void deleteSession(const QString &session); void renameSession(const QString &session); + void switchToSession(const QString &session); + +private: + void runNewSessionDialog(const QString &suggestedName, std::function createSession); }; } // namespace Internal