[gnome-shell/wip/aggregate-menu: 68/99] popupMenu: Only allow one submenu to be open at a time



commit bc4b3b81f54f60b2ec8ea5165fc0f8ef7ab09477
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Tue Jun 11 19:12:46 2013 -0400

    popupMenu: Only allow one submenu to be open at a time
    
    When the user opens another submenu, close the first one.

 js/ui/popupMenu.js |   24 +++++++++++++++++++++++-
 1 files changed, 23 insertions(+), 1 deletions(-)
---
diff --git a/js/ui/popupMenu.js b/js/ui/popupMenu.js
index 57c5c14..c9c8bac 100644
--- a/js/ui/popupMenu.js
+++ b/js/ui/popupMenu.js
@@ -868,10 +868,14 @@ const PopupMenuBase = new Lang.Class({
             let parentClosingId = this.connect('menu-closed', function() {
                 menuItem.emit('menu-closed');
             });
+            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.disconnect(activateId);
                 menuItem.disconnect(activeChangeId);
+                menuItem.disconnect(subMenuOpenStateChangedId);
                 this.disconnect(parentOpenStateChangedId);
                 this.disconnect(parentClosingId);
                 this.length--;
@@ -888,10 +892,13 @@ const PopupMenuBase = new Lang.Class({
             let closingId = this.connect('menu-closed', function() {
                 menuItem.menu.close(BoxPointer.PopupAnimation.NONE);
             });
-
+            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);
+                menuItem.disconnect(subMenuOpenStateChangedId);
                 this.disconnect(closingId);
             }));
         } else if (menuItem instanceof PopupSeparatorMenuItem) {
@@ -1034,6 +1041,19 @@ const PopupMenu = new Lang.Class({
 
         global.focus_manager.add_group(this.actor);
         this.actor.reactive = true;
+
+        this._openedSubMenu = null;
+        this.connect('submenu-open-state-changed', Lang.bind(this, this._subMenuOpenStateChanged));
+    },
+
+    _subMenuOpenStateChanged: function(menu, submenu, open) {
+        if (open) {
+            if (this._openedSubMenu)
+                this._openedSubMenu.close(true);
+            this._openedSubMenu = submenu;
+        } else {
+            this._openedSubMenu = null;
+        }
     },
 
     _boxGetPreferredWidth: function (actor, forHeight, alloc) {
@@ -1317,6 +1337,8 @@ const PopupSubMenuMenuItem = new Lang.Class({
             this.actor.add_style_pseudo_class('open');
         else
             this.actor.remove_style_pseudo_class('open');
+
+        this.emit('submenu-open-state-changed', menu, open);
     },
 
     destroy: function() {


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