[gnome-shell/wip/aggregate-menu: 31/75] popupMenu: Remove connectSubMenuSignals



commit f6d79f50402223f2cc9376f37c2f0864bbd42227
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Tue Jun 11 19:18:06 2013 -0400

    popupMenu: Remove connectSubMenuSignals
    
    The code here is a bit messy, as the signal disconnection is handled
    in two different places. Share code in a better, different way.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=702539

 js/ui/popupMenu.js |   73 ++++++++++++++++++++++++---------------------------
 1 files changed, 34 insertions(+), 39 deletions(-)
---
diff --git a/js/ui/popupMenu.js b/js/ui/popupMenu.js
index 1daf200..eda3032 100644
--- a/js/ui/popupMenu.js
+++ b/js/ui/popupMenu.js
@@ -735,24 +735,11 @@ const PopupMenuBase = new Lang.Class({
         this.emit('activate', animate);
     },
 
-    /**
-     * _connectSubMenuSignals:
-     * @object: a menu item, or a menu section
-     * @menu: a sub menu, or a menu section
-     *
-     * Connects to signals on @menu that are necessary for
-     * operating the submenu, and stores the ids on @object.
-     */
-    _connectSubMenuSignals: function(object, menu) {
-        object._subMenuActivateId = menu.connect('activate', Lang.bind(this, function(animate) {
-            this.emit('activate', animate);
-        }));
-        object._subMenuActiveChangeId = menu.connect('active-changed', Lang.bind(this, function(submenu, 
submenuItem) {
-            if (this._activeMenuItem && this._activeMenuItem != submenuItem)
-                this._activeMenuItem.setActive(false);
-            this._activeMenuItem = submenuItem;
-            this.emit('active-changed', submenuItem);
-        }));
+    _subMenuActiveChanged: function(submenu, submenuItem) {
+        if (this._activeMenuItem && this._activeMenuItem != submenuItem)
+            this._activeMenuItem.setActive(false);
+        this._activeMenuItem = submenuItem;
+        this.emit('active-changed', submenuItem);
     },
 
     _connectItemSignals: function(menuItem) {
@@ -790,11 +777,6 @@ const PopupMenuBase = new Lang.Class({
             menuItem.disconnect(menuItem._activateId);
             menuItem.disconnect(menuItem._activeChangeId);
             menuItem.disconnect(menuItem._sensitiveChangeId);
-            if (menuItem.menu) {
-                menuItem.menu.disconnect(menuItem._subMenuActivateId);
-                menuItem.menu.disconnect(menuItem._subMenuActiveChangeId);
-                this.disconnect(menuItem._closingId);
-            }
             if (menuItem == this._activeMenuItem)
                 this._activeMenuItem = null;
         }));
@@ -851,23 +833,26 @@ const PopupMenuBase = new Lang.Class({
         }
 
         if (menuItem instanceof PopupMenuSection) {
-            this._connectSubMenuSignals(menuItem, menuItem);
-            menuItem._parentOpenStateChangedId = this.connect('open-state-changed',
-                function(self, open) {
-                    if (open)
-                        menuItem.open();
-                    else
-                        menuItem.close();
-                });
-            menuItem._parentClosingId = this.connect('menu-closed', function() {
+            let activateId = menuItem.connect('activate', Lang.bind(this, function(animate) {
+                this.emit('activate', animate);
+            }));
+            let activeChangeId = menuItem.connect('active-changed', Lang.bind(this, 
this._subMenuActiveChanged));
+
+            let parentOpenStateChangedId = this.connect('open-state-changed', function(self, open) {
+                if (open)
+                    menuItem.open();
+                else
+                    menuItem.close();
+            });
+            let parentClosingId = this.connect('menu-closed', function() {
                 menuItem.emit('menu-closed');
             });
-            menuItem.connect('destroy', Lang.bind(this, function() {
-                menuItem.disconnect(menuItem._subMenuActivateId);
-                menuItem.disconnect(menuItem._subMenuActiveChangeId);
-                this.disconnect(menuItem._parentOpenStateChangedId);
-                this.disconnect(menuItem._parentClosingId);
 
+            menuItem.connect('destroy', Lang.bind(this, function() {
+                menuItem.disconnect(activateId);
+                menuItem.disconnect(activeChangeId);
+                this.disconnect(parentOpenStateChangedId);
+                this.disconnect(parentClosingId);
                 this.length--;
             }));
         } else if (menuItem instanceof PopupSubMenuMenuItem) {
@@ -875,11 +860,21 @@ const PopupMenuBase = new Lang.Class({
                 this.box.add(menuItem.menu.actor);
             else
                 this.box.insert_child_below(menuItem.menu.actor, before_item);
-            this._connectSubMenuSignals(menuItem, menuItem.menu);
+
             this._connectItemSignals(menuItem);
-            menuItem._closingId = this.connect('menu-closed', function() {
+            let subMenuActivateId = menuItem.connect('activate', Lang.bind(this, function() {
+                this.emit('activate', animate);
+            }));
+            let subMenuActiveChangeId = menuItem.menu.connect('active-changed', Lang.bind(this, 
this._subMenuActiveChanged));
+            let closingId = this.connect('menu-closed', function() {
                 menuItem.menu.close(BoxPointer.PopupAnimation.NONE);
             });
+
+            menuItem.connect('destroy', Lang.bind(this, function() {
+                menuItem.menu.disconnect(subMenuActivateId);
+                menuItem.menu.disconnect(subMenuActiveChangeId);
+                this.disconnect(closingId);
+            }));
         } else if (menuItem instanceof PopupSeparatorMenuItem) {
             this._connectItemSignals(menuItem);
 


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