MCPcopy Create free account
hub / github.com/KDE/kdevelop / actionsForParts

Method actionsForParts

plugins/openwith/openwithplugin.cpp:268–310  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

266}
267
268QList<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
312QList<QAction*> OpenWithPlugin::actionsForApplications(QWidget* parent)
313{

Callers

nothing calls this directly

Calls 12

isDirectoryFunction · 0.85
isTextPartFunction · 0.85
createActionFunction · 0.85
sortedActionsFunction · 0.85
pluginIdMethod · 0.80
reserveMethod · 0.45
sizeMethod · 0.45
isValidMethod · 0.45
nameMethod · 0.45
iconNameMethod · 0.45
textMethod · 0.45
moveMethod · 0.45

Tested by

no test coverage detected