| 186 | } |
| 187 | |
| 188 | KDevelop::ContextMenuExtension OpenWithPlugin::contextMenuExtension(KDevelop::Context* context, QWidget* parent) |
| 189 | { |
| 190 | // do not recurse |
| 191 | if (context->hasType(KDevelop::Context::OpenWithContext)) { |
| 192 | return ContextMenuExtension(); |
| 193 | } |
| 194 | |
| 195 | m_urls.clear(); |
| 196 | |
| 197 | auto* filectx = dynamic_cast<FileContext*>( context ); |
| 198 | auto* projctx = dynamic_cast<ProjectItemContext*>( context ); |
| 199 | if ( filectx && filectx->urls().count() > 0 ) { |
| 200 | m_urls = filectx->urls(); |
| 201 | } else if ( projctx && projctx->items().count() > 0 ) { |
| 202 | // For now, let's handle *either* files only *or* directories only |
| 203 | const auto items = projctx->items(); |
| 204 | const int wantedType = items.at(0)->type(); |
| 205 | for (ProjectBaseItem* item : items) { |
| 206 | if (wantedType == ProjectBaseItem::File && item->file()) { |
| 207 | m_urls << item->file()->path().toUrl(); |
| 208 | } else if ((wantedType == ProjectBaseItem::Folder || wantedType == ProjectBaseItem::BuildFolder) && item->folder()) { |
| 209 | m_urls << item->folder()->path().toUrl(); |
| 210 | } |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | if (m_urls.isEmpty()) { |
| 215 | return KDevelop::ContextMenuExtension(); |
| 216 | } |
| 217 | |
| 218 | auto mimetype = updateMimeTypeForUrls(); |
| 219 | |
| 220 | auto partActions = actionsForParts(parent); |
| 221 | auto appActions = actionsForApplications(parent); |
| 222 | |
| 223 | OpenWithContext subContext(m_urls, mimetype); |
| 224 | const QList<ContextMenuExtension> extensions = ICore::self()->pluginController()->queryPluginsForContextMenuExtensions( &subContext, parent); |
| 225 | for (const ContextMenuExtension& ext : extensions) { |
| 226 | appActions += ext.actions(ContextMenuExtension::OpenExternalGroup); |
| 227 | partActions += ext.actions(ContextMenuExtension::OpenEmbeddedGroup); |
| 228 | } |
| 229 | |
| 230 | { |
| 231 | auto other = new QAction(i18nc("@item:menu", "Other..."), parent); |
| 232 | connect(other, &QAction::triggered, this, [this] { |
| 233 | auto dialog = new KOpenWithDialog(m_urls, ICore::self()->uiController()->activeMainWindow()); |
| 234 | if (dialog->exec() == QDialog::Accepted && dialog->service()) { |
| 235 | openApplication(dialog->service()); |
| 236 | } |
| 237 | }); |
| 238 | appActions << other; |
| 239 | } |
| 240 | |
| 241 | // Now setup a menu with actions for each part and app |
| 242 | auto* menu = new QMenu(i18nc("@title:menu", "Open With"), parent); |
| 243 | auto documentOpenIcon = QIcon::fromTheme( QStringLiteral("document-open") ); |
| 244 | menu->setIcon( documentOpenIcon ); |
| 245 |
nothing calls this directly
no test coverage detected