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

Method launcherSuggestions

plugins/execute/nativeappconfig.cpp:336–395  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

334}
335
336QMenu* NativeAppConfigType::launcherSuggestions()
337{
338 auto* ret = new QMenu(i18nc("@title:menu", "Project Executables"));
339
340 KDevelop::ProjectModel* model = KDevelop::ICore::self()->projectController()->projectModel();
341 const QList<KDevelop::IProject*> projects = KDevelop::ICore::self()->projectController()->projects();
342
343 for (KDevelop::IProject* project : projects) {
344 if(project->projectFileManager()->features() & KDevelop::IProjectFileManager::Targets) {
345 const QList<KDevelop::ProjectTargetItem*> targets = targetsInFolder(project->projectItem());
346 QHash<KDevelop::ProjectBaseItem*, QList<QAction*> > targetsContainer;
347 QMenu* projectMenu = ret->addMenu(QIcon::fromTheme(QStringLiteral("project-development")), project->name());
348 for (KDevelop::ProjectTargetItem* target : targets) {
349 if(target->executable()) {
350 QStringList path = model->pathFromIndex(target->index());
351 if(!path.isEmpty()){
352 auto* act = new QAction(projectMenu);
353 act->setData(KDevelop::joinWithEscaping(path, QLatin1Char('/'), QLatin1Char('\\')));
354 act->setProperty("name", target->text());
355 path.removeFirst();
356 act->setText(path.join(QLatin1Char('/')));
357 act->setIcon(QIcon::fromTheme(QStringLiteral("system-run")));
358 connect(act, &QAction::triggered, this, &NativeAppConfigType::suggestionTriggered);
359 targetsContainer[target->parent()].append(act);
360 }
361 }
362 }
363
364 QList<QAction*> separateActions;
365 QList<QMenu*> submenus;
366 for (auto it = targetsContainer.constBegin(), end = targetsContainer.constEnd(); it != end; ++it) {
367 KDevelop::ProjectBaseItem* folder = it.key();
368 QList<QAction*> actions = it.value();
369 if(actions.size()==1 || !folder->parent()) {
370 separateActions.append(actions);
371 } else {
372 for (QAction* a : std::as_const(actions)) {
373 a->setText(a->property("name").toString());
374 }
375 QStringList path = model->pathFromIndex(folder->index());
376 path.removeFirst();
377 auto* submenu = new QMenu(path.join(QLatin1Char('/')), projectMenu);
378 std::sort(actions.begin(), actions.end(), actionLess);
379 submenu->addActions(actions);
380 submenus += submenu;
381 }
382 }
383 std::sort(separateActions.begin(), separateActions.end(), actionLess);
384 std::sort(submenus.begin(), submenus.end(), menuLess);
385 for (QMenu* m : std::as_const(submenus)) {
386 projectMenu->addMenu(m);
387 }
388 projectMenu->addActions(separateActions);
389
390 projectMenu->setEnabled(!projectMenu->isEmpty());
391 }
392 }
393

Callers 1

Calls 15

joinWithEscapingFunction · 0.85
sortFunction · 0.85
projectControllerMethod · 0.80
projectsMethod · 0.80
projectFileManagerMethod · 0.80
setPropertyMethod · 0.80
joinMethod · 0.80
setIconMethod · 0.80
constBeginMethod · 0.80
constEndMethod · 0.80
propertyMethod · 0.80
targetsInFolderFunction · 0.70

Tested by

no test coverage detected