forked from qt-creator/qt-creator
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:
@@ -88,8 +88,9 @@ SessionNameInputDialog::SessionNameInputDialog(QWidget *parent)
|
|||||||
m_newSessionLineEdit->setValidator(new SessionValidator(this, SessionManager::sessions()));
|
m_newSessionLineEdit->setValidator(new SessionValidator(this, SessionManager::sessions()));
|
||||||
hlayout->addWidget(m_newSessionLineEdit);
|
hlayout->addWidget(m_newSessionLineEdit);
|
||||||
auto buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this);
|
auto buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this);
|
||||||
buttons->button(QDialogButtonBox::Ok)->setText(tr("&Create"));
|
m_okButton = buttons->button(QDialogButtonBox::Ok);
|
||||||
m_switchToButton = buttons->addButton(tr("Create and &Open"), QDialogButtonBox::AcceptRole);
|
m_switchToButton = new QPushButton;
|
||||||
|
buttons->addButton(m_switchToButton, QDialogButtonBox::AcceptRole);
|
||||||
connect(m_switchToButton, &QPushButton::clicked, [this]() {
|
connect(m_switchToButton, &QPushButton::clicked, [this]() {
|
||||||
m_usedSwitchTo = true;
|
m_usedSwitchTo = true;
|
||||||
});
|
});
|
||||||
@@ -99,6 +100,12 @@ SessionNameInputDialog::SessionNameInputDialog(QWidget *parent)
|
|||||||
setLayout(hlayout);
|
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)
|
void SessionNameInputDialog::setValue(const QString &value)
|
||||||
{
|
{
|
||||||
m_newSessionLineEdit->setText(value);
|
m_newSessionLineEdit->setText(value);
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ class SessionNameInputDialog : public QDialog
|
|||||||
public:
|
public:
|
||||||
explicit SessionNameInputDialog(QWidget *parent = nullptr);
|
explicit SessionNameInputDialog(QWidget *parent = nullptr);
|
||||||
|
|
||||||
|
void setActionText(const QString &actionText, const QString &openActionText);
|
||||||
void setValue(const QString &value);
|
void setValue(const QString &value);
|
||||||
QString value() const;
|
QString value() const;
|
||||||
bool isSwitchToRequested() const;
|
bool isSwitchToRequested() const;
|
||||||
@@ -68,6 +69,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
QLineEdit *m_newSessionLineEdit = nullptr;
|
QLineEdit *m_newSessionLineEdit = nullptr;
|
||||||
QPushButton *m_switchToButton = nullptr;
|
QPushButton *m_switchToButton = nullptr;
|
||||||
|
QPushButton *m_okButton = nullptr;
|
||||||
bool m_usedSwitchTo = false;
|
bool m_usedSwitchTo = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -188,14 +188,23 @@ void SessionModel::resetSessions()
|
|||||||
|
|
||||||
void SessionModel::newSession()
|
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);
|
SessionManager::createSession(newName);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void SessionModel::cloneSession(const QString &session)
|
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);
|
SessionManager::cloneSession(session, newName);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -211,7 +220,12 @@ void SessionModel::deleteSession(const QString &session)
|
|||||||
|
|
||||||
void SessionModel::renameSession(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);
|
SessionManager::renameSession(session, newName);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -222,21 +236,17 @@ void SessionModel::switchToSession(const QString &session)
|
|||||||
emit sessionSwitched();
|
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;
|
if (sessionInputDialog->exec() == QDialog::Accepted) {
|
||||||
newSessionInputDialog.setWindowTitle(tr("New Session Name"));
|
QString newSession = sessionInputDialog->value();
|
||||||
newSessionInputDialog.setValue(suggestedName);
|
|
||||||
|
|
||||||
if (newSessionInputDialog.exec() == QDialog::Accepted) {
|
|
||||||
QString newSession = newSessionInputDialog.value();
|
|
||||||
if (newSession.isEmpty() || SessionManager::sessions().contains(newSession))
|
if (newSession.isEmpty() || SessionManager::sessions().contains(newSession))
|
||||||
return;
|
return;
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
createSession(newSession);
|
createSession(newSession);
|
||||||
endResetModel();
|
endResetModel();
|
||||||
|
|
||||||
if (newSessionInputDialog.isSwitchToRequested())
|
if (sessionInputDialog->isSwitchToRequested())
|
||||||
switchToSession(newSession);
|
switchToSession(newSession);
|
||||||
emit sessionCreated(newSession);
|
emit sessionCreated(newSession);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,6 +34,8 @@ namespace Internal {
|
|||||||
|
|
||||||
const char SESSION_BASE_ID[] = "Welcome.OpenSession";
|
const char SESSION_BASE_ID[] = "Welcome.OpenSession";
|
||||||
|
|
||||||
|
class SessionNameInputDialog;
|
||||||
|
|
||||||
class SessionModel : public QAbstractTableModel
|
class SessionModel : public QAbstractTableModel
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -75,7 +77,7 @@ public slots:
|
|||||||
void switchToSession(const QString &session);
|
void switchToSession(const QString &session);
|
||||||
|
|
||||||
private:
|
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
|
} // namespace Internal
|
||||||
|
|||||||
Reference in New Issue
Block a user