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() {
|
_updateClearSensitivity: function() {
|
||||||
let sources = this._tray.getSources();
|
this._clearItem.setSensitive(this._tray.clearableCount > 0);
|
||||||
sources = sources.filter(function(source) {
|
|
||||||
return !source.trayIcon && !source.isChat && !source.resident;
|
|
||||||
});
|
|
||||||
this._clearItem.setSensitive(sources.length > 0);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
setPosition: function(x, y) {
|
setPosition: function(x, y) {
|
||||||
@ -1660,6 +1656,8 @@ const MessageTray = new Lang.Class({
|
|||||||
this._desktopClone = null;
|
this._desktopClone = null;
|
||||||
this._inCtrlAltTab = false;
|
this._inCtrlAltTab = false;
|
||||||
|
|
||||||
|
this.clearableCount = 0;
|
||||||
|
|
||||||
this._lightbox = new Lightbox.Lightbox(global.overlay_group,
|
this._lightbox = new Lightbox.Lightbox(global.overlay_group,
|
||||||
{ inhibitEvents: true,
|
{ inhibitEvents: true,
|
||||||
fadeInTime: ANIMATION_TIME,
|
fadeInTime: ANIMATION_TIME,
|
||||||
@ -1896,6 +1894,9 @@ const MessageTray = new Lang.Class({
|
|||||||
this._summary.insert_child_at_index(summaryItem.actor, this._chatSummaryItemsCount);
|
this._summary.insert_child_at_index(summaryItem.actor, this._chatSummaryItemsCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!source.trayIcon && !source.isChat && !source.resident)
|
||||||
|
this.clearableCount++;
|
||||||
|
|
||||||
this._sources.set(source, obj);
|
this._sources.set(source, obj);
|
||||||
|
|
||||||
obj.notifyId = source.connect('notify', Lang.bind(this, this._onNotify));
|
obj.notifyId = source.connect('notify', Lang.bind(this, this._onNotify));
|
||||||
@ -1937,6 +1938,9 @@ const MessageTray = new Lang.Class({
|
|||||||
if (source.isChat)
|
if (source.isChat)
|
||||||
this._chatSummaryItemsCount--;
|
this._chatSummaryItemsCount--;
|
||||||
|
|
||||||
|
if (!source.trayIcon && !source.isChat && !source.resident)
|
||||||
|
this.clearableCount--;
|
||||||
|
|
||||||
source.disconnect(obj.notifyId);
|
source.disconnect(obj.notifyId);
|
||||||
source.disconnect(obj.destroyId);
|
source.disconnect(obj.destroyId);
|
||||||
source.disconnect(obj.mutedChangedId);
|
source.disconnect(obj.mutedChangedId);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user