[gnome-shell/wip/aggregate-menu: 35/75] popupMenu: Propagate sensitivity to menu children



commit 555e545deed45d02aed3543e0b09fa5fdba13b9d
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Wed Jun 12 03:16:53 2013 -0400

    popupMenu: Propagate sensitivity to menu children
    
    This way, if a parent is insensitive, all children will be, too.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=702539

 js/ui/popupMenu.js |   64 ++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 55 insertions(+), 9 deletions(-)
---
diff --git a/js/ui/popupMenu.js b/js/ui/popupMenu.js
index 6d41bfa..8d15aea 100644
--- a/js/ui/popupMenu.js
+++ b/js/ui/popupMenu.js
@@ -64,6 +64,8 @@ const PopupBaseMenuItem = new Lang.Class({
         this._spacing = 0;
         this.active = false;
         this._activatable = params.reactive && params.activate;
+        this._sensitive = true;
+        this.parentSensitive = true;
 
         if (!this._activatable)
             this.actor.add_style_class_name('popup-inactive-menu-item');
@@ -133,17 +135,24 @@ const PopupBaseMenuItem = new Lang.Class({
         }
     },
 
-    setSensitive: function(sensitive) {
-        if (!this._activatable)
-            return;
-        if (this.sensitive == sensitive)
-            return;
-
-        this.sensitive = sensitive;
+    syncSensitive: function() {
+        let sensitive = this.getSensitive();
         this.actor.reactive = sensitive;
         this.actor.can_focus = sensitive;
+        this.emit('sensitive-changed');
+        return sensitive;
+    },
 
-        this.emit('sensitive-changed', sensitive);
+    getSensitive: function() {
+        return this._activatable && this._sensitive && this.parentSensitive;
+    },
+
+    setSensitive: function(sensitive) {
+        if (this._sensitive == sensitive)
+            return;
+
+        this._sensitive = sensitive;
+        this.syncSensitive();
     },
 
     destroy: function() {
@@ -669,9 +678,21 @@ const PopupMenuBase = new Lang.Class({
         this._activeMenuItem = null;
         this._settingsActions = { };
 
+        this._sensitive = true;
+        this.parentSensitive = true;
+
         this._sessionUpdatedId = Main.sessionMode.connect('updated', Lang.bind(this, this._sessionUpdated));
     },
 
+    getSensitive: function() {
+        return this._sensitive && this.parentSensitive;
+    },
+
+    setSensitive: function(sensitive) {
+        this._sensitive = sensitive;
+        this.emit('sensitive-changed');
+    },
+
     _sessionUpdated: function() {
         this._setSettingsVisibility(Main.sessionMode.allowSettings);
     },
@@ -750,7 +771,8 @@ const PopupMenuBase = new Lang.Class({
                 this.emit('active-changed', null);
             }
         }));
-        menuItem._sensitiveChangeId = menuItem.connect('sensitive-changed', Lang.bind(this, 
function(menuItem, sensitive) {
+        menuItem._sensitiveChangeId = menuItem.connect('sensitive-changed', Lang.bind(this, function() {
+            let sensitive = menuItem.getSensitive();
             if (!sensitive && this._activeMenuItem == menuItem) {
                 if (!this.actor.navigate_focus(menuItem.actor,
                                                Gtk.DirectionType.TAB_FORWARD,
@@ -764,6 +786,12 @@ const PopupMenuBase = new Lang.Class({
         menuItem._activateId = menuItem.connect('activate', Lang.bind(this, function (menuItem, event) {
             this.emit('activate', BoxPointer.PopupAnimation.FULL);
         }));
+
+        menuItem._parentSensitiveChangeId = this.connect('sensitive-changed', Lang.bind(this, function() {
+            menuItem.parentSensitive = this.getSensitive();
+            menuItem.syncSensitive();
+        }));
+
         // the weird name is to avoid a conflict with some random property
         // the menuItem may have, called destroyId
         // (FIXME: in the future it may make sense to have container objects
@@ -773,6 +801,7 @@ const PopupMenuBase = new Lang.Class({
             menuItem.disconnect(menuItem._activateId);
             menuItem.disconnect(menuItem._activeChangeId);
             menuItem.disconnect(menuItem._sensitiveChangeId);
+            this.disconnect(menuItem._parentSensitiveChangeId);
             if (menuItem == this._activeMenuItem)
                 this._activeMenuItem = null;
         }));
@@ -846,11 +875,16 @@ const PopupMenuBase = new Lang.Class({
             let subMenuOpenStateChangedId = menuItem.connect('submenu-open-state-changed', Lang.bind(this, 
function(menuItem, submenu, open) {
                 this.emit('submenu-open-state-changed', submenu, open);
             }));
+            let subMenuSensitiveChangedId = this.connect('sensitive-changed', Lang.bind(this, function() {
+                menuItem.parentSensitive = this.getSensitive();
+                menuItem.emit('sensitive-changed');
+            }));
 
             menuItem.connect('destroy', Lang.bind(this, function() {
                 menuItem.disconnect(activateId);
                 menuItem.disconnect(activeChangeId);
                 menuItem.disconnect(subMenuOpenStateChangedId);
+                this.disconnect(subMenuSensitiveChangedId);
                 this.disconnect(parentOpenStateChangedId);
                 this.disconnect(parentClosingId);
                 this.length--;
@@ -872,6 +906,7 @@ const PopupMenuBase = new Lang.Class({
             let subMenuOpenStateChangedId = menuItem.connect('submenu-open-state-changed', Lang.bind(this, 
function(menuItem, submenu, open) {
                 this.emit('submenu-open-state-changed', submenu, open);
             }));
+
             menuItem.connect('destroy', Lang.bind(this, function() {
                 menuItem.menu.disconnect(subMenuActivateId);
                 menuItem.menu.disconnect(subMenuActiveChangeId);
@@ -1136,6 +1171,10 @@ const PopupDummyMenu = new Lang.Class({
         return false;
     },
 
+    getSensitive: function() {
+        return true;
+    },
+
     open: function() { this.emit('open-state-changed', true); },
     close: function() { this.emit('open-state-changed', false); },
     toggle: function() {},
@@ -1190,6 +1229,13 @@ const PopupSubMenu = new Lang.Class({
         return topMaxHeight >= 0 && topNaturalHeight >= topMaxHeight;
     },
 
+    getSensitive: function() {
+        if (!this._sensitive)
+            return false;
+
+        return this.sourceActor._delegate.getSensitive();
+    },
+
     open: function(animate) {
         if (this.isOpen)
             return;


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