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

Method contextMenuExtension

plugins/problemreporter/problemreporterplugin.cpp:249–299  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

247}
248
249KDevelop::ContextMenuExtension ProblemReporterPlugin::contextMenuExtension(KDevelop::Context* context, QWidget* parent)
250{
251 KDevelop::ContextMenuExtension extension;
252
253 auto* editorContext = dynamic_cast<KDevelop::EditorContext*>(context);
254 if (editorContext) {
255 DUChainReadLocker lock(DUChain::lock(), 1000);
256 if (!lock.locked()) {
257 qCDebug(PLUGIN_PROBLEMREPORTER) << "failed to lock duchain in time";
258 return extension;
259 }
260
261 QString title;
262 QList<QAction*> actions;
263
264 TopDUContext* top = DUChainUtils::standardContextForUrl(editorContext->url());
265 if (top) {
266 const auto problems = top->problems();
267 for (auto& problem : problems) {
268 if (problem->range().contains(
269 top->transformToLocalRevision(KTextEditor::Cursor(editorContext->position())))) {
270 KDevelop::IAssistant::Ptr solution = problem->solutionAssistant();
271 if (solution) {
272 title = solution->title();
273 const auto solutionActions = solution->actions();
274 for (auto& action : solutionActions) {
275 actions << action->toQAction(parent);
276 }
277 }
278 }
279 }
280 }
281
282 if (!actions.isEmpty()) {
283 QString text;
284 if (title.isEmpty())
285 text = i18nc("@action:inmenu", "Solve Problem");
286 else {
287 text = i18nc("@action:inmenu", "Solve: %1", KDevelop::htmlToPlainText(title));
288 }
289
290 auto* menu = new QMenu(text, parent);
291 for (QAction* action : std::as_const(actions)) {
292 menu->addAction(action);
293 }
294
295 extension.addAction(ContextMenuExtension::ExtensionGroup, menu->menuAction());
296 }
297 }
298 return extension;
299}
300
301void ProblemReporterPlugin::updateOpenedDocumentsHighlight()
302{

Callers

nothing calls this directly

Calls 15

htmlToPlainTextFunction · 0.85
lockedMethod · 0.80
toQActionMethod · 0.80
CursorClass · 0.50
urlMethod · 0.45
problemsMethod · 0.45
containsMethod · 0.45
rangeMethod · 0.45
positionMethod · 0.45
solutionAssistantMethod · 0.45
titleMethod · 0.45

Tested by

no test coverage detected