on xenial help sign in
Replaced findChild() with signal-based solution to allow the TextField's accept method to trigger the notifications accept-action.
commit9f62a8401a702465fb7e3550c55c8fb87033dc56 authorMirco Müller <mirco.mueller@canonical.com> dateTue 22 Jul 2014, 14:29 (12 years ago) parentbf7825b
2 files changed+14−18
qml/Notifications/Notification.qml+13−1 qml/Notifications/NotificationMenuItemFactory.qml+1−17
qml/Notifications/Notification.qml+13−1
@@ -39,6 +39,8 @@ Item {
3939 property bool fullscreen: false
4040 property int maxHeight
4141 property int margins
42+ property string acceptActionId
43+
4244 property Gradient greenGradient : Gradient {
4345 GradientStop { position: 0.0; color: "#3fb24f" }
4446 GradientStop { position: 1.0; color: "#3fb24f" }
@@ -141,6 +143,12 @@ Item {
141143 opacity: parent.opacity
142144 }
143145
146+ signal accept()
147+
148+ onAccept: {
149+ notification.notification.invokeAction(notification.acceptActionId)
150+ }
151+
144152 Item {
145153 id: contents
146154 anchors.fill: fullscreen ? nonShapedBack : shapedBack
@@ -344,7 +352,11 @@ Item {
344352 objectName: "button" + index
345353 width: buttonRow.width / 2 - spacing
346354 text: loader.actionLabel
347− property string actionId: loader.actionId
355+ Component.onCompleted: {
356+ if (index == 0) {
357+ notification.acceptActionId = loader.actionId
358+ }
359+ }
348360 gradient: notification.hints["x-canonical-private-button-tint"] == "true" && index == 0 ? greenGradient : darkgreyGradient
349361 onClicked: notification.notification.invokeAction(loader.actionId)
350362 }
qml/Notifications/NotificationMenuItemFactory.qml+1−17
@@ -65,21 +65,6 @@ Loader {
6565 text: menuData.label
6666 }
6767
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−
8368 TextField {
8469 id: textfield
8570
@@ -95,8 +80,7 @@ Loader {
9580 menuModel.changeState(menuIndex, text);
9681 }
9782 onAccepted: {
98− var accept = findChild(notification, "button0")
99− notification.notification.invokeAction(accept.actionId)
83+ notification.accept()
10084 }
10185 }
10286