Commit e5df3ded authored by David Edmundson's avatar David Edmundson

Avoid capturing MenuItem instead determine checked state from toggled signal

Summary:
Due to JS lambdas menuItem is being captured by reference, and as such
the call to menuItem.checked returns the checked state of the last item
in the for loop. Instead of adding to the capture this patch uses the
supplied boolean from the QMenuItem::toggled signal.

Also unlike Array.concat Array.splice alters the current array, we don't
want to create a new var.

BUG: 376826

Test Plan:
Debug of menuItem.text showed we were capturing the wrong thing
Clicked window into multiple activities and unticked them. All worked as intended

Reviewers: #plasma

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D4757
parent 49dea014
......@@ -338,8 +338,7 @@ PlasmaComponents.ContextMenu {
menuItem.checked = Qt.binding(function() {
return menu.visualParent && menu.get(atm.Activities).length === 0;
});
menuItem.clicked.connect(function() {
var checked = menuItem.checked;
menuItem.toggled.connect(function(checked) {
var newActivities = undefined; // will cast to an empty QStringList i.e all activities
if (!checked) {
newActivities = new Array(activityInfo.currentActivity);
......@@ -361,9 +360,8 @@ PlasmaComponents.ContextMenu {
return menu.visualParent && menu.get(atm.Activities).indexOf(activityId) >= 0;
};
})(activityId));
menuItem.clicked.connect((function(activityId) {
return function () {
var checked = menuItem.checked;
menuItem.toggled.connect((function(activityId) {
return function (checked) {
var newActivities = menu.get(atm.Activities);
if (checked) {
newActivities = newActivities.concat(activityId);
......@@ -372,7 +370,8 @@ PlasmaComponents.ContextMenu {
if (index < 0) {
return;
}
newActivities = newActivities.splice(index, 1);
newActivities.splice(index, 1);
}
return tasksModel.requestActivities(menu.modelIndex, newActivities);
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment