MessageTray: don't list the sources all the time
The point of a hash table is that you don't need to list all the elements. To avoid that, keep a "clearableCount" in MessageTray, which can be used by the message tray menu to show and hide the clear item, and that is updated in constant time when sources are added or removed. https://bugzilla.gnome.org/show_bug.cgi?id=700194
This commit is contained in:
parent
b0dc841e00
commit
fa44dc7d16
@ -1530,11 +1530,7 @@ const MessageTrayContextMenu = new Lang.Class({
|
||||
},
|
||||
|
||||
_updateClearSensitivity: function() {
|
||||
let sources = this._tray.getSources();
|
||||
sources = sources.filter(function(source) {
|
||||
return !source.trayIcon && !source.isChat && !source.resident;
|
||||
});
|
||||
this._clearItem.setSensitive(sources.length > 0);
|
||||
this._clearItem.setSensitive(this._tray.clearableCount > 0);
|
||||
},
|
||||
|
||||
setPosition: function(x, y) {
|
||||
@ -1660,6 +1656,8 @@ const MessageTray = new Lang.Class({
|
||||
this._desktopClone = null;
|
||||
this._inCtrlAltTab = false;
|
||||
|
||||
this.clearableCount = 0;
|
||||
|
||||
this._lightbox = new Lightbox.Lightbox(global.overlay_group,
|
||||
{ inhibitEvents: true,
|
||||
fadeInTime: ANIMATION_TIME,
|
||||
@ -1896,6 +1894,9 @@ const MessageTray = new Lang.Class({
|
||||
this._summary.insert_child_at_index(summaryItem.actor, this._chatSummaryItemsCount);
|
||||
}
|
||||
|
||||
if (!source.trayIcon && !source.isChat && !source.resident)
|
||||
this.clearableCount++;
|
||||
|
||||
this._sources.set(source, obj);
|
||||
|
||||
obj.notifyId = source.connect('notify', Lang.bind(this, this._onNotify));
|
||||
@ -1937,6 +1938,9 @@ const MessageTray = new Lang.Class({
|
||||
if (source.isChat)
|
||||
this._chatSummaryItemsCount--;
|
||||
|
||||
if (!source.trayIcon && !source.isChat && !source.resident)
|
||||
this.clearableCount--;
|
||||
|
||||
source.disconnect(obj.notifyId);
|
||||
source.disconnect(obj.destroyId);
|
||||
source.disconnect(obj.mutedChangedId);
|
||||
|
Loading…
Reference in New Issue
Block a user