[gnome-shell] MessageTray: don't list the sources all the time
- From: Giovanni Campagna <gcampagna src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell] MessageTray: don't list the sources all the time
- Date: Sun, 12 May 2013 19:07:06 +0000 (UTC)
commit fa44dc7d1611786dc987e7767e1811801dc2d2b8
Author: Giovanni Campagna <gcampagna src gnome org>
Date: Sun May 12 20:13:43 2013 +0200
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
js/ui/messageTray.js | 14 +++++++++-----
1 files changed, 9 insertions(+), 5 deletions(-)
---
diff --git a/js/ui/messageTray.js b/js/ui/messageTray.js
index 5cdaf2d..8c24812 100644
--- a/js/ui/messageTray.js
+++ b/js/ui/messageTray.js
@@ -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);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]