tasks:fix dolphin context menu with plasma 5.25

--update context menu code in order to be relevant with
plasma 5.25
pull/24/head
Michail Vourlakos 3 years ago
parent bef155238a
commit 48a60c6268

@ -97,32 +97,14 @@ PlasmaComponents.ContextMenu {
} }
function loadDynamicLaunchActions(launcherUrl) { function loadDynamicLaunchActions(launcherUrl) {
var sections = []; var sections = [
//From Plasma 5.10 and frameworks 5.34, places are also supported
if (LatteCore.Environment.frameworksVersion >= 336384
&& (typeof backend.placesActions === "function")) {
sections = [
{ {
title: i18n("Places"), title: i18n("Places"),
group: "places", group: "places",
actions: backend.placesActions(launcherUrl, showAllPlaces, menu) actions: backend.placesActions(launcherUrl, showAllPlaces, menu)
}, },
{ {
title: i18n("Recent Documents"), title: i18n("Recent Files"),
group: "recents",
actions: backend.recentDocumentActions(launcherUrl, menu)
},
{
title: i18n("Actions"),
group: "actions",
actions: backend.jumpListActions(launcherUrl, menu)
}
];
} else {
sections = [
{
title: i18n("Recent Documents"),
group: "recents", group: "recents",
actions: backend.recentDocumentActions(launcherUrl, menu) actions: backend.recentDocumentActions(launcherUrl, menu)
}, },
@ -131,8 +113,14 @@ PlasmaComponents.ContextMenu {
group: "actions", group: "actions",
actions: backend.jumpListActions(launcherUrl, menu) actions: backend.jumpListActions(launcherUrl, menu)
} }
]; ]
// C++ can override section heading by returning a QString as first action
sections.forEach((section) => {
if (typeof section.actions[0] === "string") {
section.title = section.actions.shift(); // take first
} }
});
// QMenu does not limit its width automatically. Even if we set a maximumWidth // QMenu does not limit its width automatically. Even if we set a maximumWidth
// it would just cut off text rather than eliding. So we do this manually. // it would just cut off text rather than eliding. So we do this manually.
@ -140,14 +128,19 @@ PlasmaComponents.ContextMenu {
var maximumWidth = theme.mSize(theme.defaultFont).width * 22; var maximumWidth = theme.mSize(theme.defaultFont).width * 22;
sections.forEach(function (section) { sections.forEach(function (section) {
// Always show the "Actions:" header, since we visually merge
// This section with the one beneath it that shows universal actions
if (section["actions"].length > 0 || section["group"] == "actions") { if (section["actions"].length > 0 || section["group"] == "actions") {
// Don't add the "Actions" header if the menu has nothing but actions
// in it, because then it's redundant (all menus have actions)
if (
(section["group"] != "actions") ||
(section["group"] == "actions" && (sections[0]["actions"].length > 0 || sections[1]["actions"].length > 0))
) {
var sectionHeader = newMenuItem(menu); var sectionHeader = newMenuItem(menu);
sectionHeader.text = section["title"]; sectionHeader.text = section["title"];
sectionHeader.section = true; sectionHeader.section = true;
menu.addMenuItem(sectionHeader, startNewInstanceItem); menu.addMenuItem(sectionHeader, startNewInstanceItem);
} }
}
for (var i = 0; i < section["actions"].length; ++i) { for (var i = 0; i < section["actions"].length; ++i) {
var item = newMenuItem(menu); var item = newMenuItem(menu);
@ -165,7 +158,7 @@ PlasmaComponents.ContextMenu {
} }
if (elided) { if (elided) {
item.action.text += "..."; item.action.text += "";
} }
menu.addMenuItem(item, startNewInstanceItem); menu.addMenuItem(item, startNewInstanceItem);

Loading…
Cancel
Save