diff --git a/src/plugins/projectexplorer/sessiondialog.cpp b/src/plugins/projectexplorer/sessiondialog.cpp index 46c65527dc0..5145bd0c7e1 100644 --- a/src/plugins/projectexplorer/sessiondialog.cpp +++ b/src/plugins/projectexplorer/sessiondialog.cpp @@ -88,8 +88,9 @@ SessionNameInputDialog::SessionNameInputDialog(QWidget *parent) m_newSessionLineEdit->setValidator(new SessionValidator(this, SessionManager::sessions())); hlayout->addWidget(m_newSessionLineEdit); auto buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this); - buttons->button(QDialogButtonBox::Ok)->setText(tr("&Create")); - m_switchToButton = buttons->addButton(tr("Create and &Open"), QDialogButtonBox::AcceptRole); + m_okButton = buttons->button(QDialogButtonBox::Ok); + m_switchToButton = new QPushButton; + buttons->addButton(m_switchToButton, QDialogButtonBox::AcceptRole); connect(m_switchToButton, &QPushButton::clicked, [this]() { m_usedSwitchTo = true; }); @@ -99,6 +100,12 @@ SessionNameInputDialog::SessionNameInputDialog(QWidget *parent) setLayout(hlayout); } +void SessionNameInputDialog::setActionText(const QString &actionText, const QString &openActionText) +{ + m_okButton->setText(actionText); + m_switchToButton->setText(openActionText); +} + void SessionNameInputDialog::setValue(const QString &value) { m_newSessionLineEdit->setText(value); diff --git a/src/plugins/projectexplorer/sessiondialog.h b/src/plugins/projectexplorer/sessiondialog.h index 576c9b4a7e1..e1ced4884d1 100644 --- a/src/plugins/projectexplorer/sessiondialog.h +++ b/src/plugins/projectexplorer/sessiondialog.h @@ -61,6 +61,7 @@ class SessionNameInputDialog : public QDialog public: explicit SessionNameInputDialog(QWidget *parent = nullptr); + void setActionText(const QString &actionText, const QString &openActionText); void setValue(const QString &value); QString value() const; bool isSwitchToRequested() const; @@ -68,6 +69,7 @@ public: private: QLineEdit *m_newSessionLineEdit = nullptr; QPushButton *m_switchToButton = nullptr; + QPushButton *m_okButton = nullptr; bool m_usedSwitchTo = false; }; diff --git a/src/plugins/projectexplorer/sessionmodel.cpp b/src/plugins/projectexplorer/sessionmodel.cpp index 38f9b8ed7d4..1f6064ffe4d 100644 --- a/src/plugins/projectexplorer/sessionmodel.cpp +++ b/src/plugins/projectexplorer/sessionmodel.cpp @@ -188,14 +188,23 @@ void SessionModel::resetSessions() void SessionModel::newSession() { - runNewSessionDialog("", [](const QString &newName) { + SessionNameInputDialog sessionInputDialog; + sessionInputDialog.setWindowTitle(tr("New Session Name")); + sessionInputDialog.setActionText(tr("&Create"), tr("Create and &Open")); + + runSessionNameInputDialog(&sessionInputDialog, [](const QString &newName) { SessionManager::createSession(newName); }); } void SessionModel::cloneSession(const QString &session) { - runNewSessionDialog(session + " (2)", [session](const QString &newName) { + SessionNameInputDialog sessionInputDialog; + sessionInputDialog.setWindowTitle(tr("New Session Name")); + sessionInputDialog.setActionText(tr("&Clone"), tr("Clone and &Open")); + sessionInputDialog.setValue(session + " (2)"); + + runSessionNameInputDialog(&sessionInputDialog, [session](const QString &newName) { SessionManager::cloneSession(session, newName); }); } @@ -211,7 +220,12 @@ void SessionModel::deleteSession(const QString &session) void SessionModel::renameSession(const QString &session) { - runNewSessionDialog(session, [session](const QString &newName) { + SessionNameInputDialog sessionInputDialog; + sessionInputDialog.setWindowTitle(tr("Rename Session")); + sessionInputDialog.setActionText(tr("&Rename"), tr("Rename and &Open")); + sessionInputDialog.setValue(session); + + runSessionNameInputDialog(&sessionInputDialog, [session](const QString &newName) { SessionManager::renameSession(session, newName); }); } @@ -222,21 +236,17 @@ void SessionModel::switchToSession(const QString &session) emit sessionSwitched(); } -void SessionModel::runNewSessionDialog(const QString &suggestedName, std::function createSession) +void SessionModel::runSessionNameInputDialog(SessionNameInputDialog *sessionInputDialog, std::function createSession) { - SessionNameInputDialog newSessionInputDialog; - newSessionInputDialog.setWindowTitle(tr("New Session Name")); - newSessionInputDialog.setValue(suggestedName); - - if (newSessionInputDialog.exec() == QDialog::Accepted) { - QString newSession = newSessionInputDialog.value(); + if (sessionInputDialog->exec() == QDialog::Accepted) { + QString newSession = sessionInputDialog->value(); if (newSession.isEmpty() || SessionManager::sessions().contains(newSession)) return; beginResetModel(); createSession(newSession); endResetModel(); - if (newSessionInputDialog.isSwitchToRequested()) + if (sessionInputDialog->isSwitchToRequested()) switchToSession(newSession); emit sessionCreated(newSession); } diff --git a/src/plugins/projectexplorer/sessionmodel.h b/src/plugins/projectexplorer/sessionmodel.h index 2b1bacfda5d..92c0f8b6aba 100644 --- a/src/plugins/projectexplorer/sessionmodel.h +++ b/src/plugins/projectexplorer/sessionmodel.h @@ -34,6 +34,8 @@ namespace Internal { const char SESSION_BASE_ID[] = "Welcome.OpenSession"; +class SessionNameInputDialog; + class SessionModel : public QAbstractTableModel { Q_OBJECT @@ -75,7 +77,7 @@ public slots: void switchToSession(const QString &session); private: - void runNewSessionDialog(const QString &suggestedName, std::function createSession); + void runSessionNameInputDialog(ProjectExplorer::Internal::SessionNameInputDialog *sessionInputDialog, std::function createSession); }; } // namespace Internal