| 275 | } |
| 276 | |
| 277 | void CompileAnalyzer::fillContextMenuExtension(ContextMenuExtension &extension, |
| 278 | Context* context, QWidget* parent) |
| 279 | { |
| 280 | if (context->hasType(KDevelop::Context::EditorContext) && !isRunning()) { |
| 281 | IDocument* doc = core()->documentController()->activeDocument(); |
| 282 | |
| 283 | auto project = core()->projectController()->findProjectForUrl(doc->url()); |
| 284 | if (!project || !project->buildSystemManager()) { |
| 285 | return; |
| 286 | } |
| 287 | if (isSupportedMimeType(doc->mimeType())) { |
| 288 | auto action = new QAction(m_toolIcon, m_toolName, parent); |
| 289 | connect(action, &QAction::triggered, this, &CompileAnalyzer::runToolOnFile); |
| 290 | extension.addAction(KDevelop::ContextMenuExtension::AnalyzeFileGroup, action); |
| 291 | } |
| 292 | auto action = new QAction(m_toolIcon, m_toolName, parent); |
| 293 | connect(action, &QAction::triggered, this, &CompileAnalyzer::runToolOnAll); |
| 294 | extension.addAction(KDevelop::ContextMenuExtension::AnalyzeProjectGroup, action); |
| 295 | } |
| 296 | |
| 297 | if (context->hasType(KDevelop::Context::ProjectItemContext) && !isRunning()) { |
| 298 | auto projectItemContext = dynamic_cast<KDevelop::ProjectItemContext*>(context); |
| 299 | const auto items = projectItemContext->items(); |
| 300 | if (items.size() != 1) { |
| 301 | return; |
| 302 | } |
| 303 | |
| 304 | const auto item = items.first(); |
| 305 | const auto itemType = item->type(); |
| 306 | if ((itemType != KDevelop::ProjectBaseItem::File) && |
| 307 | (itemType != KDevelop::ProjectBaseItem::Folder) && |
| 308 | (itemType != KDevelop::ProjectBaseItem::BuildFolder)) { |
| 309 | return; |
| 310 | } |
| 311 | if (itemType == KDevelop::ProjectBaseItem::File) { |
| 312 | const QMimeType mimetype = QMimeDatabase().mimeTypeForUrl(item->path().toUrl()); |
| 313 | if (!isSupportedMimeType(mimetype)) { |
| 314 | return; |
| 315 | } |
| 316 | } |
| 317 | if (!item->project()->buildSystemManager()) { |
| 318 | return; |
| 319 | } |
| 320 | |
| 321 | auto action = new QAction(m_toolIcon, m_toolName, parent); |
| 322 | connect(action, &QAction::triggered, this, [this, item]() { |
| 323 | runTool(item->path().toUrl()); |
| 324 | }); |
| 325 | extension.addAction(KDevelop::ContextMenuExtension::AnalyzeProjectGroup, action); |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | } |
| 330 |
no test coverage detected