MCPcopy Create free account
hub / github.com/KDE/kdevelop / fillContextMenuExtension

Method fillContextMenuExtension

plugins/compileanalyzercommon/compileanalyzer.cpp:277–327  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

275}
276
277void 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

Callers 2

contextMenuExtensionMethod · 0.80
contextMenuExtensionMethod · 0.80

Calls 15

hasTypeMethod · 0.80
activeDocumentMethod · 0.80
documentControllerMethod · 0.80
findProjectForUrlMethod · 0.80
projectControllerMethod · 0.80
buildSystemManagerMethod · 0.80
isSupportedMimeTypeFunction · 0.70
urlMethod · 0.45
mimeTypeMethod · 0.45
addActionMethod · 0.45
itemsMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected