Changeset View
Changeset View
Standalone View
Standalone View
applets/taskmanager/package/contents/ui/ContextMenu.qml
Show All 24 Lines | |||||
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 | PlasmaComponents.ContextMenu { | 30 | PlasmaComponents.ContextMenu { | ||
31 | id: menu | 31 | id: menu | ||
32 | 32 | | |||
33 | property QtObject backend | ||||
33 | property QtObject mpris2Source | 34 | property QtObject mpris2Source | ||
34 | property var modelIndex | 35 | property var modelIndex | ||
35 | readonly property var atm: TaskManager.AbstractTasksModel | 36 | readonly property var atm: TaskManager.AbstractTasksModel | ||
36 | 37 | | |||
38 | property bool showAllPlaces: false | ||||
hein: Maybe a dated C++ mindset, but I don't like having no initial value :/ | |||||
39 | | ||||
37 | placement: { | 40 | placement: { | ||
38 | if (plasmoid.location == PlasmaCore.Types.LeftEdge) { | 41 | if (plasmoid.location == PlasmaCore.Types.LeftEdge) { | ||
39 | return PlasmaCore.Types.RightPosedTopAlignedPopup; | 42 | return PlasmaCore.Types.RightPosedTopAlignedPopup; | ||
40 | } else if (plasmoid.location == PlasmaCore.Types.TopEdge) { | 43 | } else if (plasmoid.location == PlasmaCore.Types.TopEdge) { | ||
41 | return PlasmaCore.Types.BottomPosedLeftAlignedPopup; | 44 | return PlasmaCore.Types.BottomPosedLeftAlignedPopup; | ||
42 | } else { | 45 | } else { | ||
43 | return PlasmaCore.Types.TopPosedLeftAlignedPopup; | 46 | return PlasmaCore.Types.TopPosedLeftAlignedPopup; | ||
44 | } | 47 | } | ||
45 | } | 48 | } | ||
46 | 49 | | |||
47 | minimumWidth: visualParent.width | 50 | minimumWidth: visualParent.width | ||
48 | 51 | | |||
49 | onStatusChanged: { | 52 | onStatusChanged: { | ||
50 | if (visualParent && get(atm.LauncherUrlWithoutIcon) != null && status == PlasmaComponents.DialogStatus.Open) { | 53 | if (visualParent && get(atm.LauncherUrlWithoutIcon) != null && status == PlasmaComponents.DialogStatus.Open) { | ||
51 | launcherToggleAction.checked = (tasksModel.launcherPosition(get(atm.LauncherUrlWithoutIcon)) != -1); | 54 | launcherToggleAction.checked = (tasksModel.launcherPosition(get(atm.LauncherUrlWithoutIcon)) != -1); | ||
52 | activitiesDesktopsMenu.refresh(); | 55 | activitiesDesktopsMenu.refresh(); | ||
53 | 56 | | |||
54 | } else if (status == PlasmaComponents.DialogStatus.Closed) { | 57 | } else if (status == PlasmaComponents.DialogStatus.Closed) { | ||
55 | menu.destroy(); | 58 | menu.destroy(); | ||
56 | backend.ungrabMouse(visualParent); | 59 | backend.ungrabMouse(visualParent); | ||
57 | } | 60 | } | ||
58 | } | 61 | } | ||
59 | 62 | | |||
63 | Component.onCompleted: { | ||||
64 | // Cannot have "Connections" as child of PlasmaCoponents.ContextMenu. | ||||
65 | backend.showAllPlaces.connect(function() { | ||||
66 | visualParent.showContextMenu({showAllPlaces: true}); | ||||
67 | }); | ||||
68 | } | ||||
69 | | ||||
60 | function get(modelProp) { | 70 | function get(modelProp) { | ||
61 | return tasksModel.data(modelIndex, modelProp) | 71 | return tasksModel.data(modelIndex, modelProp) | ||
62 | } | 72 | } | ||
63 | 73 | | |||
64 | function show() { | 74 | function show() { | ||
65 | loadDynamicLaunchActions(get(atm.LauncherUrlWithoutIcon)); | 75 | loadDynamicLaunchActions(get(atm.LauncherUrlWithoutIcon)); | ||
66 | openRelative(); | 76 | openRelative(); | ||
67 | } | 77 | } | ||
68 | 78 | | |||
69 | function newMenuItem(parent) { | 79 | function newMenuItem(parent) { | ||
70 | return Qt.createQmlObject( | 80 | return Qt.createQmlObject( | ||
71 | "import org.kde.plasma.components 2.0 as PlasmaComponents;" + | 81 | "import org.kde.plasma.components 2.0 as PlasmaComponents;" + | ||
72 | "PlasmaComponents.MenuItem {}", | 82 | "PlasmaComponents.MenuItem {}", | ||
73 | parent); | 83 | parent); | ||
74 | } | 84 | } | ||
75 | 85 | | |||
76 | function newSeparator(parent) { | 86 | function newSeparator(parent) { | ||
77 | return Qt.createQmlObject( | 87 | return Qt.createQmlObject( | ||
78 | "import org.kde.plasma.components 2.0 as PlasmaComponents;" + | 88 | "import org.kde.plasma.components 2.0 as PlasmaComponents;" + | ||
79 | "PlasmaComponents.MenuItem { separator: true }", | 89 | "PlasmaComponents.MenuItem { separator: true }", | ||
80 | parent); | 90 | parent); | ||
81 | } | 91 | } | ||
82 | 92 | | |||
83 | function loadDynamicLaunchActions(launcherUrl) { | 93 | function loadDynamicLaunchActions(launcherUrl) { | ||
84 | var actionList = backend.jumpListActions(launcherUrl, menu); | 94 | var lists = [ | ||
85 | 95 | backend.jumpListActions(launcherUrl, menu), | |||
86 | for (var i = 0; i < actionList.length; ++i) { | 96 | backend.placesActions(launcherUrl, showAllPlaces, menu), | ||
87 | var item = newMenuItem(menu); | 97 | backend.recentDocumentActions(launcherUrl, menu) | ||
88 | item.action = actionList[i]; | 98 | ] | ||
89 | menu.addMenuItem(item, virtualDesktopsMenuItem); | | |||
90 | } | | |||
91 | 99 | | |||
92 | if (actionList.length > 0) { | 100 | lists.forEach(function (list) { | ||
93 | menu.addMenuItem(newSeparator(menu), virtualDesktopsMenuItem); | 101 | for (var i = 0; i < list.length; ++i) { | ||
94 | } | | |||
95 | | ||||
96 | var actionList = backend.recentDocumentActions(launcherUrl, menu); | | |||
97 | | ||||
98 | for (var i = 0; i < actionList.length; ++i) { | | |||
99 | var item = newMenuItem(menu); | 102 | var item = newMenuItem(menu); | ||
100 | item.action = actionList[i]; | 103 | item.action = list[i]; | ||
101 | menu.addMenuItem(item, virtualDesktopsMenuItem); | 104 | menu.addMenuItem(item, virtualDesktopsMenuItem); | ||
102 | } | 105 | } | ||
103 | 106 | | |||
104 | if (actionList.length > 0) { | 107 | if (list.length > 0) { | ||
105 | menu.addMenuItem(newSeparator(menu), virtualDesktopsMenuItem); | 108 | menu.addMenuItem(newSeparator(menu), virtualDesktopsMenuItem); | ||
106 | } | 109 | } | ||
110 | }); | ||||
107 | 111 | | |||
108 | // Add Media Player control actions | 112 | // Add Media Player control actions | ||
109 | var sourceName = mpris2Source.sourceNameForLauncherUrl(launcherUrl, get(atm.AppPid)); | 113 | var sourceName = mpris2Source.sourceNameForLauncherUrl(launcherUrl, get(atm.AppPid)); | ||
110 | 114 | | |||
111 | if (sourceName && !(get(atm.LegacyWinIdList) != undefined && get(atm.LegacyWinIdList).length > 1)) { | 115 | if (sourceName && !(get(atm.LegacyWinIdList) != undefined && get(atm.LegacyWinIdList).length > 1)) { | ||
112 | var playerData = mpris2Source.data[sourceName] | 116 | var playerData = mpris2Source.data[sourceName] | ||
113 | 117 | | |||
114 | if (playerData.CanControl) { | 118 | if (playerData.CanControl) { | ||
▲ Show 20 Lines • Show All 545 Lines • Show Last 20 Lines |
Maybe a dated C++ mindset, but I don't like having no initial value :/