SessionNameInputDialog: allow to setup title and button

Change-Id: Ifd08f51b12748814b50192e54789d9b036aaaca3
Task-number: QTCREATORBUG-18272
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
Tim Jenssen
2017-05-29 17:46:59 +02:00
parent 89639b0bf3
commit e3a3f52aee
4 changed files with 35 additions and 14 deletions

View File

@@ -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);

View File

@@ -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;
};

View File

@@ -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<void(const QString &)> createSession)
void SessionModel::runSessionNameInputDialog(SessionNameInputDialog *sessionInputDialog, std::function<void(const QString &)> 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);
}

View File

@@ -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<void(const QString &)> createSession);
void runSessionNameInputDialog(ProjectExplorer::Internal::SessionNameInputDialog *sessionInputDialog, std::function<void(const QString &)> createSession);
};
} // namespace Internal