[gnome-shell] PopupMenu: make parameters overridable in items



commit 6e236546eafa7eabc1b9db36c2b61acba4f8b773
Author: Giovanni Campagna <gcampagna src gnome org>
Date:   Tue Jan 25 22:06:40 2011 +0100

    PopupMenu: make parameters overridable in items
    
    Make all subclasses of PopupMenuBase accept a params argument, which
    can be used to make the item non reactive, not responsive to hover
    and, as a new feature, with a different style class.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=621707

 js/ui/popupMenu.js  |   27 ++++++++++++++++++---------
 js/ui/statusMenu.js |    4 ++--
 2 files changed, 20 insertions(+), 11 deletions(-)
---
diff --git a/js/ui/popupMenu.js b/js/ui/popupMenu.js
index 05a67bd..e3aeffe 100644
--- a/js/ui/popupMenu.js
+++ b/js/ui/popupMenu.js
@@ -26,7 +26,9 @@ PopupBaseMenuItem.prototype = {
     _init: function (params) {
         params = Params.parse (params, { reactive: true,
                                          activate: true,
-                                         hover: true });
+                                         hover: true,
+                                         style_class: null
+                                       });
         this.actor = new Shell.GenericContainer({ style_class: 'popup-menu-item',
                                                   reactive: params.reactive,
                                                   track_hover: params.reactive,
@@ -43,6 +45,9 @@ PopupBaseMenuItem.prototype = {
         this._spacing = 0;
         this.active = false;
 
+        if (params.style_class)
+            this.actor.add_style_class_name(params.style_class);
+
         if (params.reactive && params.activate) {
             this.actor.connect('button-release-event', Lang.bind(this, this._onButtonReleaseEvent));
             this.actor.connect('key-press-event', Lang.bind(this, this._onKeyPressEvent));
@@ -527,8 +532,8 @@ function PopupSwitchMenuItem() {
 PopupSwitchMenuItem.prototype = {
     __proto__: PopupBaseMenuItem.prototype,
 
-    _init: function(text, active) {
-        PopupBaseMenuItem.prototype._init.call(this);
+    _init: function(text, active, params) {
+        PopupBaseMenuItem.prototype._init.call(this, params);
 
         this.label = new St.Label({ text: text });
         this._switch = new Switch(active);
@@ -555,15 +560,15 @@ PopupSwitchMenuItem.prototype = {
     }
 };
 
-function PopupImageMenuItem(text, iconName) {
-    this._init(text, iconName);
+function PopupImageMenuItem() {
+    this._init.apply(this, arguments);
 }
 
 PopupImageMenuItem.prototype = {
     __proto__: PopupBaseMenuItem.prototype,
 
-    _init: function (text, iconName) {
-        PopupBaseMenuItem.prototype._init.call(this);
+    _init: function (text, iconName, params) {
+        PopupBaseMenuItem.prototype._init.call(this, params);
 
         this.label = new St.Label({ text: text });
         this.addActor(this.label);
@@ -608,8 +613,12 @@ PopupMenuBase.prototype = {
     _init: function(sourceActor, styleClass) {
         this.sourceActor = sourceActor;
 
-        this.box = new St.BoxLayout({ style_class: styleClass,
-                                      vertical: true });
+        if (styleClass !== undefined) {
+            this.box = new St.BoxLayout({ style_class: styleClass,
+                                          vertical: true });
+        } else {
+            this.box = new St.BoxLayout({ vertical: true });
+        }
 
         this.isOpen = false;
         this._activeMenuItem = null;
diff --git a/js/ui/statusMenu.js b/js/ui/statusMenu.js
index ecc12b0..dc17f0f 100644
--- a/js/ui/statusMenu.js
+++ b/js/ui/statusMenu.js
@@ -99,12 +99,12 @@ StatusMenuButton.prototype = {
     _createSubMenu: function() {
         let item;
 
-        item = new PopupMenu.PopupImageMenuItem(_("Available"), 'user-available', true);
+        item = new PopupMenu.PopupImageMenuItem(_("Available"), 'user-available');
         item.connect('activate', Lang.bind(this, this._setPresenceStatus, GnomeSession.PresenceStatus.AVAILABLE));
         this.menu.addMenuItem(item);
         this._presenceItems[GnomeSession.PresenceStatus.AVAILABLE] = item;
 
-        item = new PopupMenu.PopupImageMenuItem(_("Busy"), 'user-busy', true);
+        item = new PopupMenu.PopupImageMenuItem(_("Busy"), 'user-busy');
         item.connect('activate', Lang.bind(this, this._setPresenceStatus, GnomeSession.PresenceStatus.BUSY));
         this.menu.addMenuItem(item);
         this._presenceItems[GnomeSession.PresenceStatus.BUSY] = item;



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