Changeset View
Changeset View
Standalone View
Standalone View
applets/taskmanager/package/contents/ui/ContextMenu.qml
Show All 21 Lines | |||||
22 | 22 | | |||
23 | import org.kde.plasma.plasmoid 2.0 | 23 | import org.kde.plasma.plasmoid 2.0 | ||
24 | 24 | | |||
25 | import org.kde.plasma.core 2.0 as PlasmaCore | 25 | import org.kde.plasma.core 2.0 as PlasmaCore | ||
26 | import org.kde.plasma.components 2.0 as PlasmaComponents | 26 | import org.kde.plasma.components 2.0 as PlasmaComponents | ||
27 | 27 | | |||
28 | import org.kde.taskmanager 0.1 as TaskManager | 28 | import org.kde.taskmanager 0.1 as TaskManager | ||
29 | 29 | | |||
30 | import "../code/layout.js" as LayoutManager | ||||
31 | | ||||
30 | PlasmaComponents.ContextMenu { | 32 | PlasmaComponents.ContextMenu { | ||
31 | id: menu | 33 | id: menu | ||
32 | 34 | | |||
33 | property QtObject backend | 35 | property QtObject backend | ||
34 | property QtObject mpris2Source | 36 | property QtObject mpris2Source | ||
35 | property var modelIndex | 37 | property var modelIndex | ||
36 | readonly property var atm: TaskManager.AbstractTasksModel | 38 | readonly property var atm: TaskManager.AbstractTasksModel | ||
37 | 39 | | |||
▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Line(s) | |||||
94 | 96 | | |||
95 | function loadDynamicLaunchActions(launcherUrl) { | 97 | function loadDynamicLaunchActions(launcherUrl) { | ||
96 | var lists = [ | 98 | var lists = [ | ||
97 | backend.jumpListActions(launcherUrl, menu), | 99 | backend.jumpListActions(launcherUrl, menu), | ||
98 | backend.placesActions(launcherUrl, showAllPlaces, menu), | 100 | backend.placesActions(launcherUrl, showAllPlaces, menu), | ||
99 | backend.recentDocumentActions(launcherUrl, menu) | 101 | backend.recentDocumentActions(launcherUrl, menu) | ||
100 | ] | 102 | ] | ||
101 | 103 | | |||
104 | // QMenu does not limit its width automatically. Even if we set a maximumWidth | ||||
105 | // it would just cut off text rather than eliding. So we do this manually. | ||||
106 | var textMetrics = Qt.createQmlObject("import QtQuick 2.4; TextMetrics {}", menu); | ||||
107 | var maximumWidth = LayoutManager.maximumContextMenuTextWidth(); | ||||
108 | | ||||
102 | lists.forEach(function (list) { | 109 | lists.forEach(function (list) { | ||
103 | for (var i = 0; i < list.length; ++i) { | 110 | for (var i = 0; i < list.length; ++i) { | ||
104 | var item = newMenuItem(menu); | 111 | var item = newMenuItem(menu); | ||
105 | item.action = list[i]; | 112 | item.action = list[i]; | ||
113 | | ||||
114 | // Crude way of manually eliding... | ||||
115 | var elided = false; | ||||
116 | textMetrics.text = Qt.binding(function() { | ||||
117 | return item.action.text; | ||||
118 | }); | ||||
119 | | ||||
120 | while (textMetrics.width > maximumWidth) { | ||||
121 | item.action.text = item.action.text.slice(0, -1); | ||||
122 | elided = true; | ||||
123 | } | ||||
124 | | ||||
125 | if (elided) { | ||||
126 | item.action.text += "..."; | ||||
hein: We can't hard-code "...". Different locales use different characters for text elision (e.g. an… | |||||
127 | } | ||||
128 | | ||||
106 | menu.addMenuItem(item, virtualDesktopsMenuItem); | 129 | menu.addMenuItem(item, virtualDesktopsMenuItem); | ||
107 | } | 130 | } | ||
108 | 131 | | |||
109 | if (list.length > 0) { | 132 | if (list.length > 0) { | ||
110 | menu.addMenuItem(newSeparator(menu), virtualDesktopsMenuItem); | 133 | menu.addMenuItem(newSeparator(menu), virtualDesktopsMenuItem); | ||
111 | } | 134 | } | ||
112 | }); | 135 | }); | ||
113 | 136 | | |||
▲ Show 20 Lines • Show All 555 Lines • Show Last 20 Lines |
We can't hard-code "...". Different locales use different characters for text elision (e.g. an actual ellipsis, not three dots).