| 178 | } |
| 179 | |
| 180 | KDevelop::ContextMenuExtension ExternalScriptPlugin::contextMenuExtension(KDevelop::Context* context, QWidget* parent) |
| 181 | { |
| 182 | m_urls.clear(); |
| 183 | |
| 184 | int folderCount = 0; |
| 185 | |
| 186 | if (context->type() == KDevelop::Context::FileContext) { |
| 187 | auto* filectx = static_cast<KDevelop::FileContext*>(context); |
| 188 | m_urls = filectx->urls(); |
| 189 | } else if (context->type() == KDevelop::Context::ProjectItemContext) { |
| 190 | auto* projctx = static_cast<KDevelop::ProjectItemContext*>(context); |
| 191 | const auto items = projctx->items(); |
| 192 | for (KDevelop::ProjectBaseItem* item : items) { |
| 193 | if (item->file()) { |
| 194 | m_urls << item->file()->path().toUrl(); |
| 195 | } else if (item->folder()) { |
| 196 | m_urls << item->folder()->path().toUrl(); |
| 197 | folderCount++; |
| 198 | } |
| 199 | } |
| 200 | } else if (context->type() == KDevelop::Context::EditorContext) { |
| 201 | auto* econtext = static_cast<KDevelop::EditorContext*>(context); |
| 202 | m_urls << econtext->url(); |
| 203 | } |
| 204 | |
| 205 | if (!m_urls.isEmpty()) { |
| 206 | KDevelop::ContextMenuExtension ext; |
| 207 | QMenu* menu = nullptr; |
| 208 | |
| 209 | for (int row = 0; row < m_model->rowCount(); ++row) { |
| 210 | auto* item = dynamic_cast<ExternalScriptItem*>(m_model->item(row)); |
| 211 | Q_ASSERT(item); |
| 212 | |
| 213 | if (context->type() != KDevelop::Context::EditorContext) { |
| 214 | // filter scripts that depend on an opened document |
| 215 | // if the context menu was not requested inside the editor |
| 216 | if (item->performParameterReplacement() && item->command().contains(QLatin1String("%s"))) { |
| 217 | continue; |
| 218 | } else if (item->inputMode() == ExternalScriptItem::InputSelectionOrNone) { |
| 219 | continue; |
| 220 | } |
| 221 | } |
| 222 | |
| 223 | if (folderCount == m_urls.count()) { |
| 224 | // when only folders filter items that don't have %d parameter (or another parameter) |
| 225 | if (item->performParameterReplacement() && |
| 226 | (!item->command().contains(QLatin1String("%d")) || |
| 227 | item->command().contains(QLatin1String("%s")) || |
| 228 | item->command().contains(QLatin1String("%u")) || |
| 229 | item->command().contains(QLatin1String("%f")) || |
| 230 | item->command().contains(QLatin1String("%b")) || |
| 231 | item->command().contains(QLatin1String("%n")) |
| 232 | ) |
| 233 | ) { |
| 234 | continue; |
| 235 | } |
| 236 | } |
| 237 |
nothing calls this directly
no test coverage detected