[gnome-shell/gnome-3-16] panel: Set up 'open-state-changed' handler on menu changes



commit 79c020fdb9424d2eee453f50b35a777946860b3b
Author: Florian Müllner <fmuellner gnome org>
Date:   Tue Apr 28 11:05:58 2015 +0200

    panel: Set up 'open-state-changed' handler on menu changes
    
    Commit 08690d658f42 generalized the banner-blocking behavior of the
    dateMenu to all menus that would obscure the banner. However setting
    up the 'open-state-changed' handler only when an indicator is added
    does not work for indicators that change their entire menu (like the
    app menu) - we currently end up with menus with no connected signal
    handler, and throw an error when trying to disconnect an invalid
    signal ID.
    To address this, add a new PanelButton::menu-set signal and use that
    to set up the 'open-state-changed' handler.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=745910

 js/ui/panel.js     |   39 +++++++++++++++++++++------------------
 js/ui/panelMenu.js |    1 +
 2 files changed, 22 insertions(+), 18 deletions(-)
---
diff --git a/js/ui/panel.js b/js/ui/panel.js
index 46be6ac..77f44c8 100644
--- a/js/ui/panel.js
+++ b/js/ui/panel.js
@@ -1003,24 +1003,6 @@ const Panel = new Lang.Class({
         if (parent)
             parent.remove_actor(container);
 
-        if (indicator._openChangedId > 0)
-            indicator.menu.disconnect(indicator._openChangedId);
-        indicator._openChangedId = 0;
-
-        if (indicator.menu)
-            indicator._openChangedId = indicator.menu.connect('open-state-changed',
-                Lang.bind(this, function(menu, isOpen) {
-                    let boxAlignment;
-                    if (box == this._leftBox)
-                        boxAlignment = Clutter.ActorAlign.START;
-                    else if (box == this._centerBox)
-                        boxAlignment = Clutter.ActorAlign.CENTER;
-                    else if (box == this._rightBox)
-                        boxAlignment = Clutter.ActorAlign.END;
-
-                    if (boxAlignment == Main.messageTray.bannerAlignment)
-                        Main.messageTray.bannerBlocked = isOpen;
-                }));
 
         box.insert_child_at_index(container, position);
         if (indicator.menu)
@@ -1031,6 +1013,8 @@ const Panel = new Lang.Class({
             emitter.disconnect(destroyId);
             container.destroy();
         }));
+        indicator.connect('menu-set', Lang.bind(this, this._onMenuSet));
+        this._onMenuSet(indicator);
     },
 
     addToStatusArea: function(role, indicator, position, box) {
@@ -1062,5 +1046,24 @@ const Panel = new Lang.Class({
         this.actor.remove_style_class_name(className);
         this._rightCorner.actor.remove_style_class_name(className);
         this._leftCorner.actor.remove_style_class_name(className);
+    },
+
+    _onMenuSet: function(indicator) {
+        if (!indicator.menu || indicator.menu._openChangedId > 0)
+            return;
+
+        indicator.menu._openChangedId = indicator.menu.connect('open-state-changed',
+            Lang.bind(this, function(menu, isOpen) {
+                let boxAlignment;
+                if (this._leftBox.contains(indicator.container))
+                    boxAlignment = Clutter.ActorAlign.START;
+                else if (this._centerBox.contains(indicator.container))
+                    boxAlignment = Clutter.ActorAlign.CENTER;
+                else if (this._rightBox.contains(indicator.container))
+                    boxAlignment = Clutter.ActorAlign.END;
+
+                if (boxAlignment == Main.messageTray.bannerAlignment)
+                    Main.messageTray.bannerBlocked = isOpen;
+            }));
     }
 });
diff --git a/js/ui/panelMenu.js b/js/ui/panelMenu.js
index 092ca23..d427ab5 100644
--- a/js/ui/panelMenu.js
+++ b/js/ui/panelMenu.js
@@ -128,6 +128,7 @@ const Button = new Lang.Class({
             Main.uiGroup.add_actor(this.menu.actor);
             this.menu.actor.hide();
         }
+        this.emit('menu-set');
     },
 
     _onEvent: function(actor, event) {


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