| 101 | } |
| 102 | |
| 103 | KDevelop::ContextMenuExtension DockerPlugin::contextMenuExtension(KDevelop::Context* context, QWidget* parent) |
| 104 | { |
| 105 | QList<QUrl> urls; |
| 106 | |
| 107 | if ( context->type() == KDevelop::Context::FileContext ) { |
| 108 | auto* filectx = static_cast<KDevelop::FileContext*>(context); |
| 109 | urls = filectx->urls(); |
| 110 | } else if ( context->type() == KDevelop::Context::ProjectItemContext ) { |
| 111 | auto* projctx = static_cast<KDevelop::ProjectItemContext*>(context); |
| 112 | const auto items = projctx->items(); |
| 113 | for (KDevelop::ProjectBaseItem* item : items) { |
| 114 | if ( item->file() ) { |
| 115 | urls << item->path().toUrl(); |
| 116 | } |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | for(auto it = urls.begin(); it != urls.end(); ) { |
| 121 | if (it->isLocalFile() && it->fileName() == QLatin1String("Dockerfile")) { |
| 122 | ++it; |
| 123 | } else { |
| 124 | it = urls.erase(it); |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | if ( !urls.isEmpty() ) { |
| 129 | KDevelop::ContextMenuExtension ext; |
| 130 | for (const QUrl& url : std::as_const(urls)) { |
| 131 | const KDevelop::Path file(url); |
| 132 | |
| 133 | auto action = new QAction(QIcon::fromTheme(QStringLiteral("text-dockerfile")), i18n("docker build '%1'", file.path()), parent); |
| 134 | connect(action, &QAction::triggered, this, [this, file]() { |
| 135 | const auto dir = file.parent(); |
| 136 | const QString name = QInputDialog::getText( |
| 137 | ICore::self()->uiController()->activeMainWindow(), i18nc("@title:window", "Choose Tag Name"), |
| 138 | i18nc("@label:textbox", "Tag name for '%1':", file.path()), |
| 139 | QLineEdit::Normal, dir.lastPathSegment() |
| 140 | ); |
| 141 | |
| 142 | auto* const process = new DockerBuildJob(this); |
| 143 | process->setExecuteOnHost(true); |
| 144 | *process << QStringList{QStringLiteral("docker"), QStringLiteral("build"), QStringLiteral("--tag"), name, dir.toLocalFile()}; |
| 145 | process->setJobName(i18nc("%1 - Docker tag name", "Docker Build \"%1\"", name)); |
| 146 | connect(process, &KJob::finished, this, [name] (KJob* job) { |
| 147 | if (job->error() != 0) |
| 148 | return; |
| 149 | |
| 150 | ICore::self()->runtimeController()->addRuntimes(new DockerRuntime(name)); |
| 151 | }); |
| 152 | ICore::self()->runController()->registerJob(process); |
| 153 | }); |
| 154 | ext.addAction(KDevelop::ContextMenuExtension::RunGroup, action); |
| 155 | } |
| 156 | |
| 157 | return ext; |
| 158 | } |
| 159 | |
| 160 | return KDevelop::IPlugin::contextMenuExtension(context, parent); |
nothing calls this directly
no test coverage detected