| 266 | } |
| 267 | |
| 268 | QList<QAction*> OpenWithPlugin::actionsForParts(QWidget* parent) |
| 269 | { |
| 270 | if (isDirectory(m_mimeType)) { |
| 271 | // Don't return any parts for directories, KDevelop can only open files, not folders, thus |
| 272 | // we wouldn't ever actually do anything with the parts shown to the user here. |
| 273 | // Note that we can open a folder in an external application just fine though. |
| 274 | return {}; |
| 275 | } |
| 276 | |
| 277 | const auto parts = KParts::PartLoader::partsForMimeType(m_mimeType); |
| 278 | QList<QAction*> actions; |
| 279 | actions.reserve(parts.size()); |
| 280 | |
| 281 | int textEditorActionPos = -1; |
| 282 | for (const auto& part : parts) { |
| 283 | const auto pluginId = part.pluginId(); |
| 284 | const auto isTextEditor = isTextPart(pluginId); |
| 285 | |
| 286 | if (isTextEditor) { |
| 287 | textEditorActionPos = actions.size(); |
| 288 | } |
| 289 | |
| 290 | const bool isDefault = |
| 291 | m_defaultOpener.isValid() ? FileOpener::fromPartId(pluginId) == m_defaultOpener : isTextEditor; |
| 292 | auto* action = createAction(isTextEditor ? i18nc("@item:inmenu", "Default Editor") : part.name(), |
| 293 | part.iconName(), parent, isDefault); |
| 294 | connect(action, &QAction::triggered, this, [this, action, pluginId]() { |
| 295 | openPart(pluginId, action->text()); |
| 296 | }); |
| 297 | actions << action; |
| 298 | } |
| 299 | |
| 300 | // partsForMimeType has the preferred part at the first position, let's keep it there |
| 301 | int sortOffset = 1; |
| 302 | if (textEditorActionPos > 0) { |
| 303 | // move the text editor action up front |
| 304 | actions.move(textEditorActionPos, 0); |
| 305 | // keep the user-preferred mime at the 2nd pos |
| 306 | sortOffset++; |
| 307 | } |
| 308 | |
| 309 | return sortedActions(std::move(actions), sortOffset); |
| 310 | } |
| 311 | |
| 312 | QList<QAction*> OpenWithPlugin::actionsForApplications(QWidget* parent) |
| 313 | { |
nothing calls this directly
no test coverage detected