on xenial help sign in
Better API for indicator menu select activation
de24225Nick Dedekind
modules/Unity/Indicators/qml/BasicMenu.qml+4−7
@@ -23,11 +23,14 @@ import Ubuntu.Components.ListItems 0.1 as ListItem
23ListItem.Standard {
23ListItem.Standard {
24 id: _priv
24 id: _priv
25
25
26− property bool listViewIsCurrentItem : false
26+ property bool menuActivated : false
27 property QtObject menu
27 property QtObject menu
28 property QtObject actionGroup
28 property QtObject actionGroup
29 property alias color: __bg.color
29 property alias color: __bg.color
30
30
31+ signal activateMenu()
32+ signal deactivateMenu()
33+
31 showDivider: false
34 showDivider: false
32 __foregroundColor: "#e8e1d0"
35 __foregroundColor: "#e8e1d0"
33
36
@@ -42,10 +45,4 @@ ListItem.Standard {
42 color: "#221e1c"
45 color: "#221e1c"
43 z: -1
46 z: -1
44 }
47 }
45−
46− function listViewSelectItem(targetIndex) {
47− if (__menuFactory != undefined) {
48− return __menuFactory.selectItem(targetIndex)
49− }
50− }
51}
48}
modules/Unity/Indicators/qml/IndicatorPage.qml+5−1
@@ -134,7 +134,11 @@ IndicatorBase {
134 height: implicitHeight
134 height: implicitHeight
135 menu: model
135 menu: model
136
136
137+ Connections {
138+ target : factory
139+ onActivated: item.ListView.view.currentIndex = index
137− onSelectItem: item.ListView.view.currentIndex = targetIndex
140+ onDeactivated: item.ListView.view.currentIndex = -1
141+ }
138 }
142 }
139 }
143 }
140 }
144 }
modules/Unity/Indicators/qml/MenuFactory.qml+9−7
@@ -33,7 +33,8 @@ Item {
33
33
34 implicitHeight: (__loader.status === Loader.Ready) ? __loader.item.implicitHeight : 0
34 implicitHeight: (__loader.status === Loader.Ready) ? __loader.item.implicitHeight : 0
35
35
36− signal selectItem(int targetIndex)
36+ signal activated()
37+ signal deactivated()
37
38
38 property var _map: {
39 property var _map: {
39 "unity.widgets.systemsettings.tablet.volumecontrol" : sliderMenu,
40 "unity.widgets.systemsettings.tablet.volumecontrol" : sliderMenu,
@@ -95,12 +96,13 @@ Item {
95 return undefined;
96 return undefined;
96 }
97 }
97
98
98− onStatusChanged: {
99+ onLoaded: {
99− if (status == Loader.Ready) {
100− item.listViewIsCurrentItem = Qt.binding(function() { return isCurrentItem; });
100+ item.menuActivated = Qt.binding(function() { return isCurrentItem; });
101− item.actionGroup = Qt.binding(function() { return __menuFactory.actionGroup; });
101+ item.actionGroup = Qt.binding(function() { return __menuFactory.actionGroup; });
102− item.menu = Qt.binding(function() { return __menuFactory.menu; });
102+ item.menu = Qt.binding(function() { return __menuFactory.menu; });
103− }
103+
104+ item.activateMenu.connect(function() { __menuFactory.activated(); });
105+ item.deactivateMenu.connect(function() { __menuFactory.deactivated(); });
104 }
106 }
105 }
107 }
106}
108}
modules/Unity/Indicators/qml/messaging/HeroMessage.qml+5−5
@@ -51,17 +51,17 @@ Indicators.BasicMenu {
51
51
52 onAppIconClicked: {
52 onAppIconClicked: {
53 if (action && action.valid) {
53 if (action && action.valid) {
54− listViewSelectItem(-1)
54+ deactivateMenu()
55 action.activate(true)
55 action.activate(true)
56 }
56 }
57 }
57 }
58 }
58 }
59
59
60 onClicked: {
60 onClicked: {
61− if (listViewIsCurrentItem) {
61+ if (menuActivated) {
62− listViewSelectItem(-1)
62+ deactivateMenu()
63 } else {
63 } else {
64− listViewSelectItem(index)
64+ activateMenu()
65 }
65 }
66 }
66 }
67
67
@@ -79,7 +79,7 @@ Indicators.BasicMenu {
79
79
80 states: State {
80 states: State {
81 name: "expanded"
81 name: "expanded"
82− when: listViewIsCurrentItem
82+ when: menuActivated
83
83
84 PropertyChanges {
84 PropertyChanges {
85 target: __heroMessage
85 target: __heroMessage
modules/Unity/Indicators/qml/messaging/MessageItem.qml+8−2
@@ -39,8 +39,8 @@ Indicators.BasicMenu {
39 // property will be propagated to the __contents.item at any time
39 // property will be propagated to the __contents.item at any time
40 Binding {
40 Binding {
41 target: __contents.item
41 target: __contents.item
42− property: "listViewIsCurrentItem"
42+ property: "menuActivated"
43− value: listViewIsCurrentItem
43+ value: menuActivated
44 when: (__contents.status == Loader.Ready)
44 when: (__contents.status == Loader.Ready)
45 }
45 }
46
46
@@ -64,6 +64,12 @@ Indicators.BasicMenu {
64 value: actionsDescription
64 value: actionsDescription
65 when: (__contents.status == Loader.Ready)
65 when: (__contents.status == Loader.Ready)
66 }
66 }
67+
68+ Connections {
69+ target: __contents.item ? __contents.item : null
70+ onActivateMenu: activateMenu()
71+ onDeactivateMenu: deactivateMenu()
72+ }
67 }
73 }
68
74
69
75