[gnome-shell] panel: Add an easier way of adding items to the system status area



commit 08126e5a38513dffb0018f9c26aaa72dbceba34d
Author: Giovanni Campagna <gcampagna src gnome org>
Date:   Mon Aug 22 23:19:13 2011 +0200

    panel: Add an easier way of adding items to the system status area
    
    Extensions often want to add items to the system status area, so it
    is useful to add a convenience API for it. Also, we now allow
    for cleaner destruction of panel objects, by just calling destroy()
    on it.
    Based on a patch by Jasper St. Pierre.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=653205

 js/ui/panel.js     |   28 ++++++++++++++++++++++++----
 js/ui/panelMenu.js |   11 +++++++++++
 2 files changed, 35 insertions(+), 4 deletions(-)
---
diff --git a/js/ui/panel.js b/js/ui/panel.js
index 91adc4c..2fa00ce 100644
--- a/js/ui/panel.js
+++ b/js/ui/panel.js
@@ -962,11 +962,9 @@ Panel.prototype = {
                 // This icon is not implemented (this is a bug)
                 continue;
             }
-            let indicator = new constructor();
-            this._statusBox.add(indicator.actor);
-            this._menus.addMenu(indicator.menu);
 
-            this._statusArea[role] = indicator;
+            let indicator = new constructor();
+            this.addToStatusArea(role, indicator, i-1);
         }
 
         // PopupMenuManager depends on menus being added in order for
@@ -974,6 +972,28 @@ Panel.prototype = {
         this._menus.addMenu(this._userMenu.menu);
     },
 
+    addToStatusArea: function(role, indicator, position) {
+        if (this._statusArea[role])
+            throw new Error('Extension point conflict: there is already a status indicator for role ' + role);
+
+        if (!(indicator instanceof PanelMenu.Button))
+            throw new TypeError('Status indicator must be an instance of PanelMenu.Button');
+
+        if (!position)
+            position = 0;
+
+        this._statusBox.insert_actor(indicator.actor, position);
+        this._menus.addMenu(indicator.menu);
+
+        this._statusArea[role] = indicator;
+        let destroyId = indicator.connect('destroy', Lang.bind(this, function(emitter) {
+            this._statusArea[role] = null;
+            emitter.disconnect(destroyId);
+        }));
+
+        return indicator;
+    },
+
     startupAnimation: function() {
         let oldY = this.actor.y;
         this.actor.y = oldY - this.actor.height;
diff --git a/js/ui/panelMenu.js b/js/ui/panelMenu.js
index 5e9a191..44e2078 100644
--- a/js/ui/panelMenu.js
+++ b/js/ui/panelMenu.js
@@ -2,6 +2,7 @@
 
 const Clutter = imports.gi.Clutter;
 const Gtk = imports.gi.Gtk;
+const Signals = imports.signals;
 const St = imports.gi.St;
 
 const Lang = imports.lang;
@@ -80,8 +81,18 @@ Button.prototype = {
             this.actor.add_style_pseudo_class('active');
         else
             this.actor.remove_style_pseudo_class('active');
+    },
+
+    destroy: function() {
+        this.actor._delegate = null;
+
+        this.menu.destroy();
+        this.actor.destroy();
+
+        this.emit('destroy');
     }
 };
+Signals.addSignalMethods(Button.prototype);
 
 /* SystemStatusButton:
  *



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