| 1027 | } |
| 1028 | |
| 1029 | ContextMenuExtension RunController::contextMenuExtension(Context* ctx, QWidget* parent) |
| 1030 | { |
| 1031 | Q_D(RunController); |
| 1032 | |
| 1033 | d->launchAsInfo.clear(); |
| 1034 | d->contextItem = nullptr; |
| 1035 | ContextMenuExtension ext; |
| 1036 | if( ctx->type() == Context::ProjectItemContext ) { |
| 1037 | auto* prjctx = static_cast<KDevelop::ProjectItemContext*>(ctx); |
| 1038 | if( prjctx->items().count() == 1 ) |
| 1039 | { |
| 1040 | ProjectBaseItem* itm = prjctx->items().at( 0 ); |
| 1041 | int i = 0; |
| 1042 | for (ILaunchMode* mode : std::as_const(d->launchModes)) { |
| 1043 | auto* menu = new KActionMenu(i18nc("@title:menu", "%1 As...", mode->name() ), parent); |
| 1044 | const auto types = launchConfigurationTypes(); |
| 1045 | for (LaunchConfigurationType* type : types) { |
| 1046 | bool hasLauncher = false; |
| 1047 | const auto launchers = type->launchers(); |
| 1048 | for (ILauncher* launcher : launchers) { |
| 1049 | if( launcher->supportedModes().contains( mode->id() ) ) |
| 1050 | { |
| 1051 | hasLauncher = true; |
| 1052 | } |
| 1053 | } |
| 1054 | if( hasLauncher && type->canLaunch(itm) ) |
| 1055 | { |
| 1056 | d->launchAsInfo[i] = qMakePair( type->id(), mode->id() ); |
| 1057 | auto* act = new QAction(menu); |
| 1058 | act->setText( type->name() ); |
| 1059 | qCDebug(SHELL) << "Connect " << i << "for action" << act->text() << "in mode" << mode->name(); |
| 1060 | connect(act, &QAction::triggered, |
| 1061 | this, [this, i] () { Q_D(RunController); d->launchAs(i); } ); |
| 1062 | menu->addAction(act); |
| 1063 | i++; |
| 1064 | } |
| 1065 | } |
| 1066 | if( menu->menu()->actions().count() > 0 ) |
| 1067 | { |
| 1068 | ext.addAction( ContextMenuExtension::RunGroup, menu); |
| 1069 | } else { |
| 1070 | delete menu; |
| 1071 | } |
| 1072 | } |
| 1073 | if( ext.actions( ContextMenuExtension::RunGroup ).count() > 0 ) |
| 1074 | { |
| 1075 | d->contextItem = itm; |
| 1076 | } |
| 1077 | } |
| 1078 | } |
| 1079 | return ext; |
| 1080 | } |
| 1081 | |
| 1082 | |
| 1083 |
no test coverage detected