Commit a09ffde2 authored by Thorbjørn Lindeijer's avatar Thorbjørn Lindeijer
Browse files

Set a parent for the New and Rename Session dialogs

Fixes window manager glitches at least on GNOME.

Reviewed-by: dt
parent 16989185
...@@ -74,23 +74,27 @@ void SessionValidator::fixup(QString &input) const ...@@ -74,23 +74,27 @@ void SessionValidator::fixup(QString &input) const
input = copy; input = copy;
} }
class SessionNameInputDialog : public QDialog class SessionNameInputDialog : public QDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
SessionNameInputDialog(const QStringList& sessions, const QString &initialValue = QString()); SessionNameInputDialog(const QStringList &sessions, QWidget *parent = 0);
void setValue(const QString &value);
QString value() const; QString value() const;
private: private:
QLineEdit *m_newSessionLineEdit; QLineEdit *m_newSessionLineEdit;
}; };
SessionNameInputDialog::SessionNameInputDialog(const QStringList& sessions, const QString &initialValue) SessionNameInputDialog::SessionNameInputDialog(const QStringList &sessions, QWidget *parent)
: QDialog(parent)
{ {
QVBoxLayout *hlayout = new QVBoxLayout(this); QVBoxLayout *hlayout = new QVBoxLayout(this);
QLabel *label = new QLabel(tr("Enter the name of the session:"), this); QLabel *label = new QLabel(tr("Enter the name of the session:"), this);
hlayout->addWidget(label); hlayout->addWidget(label);
m_newSessionLineEdit = new QLineEdit(this); m_newSessionLineEdit = new QLineEdit(this);
m_newSessionLineEdit->setText(initialValue);
m_newSessionLineEdit->setValidator(new SessionValidator(this, sessions)); m_newSessionLineEdit->setValidator(new SessionValidator(this, sessions));
hlayout->addWidget(m_newSessionLineEdit); hlayout->addWidget(m_newSessionLineEdit);
QDialogButtonBox *buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this); QDialogButtonBox *buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this);
...@@ -100,11 +104,17 @@ SessionNameInputDialog::SessionNameInputDialog(const QStringList& sessions, cons ...@@ -100,11 +104,17 @@ SessionNameInputDialog::SessionNameInputDialog(const QStringList& sessions, cons
setLayout(hlayout); setLayout(hlayout);
} }
void SessionNameInputDialog::setValue(const QString &value)
{
m_newSessionLineEdit->setText(value);
}
QString SessionNameInputDialog::value() const QString SessionNameInputDialog::value() const
{ {
return m_newSessionLineEdit->text(); return m_newSessionLineEdit->text();
} }
SessionDialog::SessionDialog(SessionManager *sessionManager) SessionDialog::SessionDialog(SessionManager *sessionManager)
: m_sessionManager(sessionManager) : m_sessionManager(sessionManager)
{ {
...@@ -174,7 +184,7 @@ void SessionDialog::updateActions() ...@@ -174,7 +184,7 @@ void SessionDialog::updateActions()
void SessionDialog::createNew() void SessionDialog::createNew()
{ {
SessionNameInputDialog newSessionInputDialog(m_sessionManager->sessions()); SessionNameInputDialog newSessionInputDialog(m_sessionManager->sessions(), this);
newSessionInputDialog.setWindowTitle(tr("New session name")); newSessionInputDialog.setWindowTitle(tr("New session name"));
if (newSessionInputDialog.exec() == QDialog::Accepted) { if (newSessionInputDialog.exec() == QDialog::Accepted) {
...@@ -192,8 +202,10 @@ void SessionDialog::createNew() ...@@ -192,8 +202,10 @@ void SessionDialog::createNew()
void SessionDialog::clone() void SessionDialog::clone()
{ {
SessionNameInputDialog newSessionInputDialog(m_sessionManager->sessions(), m_ui.sessionList->currentItem()->text()); SessionNameInputDialog newSessionInputDialog(m_sessionManager->sessions(), this);
newSessionInputDialog.setValue(m_ui.sessionList->currentItem()->text());
newSessionInputDialog.setWindowTitle(tr("New session name")); newSessionInputDialog.setWindowTitle(tr("New session name"));
if (newSessionInputDialog.exec() == QDialog::Accepted) { if (newSessionInputDialog.exec() == QDialog::Accepted) {
QString newSession = newSessionInputDialog.value(); QString newSession = newSessionInputDialog.value();
if (m_sessionManager->cloneSession(m_ui.sessionList->currentItem()->text(), newSession)) { if (m_sessionManager->cloneSession(m_ui.sessionList->currentItem()->text(), newSession)) {
...@@ -213,11 +225,12 @@ void SessionDialog::remove() ...@@ -213,11 +225,12 @@ void SessionDialog::remove()
markItems(); markItems();
} }
void SessionDialog::rename() void SessionDialog::rename()
{ {
SessionNameInputDialog newSessionInputDialog(m_sessionManager->sessions(), m_ui.sessionList->currentItem()->text()); SessionNameInputDialog newSessionInputDialog(m_sessionManager->sessions(), this);
newSessionInputDialog.setValue(m_ui.sessionList->currentItem()->text());
newSessionInputDialog.setWindowTitle(tr("Rename session")); newSessionInputDialog.setWindowTitle(tr("Rename session"));
if (newSessionInputDialog.exec() == QDialog::Accepted) { if (newSessionInputDialog.exec() == QDialog::Accepted) {
m_sessionManager->renameSession(m_ui.sessionList->currentItem()->text(), newSessionInputDialog.value()); m_sessionManager->renameSession(m_ui.sessionList->currentItem()->text(), newSessionInputDialog.value());
m_ui.sessionList->clear(); m_ui.sessionList->clear();
...@@ -226,7 +239,6 @@ void SessionDialog::rename() ...@@ -226,7 +239,6 @@ void SessionDialog::rename()
} }
} }
void SessionDialog::switchToSession() void SessionDialog::switchToSession()
{ {
if (m_ui.sessionList->currentItem()) { if (m_ui.sessionList->currentItem()) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment