| 575 | } |
| 576 | |
| 577 | KDevelop::ContextMenuExtension PatchReviewPlugin::contextMenuExtension(KDevelop::Context* context, QWidget* parent) |
| 578 | { |
| 579 | QList<QUrl> urls; |
| 580 | |
| 581 | if ( context->type() == KDevelop::Context::FileContext ) { |
| 582 | auto* filectx = static_cast<KDevelop::FileContext*>(context); |
| 583 | urls = filectx->urls(); |
| 584 | } else if ( context->type() == KDevelop::Context::ProjectItemContext ) { |
| 585 | auto* projctx = static_cast<KDevelop::ProjectItemContext*>(context); |
| 586 | const auto items = projctx->items(); |
| 587 | for (KDevelop::ProjectBaseItem* item : items) { |
| 588 | if ( item->file() ) { |
| 589 | urls << item->file()->path().toUrl(); |
| 590 | } |
| 591 | } |
| 592 | } else if ( context->type() == KDevelop::Context::EditorContext ) { |
| 593 | auto* econtext = static_cast<KDevelop::EditorContext*>(context); |
| 594 | urls << econtext->url(); |
| 595 | |
| 596 | if (urls.constFirst().isEmpty()) { |
| 597 | // This must be an Untitled document. The Review Patch action makes no sense for an unsaved document, |
| 598 | // and triggering it causes an assertion failure in DocumentControllerPrivate::openDocumentInternal(). |
| 599 | // Do not add our context menu item to prevent this. |
| 600 | urls.clear(); |
| 601 | } |
| 602 | } |
| 603 | |
| 604 | if (urls.size() == 1) { |
| 605 | auto* reviewAction = new QAction(QIcon::fromTheme(QStringLiteral("text-x-patch")), |
| 606 | i18nc("@action:inmenu", "Review Patch"), parent); |
| 607 | reviewAction->setData(QVariant(urls[0])); |
| 608 | connect( reviewAction, &QAction::triggered, this, &PatchReviewPlugin::executeFileReviewAction ); |
| 609 | ContextMenuExtension cm; |
| 610 | cm.addAction( KDevelop::ContextMenuExtension::VcsGroup, reviewAction ); |
| 611 | return cm; |
| 612 | } |
| 613 | |
| 614 | return KDevelop::IPlugin::contextMenuExtension(context, parent); |
| 615 | } |
| 616 | |
| 617 | void PatchReviewPlugin::executeFileReviewAction() |
| 618 | { |