| 164 | } |
| 165 | |
| 166 | QString EnvironmentWidget::askNewProfileName(const QString& defaultName) |
| 167 | { |
| 168 | ScopedDialog<QDialog> dialog(this); |
| 169 | dialog->setWindowTitle(i18nc("@title:window", "Enter Name of New Environment Profile")); |
| 170 | |
| 171 | auto *layout = new QVBoxLayout(dialog); |
| 172 | |
| 173 | auto editLayout = new QHBoxLayout; |
| 174 | |
| 175 | auto label = new QLabel(i18nc("@label:textbox", "Name:")); |
| 176 | editLayout->addWidget(label); |
| 177 | auto edit = new QLineEdit; |
| 178 | editLayout->addWidget(edit); |
| 179 | layout->addLayout(editLayout); |
| 180 | |
| 181 | auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); |
| 182 | auto okButton = buttonBox->button(QDialogButtonBox::Ok); |
| 183 | okButton->setEnabled(false); |
| 184 | okButton->setDefault(true); |
| 185 | dialog->connect(buttonBox, &QDialogButtonBox::accepted, dialog.data(), &QDialog::accept); |
| 186 | dialog->connect(buttonBox, &QDialogButtonBox::rejected, dialog.data(), &QDialog::reject); |
| 187 | layout->addWidget(buttonBox); |
| 188 | |
| 189 | auto validator = new ProfileNameValidator(m_environmentProfileListModel, dialog); |
| 190 | connect(edit, &QLineEdit::textChanged, validator, [validator, okButton](const QString& text) { |
| 191 | int pos; |
| 192 | QString t(text); |
| 193 | const bool isValidProfileName = (validator->validate(t, pos) == QValidator::Acceptable); |
| 194 | okButton->setEnabled(isValidProfileName); |
| 195 | }); |
| 196 | |
| 197 | edit->setText(defaultName); |
| 198 | edit->selectAll(); |
| 199 | |
| 200 | if (dialog->exec() != QDialog::Accepted) { |
| 201 | return {}; |
| 202 | } |
| 203 | |
| 204 | return edit->text(); |
| 205 | } |
| 206 | |
| 207 | void EnvironmentWidget::removeSelectedVariables() |
| 208 | { |