[gnome-shell] messageTray: Make clear item insensetive when there is nothing to clear



commit 2138fc2349b27e5f943af236e71ece0512a7c513
Author: Adel Gadllah <adel gadllah gmail com>
Date:   Wed Feb 13 13:08:28 2013 +0100

    messageTray: Make clear item insensetive when there is nothing to clear
    
    There is no point in having a menu entry that does nothing so set the item
    to insensitive when there are no items to clear.

 js/ui/messageTray.js |   15 ++++++++++++++-
 1 files changed, 14 insertions(+), 1 deletions(-)
---
diff --git a/js/ui/messageTray.js b/js/ui/messageTray.js
index dae841f..4daee88 100644
--- a/js/ui/messageTray.js
+++ b/js/ui/messageTray.js
@@ -1457,8 +1457,9 @@ const MessageTrayContextMenu = new Lang.Class({
         Main.uiGroup.add_actor(this._dummy);
 
         this.parent(this._dummy, 0, St.Side.BOTTOM);
+        this._tray = tray;
 
-        this.addAction(_("Clear"), function() {
+        this._clearItem = this.addAction(_("Clear"), function() {
             let toDestroy = [];
             let sources = tray.getSources();
             for (let i = 0; i < sources.length; i++) {
@@ -1478,6 +1479,10 @@ const MessageTrayContextMenu = new Lang.Class({
             tray.close();
         });
 
+        tray.connect('source-added', Lang.bind(this, this._updateClearSensitivity));
+        tray.connect('source-removed', Lang.bind(this, this._updateClearSensitivity));
+        this._updateClearSensitivity();
+
         let separator = new PopupMenu.PopupSeparatorMenuItem();
         this.addMenuItem(separator);
 
@@ -1485,6 +1490,14 @@ const MessageTrayContextMenu = new Lang.Class({
         settingsItem.connect('activate', function() { tray.close(); });
     },
 
+    _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);
+    },
+
     setPosition: function(x, y) {
         this._dummy.set_position(x, y);
     }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]