on xenial help sign in
Replaced findChild() with signal-based solution to allow the TextField's accept method to trigger the notifications accept-action.
9f62a84Mirco Müller
qml/Notifications/Notification.qml+13−1
@@ -39,6 +39,8 @@ Item {
39 property bool fullscreen: false
39 property bool fullscreen: false
40 property int maxHeight
40 property int maxHeight
41 property int margins
41 property int margins
42+ property string acceptActionId
43+
42 property Gradient greenGradient : Gradient {
44 property Gradient greenGradient : Gradient {
43 GradientStop { position: 0.0; color: "#3fb24f" }
45 GradientStop { position: 0.0; color: "#3fb24f" }
44 GradientStop { position: 1.0; color: "#3fb24f" }
46 GradientStop { position: 1.0; color: "#3fb24f" }
@@ -141,6 +143,12 @@ Item {
141 opacity: parent.opacity
143 opacity: parent.opacity
142 }
144 }
143
145
146+ signal accept()
147+
148+ onAccept: {
149+ notification.notification.invokeAction(notification.acceptActionId)
150+ }
151+
144 Item {
152 Item {
145 id: contents
153 id: contents
146 anchors.fill: fullscreen ? nonShapedBack : shapedBack
154 anchors.fill: fullscreen ? nonShapedBack : shapedBack
@@ -344,7 +352,11 @@ Item {
344 objectName: "button" + index
352 objectName: "button" + index
345 width: buttonRow.width / 2 - spacing
353 width: buttonRow.width / 2 - spacing
346 text: loader.actionLabel
354 text: loader.actionLabel
347− property string actionId: loader.actionId
355+ Component.onCompleted: {
356+ if (index == 0) {
357+ notification.acceptActionId = loader.actionId
358+ }
359+ }
348 gradient: notification.hints["x-canonical-private-button-tint"] == "true" && index == 0 ? greenGradient : darkgreyGradient
360 gradient: notification.hints["x-canonical-private-button-tint"] == "true" && index == 0 ? greenGradient : darkgreyGradient
349 onClicked: notification.notification.invokeAction(loader.actionId)
361 onClicked: notification.notification.invokeAction(loader.actionId)
350 }
362 }
qml/Notifications/NotificationMenuItemFactory.qml+1−17
@@ -65,21 +65,6 @@ Loader {
65 text: menuData.label
65 text: menuData.label
66 }
66 }
67
67
68− function findChild(obj, objectName) {
69− var childs = new Array(0);
70− childs.push(obj)
71− while (childs.length > 0) {
72− if (childs[0].objectName == objectName) {
73− return childs[0]
74− }
75− for (var i in childs[0]["children"]) {
76− childs.push(childs[0]["children"][i])
77− }
78− childs.splice(0, 1);
79− }
80− return null;
81− }
82−
83 TextField {
68 TextField {
84 id: textfield
69 id: textfield
85
70
@@ -95,8 +80,7 @@ Loader {
95 menuModel.changeState(menuIndex, text);
80 menuModel.changeState(menuIndex, text);
96 }
81 }
97 onAccepted: {
82 onAccepted: {
98− var accept = findChild(notification, "button0")
83+ notification.accept()
99− notification.notification.invokeAction(accept.actionId)
100 }
84 }
101 }
85 }
102
86