| 313 | } |
| 314 | |
| 315 | void SessionItemWidgetPrivate::runInputDialog(const QString &title, const QStringList &actList, |
| 316 | const QString &editText, std::function<void(const QString &)> handler) |
| 317 | { |
| 318 | Q_ASSERT(actList.size() == 2); |
| 319 | |
| 320 | DDialog dlg(q); |
| 321 | dlg.setSpacing(10); |
| 322 | dlg.setTitle(title); |
| 323 | dlg.setIcon(QIcon::fromTheme("ide")); |
| 324 | DLineEdit *lineEdit = new DLineEdit(&dlg); |
| 325 | QRegExpValidator *validator = new QRegExpValidator(QRegExp("[^/\?:\\\\*]*"), lineEdit); |
| 326 | lineEdit->lineEdit()->setValidator(validator); |
| 327 | lineEdit->setPlaceholderText(SessionItemWidget::tr("Please input session name")); |
| 328 | lineEdit->setText(editText); |
| 329 | connect(lineEdit, &DLineEdit::textChanged, &dlg, [&dlg](const QString &text) { |
| 330 | dlg.getButton(1)->setEnabled(!text.isEmpty()); |
| 331 | dlg.getButton(2)->setEnabled(!text.isEmpty()); |
| 332 | }); |
| 333 | dlg.addContent(lineEdit); |
| 334 | dlg.setFocusProxy(lineEdit); |
| 335 | |
| 336 | dlg.addButton(SessionItemWidget::tr("Cancel", "button")); |
| 337 | dlg.addButton(actList[0]); |
| 338 | dlg.addButton(actList[1], true, DDialog::ButtonRecommend); |
| 339 | dlg.setOnButtonClickedClose(false); |
| 340 | connect(&dlg, &DDialog::buttonClicked, this, [&](int index) { |
| 341 | if (index == 0) |
| 342 | return dlg.reject(); |
| 343 | |
| 344 | const auto name = lineEdit->text(); |
| 345 | if (sessionSrv->sessionList().contains(name)) { |
| 346 | QString msg = tr("The session already exists, please re-enter."); |
| 347 | lineEdit->showAlertMessage(msg); |
| 348 | return; |
| 349 | } |
| 350 | |
| 351 | handler(name); |
| 352 | if (index == 2) |
| 353 | sessionSrv->loadSession(name); |
| 354 | |
| 355 | dlg.accept(); |
| 356 | }); |
| 357 | |
| 358 | dlg.exec(); |
| 359 | } |
| 360 | |
| 361 | SessionItemWidget::SessionItemWidget(QWidget *parent) |
| 362 | : DFrame(parent), |
nothing calls this directly
no test coverage detected