From c698dee0711b427f684987381831c64f4395c23a Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Fri, 10 May 2013 14:32:58 -0400 Subject: [PATCH] remoteMenu: Add support for the submenu show requests This lets clients defer submenus showing until their submenu model is ready. https://bugzilla.gnome.org/show_bug.cgi?id=700257 --- js/ui/popupMenu.js | 25 ++++++++++++++++++++----- js/ui/remoteMenu.js | 29 ++++++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 6 deletions(-) diff --git a/js/ui/popupMenu.js b/js/ui/popupMenu.js index bfb950ff9..c3ac653f2 100644 --- a/js/ui/popupMenu.js +++ b/js/ui/popupMenu.js @@ -1516,15 +1516,30 @@ const PopupSubMenuMenuItem = new Lang.Class({ this.parent(); }, + setSubmenuShown: function(open) { + if (open) + this.menu.open(BoxPointer.PopupAnimation.FULL); + else + this.menu.close(BoxPointer.PopupAnimation.FULL); + }, + + _setOpenState: function(open) { + this._setSubmenuShown(open); + }, + + _getOpenState: function() { + return this.menu.isOpen; + }, + _onKeyPressEvent: function(actor, event) { let symbol = event.get_key_symbol(); if (symbol == Clutter.KEY_Right) { - this.menu.open(BoxPointer.PopupAnimation.FULL); + this._setOpenState(true); this.menu.actor.navigate_focus(null, Gtk.DirectionType.DOWN, false); return true; - } else if (symbol == Clutter.KEY_Left && this.menu.isOpen) { - this.menu.close(); + } else if (symbol == Clutter.KEY_Left && this._getOpenState()) { + this._setOpenState(false); return true; } @@ -1532,11 +1547,11 @@ const PopupSubMenuMenuItem = new Lang.Class({ }, activate: function(event) { - this.menu.open(BoxPointer.PopupAnimation.FULL); + this._setOpenState(true); }, _onButtonReleaseEvent: function(actor) { - this.menu.toggle(); + this._setOpenState(!this._getOpenState()); } }); diff --git a/js/ui/remoteMenu.js b/js/ui/remoteMenu.js index 09ae06659..144dbdb62 100644 --- a/js/ui/remoteMenu.js +++ b/js/ui/remoteMenu.js @@ -60,12 +60,31 @@ const RemoteMenuSeparatorItemMapper = new Lang.Class({ }, }); +const RequestSubMenu = new Lang.Class({ + Name: 'RequestSubMenu', + Extends: PopupMenu.PopupSubMenuMenuItem, + + _init: function() { + this.parent(''); + this._requestOpen = false; + }, + + _setOpenState: function(open) { + this.emit('request-open', open); + this._requestOpen = open; + }, + + _getOpenState: function() { + return this._requestOpen; + }, +}); + const RemoteMenuSubmenuItemMapper = new Lang.Class({ Name: 'RemoteMenuSubmenuItemMapper', _init: function(trackerItem) { this._trackerItem = trackerItem; - this.menuItem = new PopupMenu.PopupSubMenuMenuItem(''); + this.menuItem = new RequestSubMenu(); this._trackerItem.connect('notify::label', Lang.bind(this, this._updateLabel)); this._updateLabel(); @@ -73,6 +92,14 @@ const RemoteMenuSubmenuItemMapper = new Lang.Class({ _insertItem.bind(null, this.menuItem.menu), _removeItem.bind(null, this.menuItem.menu)); + this.menuItem.connect('request-open', Lang.bind(this, function(menu, open) { + this._trackerItem.request_submenu_shown(open); + })); + + this._trackerItem.connect('notify::submenu-shown', Lang.bind(this, function() { + this.menuItem.setSubmenuShown(this._trackerItem.get_submenu_shown()); + })); + this.menuItem.connect('destroy', function() { trackerItem.run_dispose(); });