on xenial help sign in
MenuItemFactory: make filtering of entries by action cleaner using a map
5abb376Marco Trevisan (Treviño)
qml/Panel/Indicators/MenuItemFactory.qml+22−18
@@ -31,7 +31,7 @@ Item {
31 property var rootModel: null
31 property var rootModel: null
32 property var menuModel: null
32 property var menuModel: null
33
33
34− property var _map: {
34+ readonly property var _map: {
35 "default": {
35 "default": {
36 "unity.widgets.systemsettings.tablet.volumecontrol" : sliderMenu,
36 "unity.widgets.systemsettings.tablet.volumecontrol" : sliderMenu,
37 "unity.widgets.systemsettings.tablet.switch" : switchMenu,
37 "unity.widgets.systemsettings.tablet.switch" : switchMenu,
@@ -69,8 +69,21 @@ Item {
69 "indicator.guest-menu-item": Platform.isPC ? userMenuItem : null,
69 "indicator.guest-menu-item": Platform.isPC ? userMenuItem : null,
70 "com.canonical.indicator.switch": Math.min(Screen.width, Screen.height) > units.gu(60) ? switchMenu : null // Desktop mode switch
70 "com.canonical.indicator.switch": Math.min(Screen.width, Screen.height) > units.gu(60) ? switchMenu : null // Desktop mode switch
71 },
71 },
72− "indicator-messages" : {
72+ "indicator-messages": {
73− "com.canonical.indicator.button" : messagesButtonMenu
73+ "com.canonical.indicator.button": messagesButtonMenu
74+ }
75+ }
76+
77+ readonly property var _action_filter_map: {
78+ "indicator-session": {
79+ "indicator.logout": Platform.isPC ? undefined : null,
80+ "indicator.suspend": Platform.isPC ? undefined : null,
81+ "indicator.hibernate": Platform.isPC ? undefined : null,
82+ "indicator.reboot": Platform.isPC ? undefined : null
83+ },
84+ "indicator-keyboard": {
85+ "indicator.map": null,
86+ "indicator.chart": null
74 }
87 }
75 }
88 }
76
89
@@ -1016,21 +1029,12 @@ Item {
1016 if (context.indexOf("fake-") == 0)
1029 if (context.indexOf("fake-") == 0)
1017 context = context.substring("fake-".length)
1030 context = context.substring("fake-".length)
1018
1031
1019− // tweak indicator-session items
1032+ if (modelData.action !== undefined && modelData.action !== "") {
1020− if (context === "indicator-session") {
1033+ var contextFilter = _action_filter_map[context]
1021− if ((modelData.action === "indicator.logout" || modelData.action === "indicator.suspend" || modelData.action === "indicator.hibernate" ||
1034+ if (contextFilter !== undefined) {
1022− modelData.action === "indicator.reboot")
1035+ var component = contextFilter[modelData.action];
1023− && !Platform.isPC) {
1036+ if (component !== undefined)
1024− return null; // logout, suspend and hibernate hidden on devices
1037+ return component
1025− }
1026− }
1027−
1028− // specialize for indicator-keyboard
1029− if (context === "indicator-keyboard") {
1030− if (modelData.isRadio) {
1031− return keymapMenu;
1032− } else if (modelData.action === "indicator.map" || modelData.action === "indicator.chart") {
1033− return null; // map and chart not available
1034 }
1038 }
1035 }
1039 }
1036
1040