messageTray: store notifications and signal ids in an array of objects in SummaryItem

The code is cleaner that way. It also allows us to find the notification object
after the notification actor is destroyed and disconnect the signals.
This commit is contained in:
Marina Zhurakhinskaya 2011-09-08 00:40:58 -04:00
parent 98649f9397
commit f7fb6b2160

View File

@ -1169,9 +1169,7 @@ SummaryItem.prototype = {
this.notificationStack = new St.BoxLayout({ name: 'summary-notification-stack', this.notificationStack = new St.BoxLayout({ name: 'summary-notification-stack',
vertical: true }); vertical: true });
this.notificationStackView.add_actor(this.notificationStack); this.notificationStackView.add_actor(this.notificationStack);
this._notificationExpandedIds = []; this._stackedNotifications = [];
this._notificationDoneDisplayingIds = [];
this._notificationDestroyedIds = [];
this._oldMaxScrollAdjustment = 0; this._oldMaxScrollAdjustment = 0;
@ -1240,18 +1238,19 @@ SummaryItem.prototype = {
doneShowingNotificationStack: function() { doneShowingNotificationStack: function() {
let notificationActors = this.notificationStack.get_children(); let notificationActors = this.notificationStack.get_children();
for (let i = 0; i < notificationActors.length; i++) { for (let i = 0; i < this._stackedNotifications.length; i++) {
notificationActors[i]._delegate.collapseCompleted(); let stackedNotification = this._stackedNotifications[i];
notificationActors[i]._delegate.disconnect(this._notificationExpandedIds[i]); let notification = stackedNotification.notification;
notificationActors[i]._delegate.disconnect(this._notificationDoneDisplayingIds[i]); notification.collapseCompleted();
notificationActors[i]._delegate.disconnect(this._notificationDestroyedIds[i]); notification.disconnect(stackedNotification.notificationExpandedId);
this.notificationStack.remove_actor(notificationActors[i]); notification.disconnect(stackedNotification.notificationDoneDisplayingId);
notificationActors[i]._delegate.setIconVisible(true); notification.disconnect(stackedNotification.notificationDestroyedId);
notificationActors[i]._delegate.enableScrolling(true); if (notification.actor.get_parent() == this.notificationStack)
this.notificationStack.remove_actor(notification.actor);
notification.setIconVisible(true);
notification.enableScrolling(true);
} }
this._notificationExpandedIds = []; this._stackedNotifications = [];
this._notificationDoneDisplayingIds = [];
this._notificationDestroyedIds = [];
}, },
_notificationAddedToSource: function(source, notification) { _notificationAddedToSource: function(source, notification) {
@ -1260,12 +1259,12 @@ SummaryItem.prototype = {
}, },
_appendNotificationToStack: function(notification) { _appendNotificationToStack: function(notification) {
let notificationExpandedId = notification.connect('expanded', Lang.bind(this, this._contentUpdated)); let stackedNotification = {};
this._notificationExpandedIds.push(notificationExpandedId); stackedNotification.notification = notification;
let notificationDoneDisplayingId = notification.connect('done-displaying', Lang.bind(this, this._notificationDoneDisplaying)); stackedNotification.notificationExpandedId = notification.connect('expanded', Lang.bind(this, this._contentUpdated));
this._notificationDoneDisplayingIds.push(notificationDoneDisplayingId); stackedNotification.notificationDoneDisplayingId = notification.connect('done-displaying', Lang.bind(this, this._notificationDoneDisplaying));
let notificationDestroyedId = notification.connect('destroy', Lang.bind(this, this._notificationDestroyed)); stackedNotification.notificationDestroyedId = notification.connect('destroy', Lang.bind(this, this._notificationDestroyed));
this._notificationDestroyedIds.push(notificationDestroyedId); this._stackedNotifications.push(stackedNotification);
if (!this.source.isChat) if (!this.source.isChat)
notification.enableScrolling(false); notification.enableScrolling(false);
if (this.notificationStack.get_children().length > 0) if (this.notificationStack.get_children().length > 0)
@ -1295,17 +1294,18 @@ SummaryItem.prototype = {
}, },
_notificationDestroyed: function(notification) { _notificationDestroyed: function(notification) {
let index = this.notificationStack.get_children().indexOf(notification.actor); for (let i = 0; i < this._stackedNotifications.length; i++) {
if (index >= 0) { if (this._stackedNotifications[i].notification == notification) {
notification.disconnect(this._notificationExpandedIds[index]); let stackedNotification = this._stackedNotifications[i];
this._notificationExpandedIds.splice(index, 1); notification.disconnect(stackedNotification.notificationExpandedId);
notification.disconnect(this._notificationDoneDisplayingIds[index]); notification.disconnect(stackedNotification.notificationDoneDisplayingId);
this._notificationDoneDisplayingIds.splice(index, 1); notification.disconnect(stackedNotification.notificationDestroyedId);
notification.disconnect(this._notificationDestroyedIds[index]); this._stackedNotifications.splice(i, 1);
this._notificationDestroyedIds.splice(index, 1);
this.notificationStack.remove_actor(notification.actor);
this._contentUpdated(); this._contentUpdated();
break;
} }
}
if (this.notificationStack.get_children().length > 0) if (this.notificationStack.get_children().length > 0)
this.notificationStack.get_children()[0]._delegate.setIconVisible(true); this.notificationStack.get_children()[0]._delegate.setIconVisible(true);
} }