| 196 | } |
| 197 | |
| 198 | KDevelop::ContextMenuExtension FlatpakPlugin::contextMenuExtension(KDevelop::Context* context, QWidget* parent) |
| 199 | { |
| 200 | QList<QUrl> urls; |
| 201 | |
| 202 | if ( context->type() == KDevelop::Context::FileContext ) { |
| 203 | auto* filectx = static_cast<KDevelop::FileContext*>(context); |
| 204 | urls = filectx->urls(); |
| 205 | } else if ( context->type() == KDevelop::Context::ProjectItemContext ) { |
| 206 | auto* projctx = static_cast<KDevelop::ProjectItemContext*>(context); |
| 207 | const auto items = projctx->items(); |
| 208 | for (KDevelop::ProjectBaseItem* item : items) { |
| 209 | if ( item->file() ) { |
| 210 | urls << item->file()->path().toUrl(); |
| 211 | } |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | const QRegularExpression nameRx(QStringLiteral(".*\\..*\\..*\\.json$")); |
| 216 | for(auto it = urls.begin(); it != urls.end(); ) { |
| 217 | if (it->isLocalFile() && (it->path().contains(nameRx) || it->fileName() == kdeFlatpakManifestFileName)) { |
| 218 | ++it; |
| 219 | } else { |
| 220 | it = urls.erase(it); |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | if ( !urls.isEmpty() ) { |
| 225 | KDevelop::ContextMenuExtension ext; |
| 226 | for (const QUrl& url : std::as_const(urls)) { |
| 227 | const KDevelop::Path file(url); |
| 228 | const auto doc = FlatpakRuntime::config(file); |
| 229 | const auto arches = availableArches(doc); |
| 230 | for (const QString& arch : arches) { |
| 231 | if (const auto it = std::find_if(m_runtimes.cbegin(), m_runtimes.cend(), |
| 232 | [&arch, &file](const FlatpakRuntime* runtime) { |
| 233 | return runtime->arch() == arch && runtime->file() == file; |
| 234 | }); |
| 235 | it != m_runtimes.cend()) { |
| 236 | auto action = |
| 237 | new QAction(i18nc("@action:inmenu", "Rebuild Flatpak Environment: %1", (*it)->name()), parent); |
| 238 | connect(action, &QAction::triggered, this, [it]() { |
| 239 | ICore::self()->runController()->registerJob((*it)->rebuild()); |
| 240 | }); |
| 241 | ext.addAction(KDevelop::ContextMenuExtension::RunGroup, action); |
| 242 | } else { |
| 243 | auto action = new QAction( |
| 244 | i18nc("@action:inmenu", "Build Flatpak Environment %1 for %2", doc[u"id"].toString(), arch), |
| 245 | parent); |
| 246 | connect(action, &QAction::triggered, this, [this, file, arch]() { |
| 247 | createRuntime(file, arch); |
| 248 | }); |
| 249 | ext.addAction(KDevelop::ContextMenuExtension::RunGroup, action); |
| 250 | } |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | return ext; |
| 255 | } |
nothing calls this directly
no test coverage detected