| 490 | } |
| 491 | |
| 492 | void UiController::selectNewToolViewToAdd(MainWindow *mw) |
| 493 | { |
| 494 | Q_D(UiController); |
| 495 | |
| 496 | if (!mw || !mw->area()) |
| 497 | return; |
| 498 | |
| 499 | ScopedDialog<QDialog> dia(mw); |
| 500 | dia->setWindowTitle(i18nc("@title:window", "Select Tool View to Add")); |
| 501 | |
| 502 | auto mainLayout = new QVBoxLayout(dia); |
| 503 | |
| 504 | auto *list = new NewToolViewListWidget(mw, dia); |
| 505 | |
| 506 | list->setSelectionMode(QAbstractItemView::ExtendedSelection); |
| 507 | list->setSortingEnabled(true); |
| 508 | for (QHash<IToolViewFactory*, Sublime::ToolDocument*>::const_iterator it = d->factoryDocuments.constBegin(); |
| 509 | it != d->factoryDocuments.constEnd(); ++it) |
| 510 | { |
| 511 | auto* item = new ViewSelectorItem(it.value()->title(), it.key(), list); |
| 512 | if (toolViewPresent(it.value(), mw->area())) { |
| 513 | // Disable item if the tool view is already present. |
| 514 | item->setFlags(item->flags() & ~Qt::ItemIsEnabled); |
| 515 | } |
| 516 | list->addItem(item); |
| 517 | } |
| 518 | |
| 519 | list->setFocus(); |
| 520 | connect(list, &NewToolViewListWidget::addNewToolView, this, &UiController::addNewToolView); |
| 521 | mainLayout->addWidget(list); |
| 522 | |
| 523 | auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel); |
| 524 | auto okButton = buttonBox->button(QDialogButtonBox::Ok); |
| 525 | okButton->setDefault(true); |
| 526 | okButton->setShortcut(Qt::CTRL | Qt::Key_Return); |
| 527 | dia->connect(buttonBox, &QDialogButtonBox::accepted, dia.data(), &QDialog::accept); |
| 528 | dia->connect(buttonBox, &QDialogButtonBox::rejected, dia.data(), &QDialog::reject); |
| 529 | mainLayout->addWidget(buttonBox); |
| 530 | |
| 531 | if (dia->exec() == QDialog::Accepted) |
| 532 | { |
| 533 | const auto items = list->selectedItems(); |
| 534 | for (QListWidgetItem* item : items) { |
| 535 | addNewToolView(mw, item); |
| 536 | } |
| 537 | } |
| 538 | } |
| 539 | |
| 540 | void UiController::addNewToolView(MainWindow *mw, QListWidgetItem* item) |
| 541 | { |
no test coverage detected