[gnome-shell/wip/gtkmenutrackeritem: 9/9] remoteMenu: Re-add support for remote submenus
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell/wip/gtkmenutrackeritem: 9/9] remoteMenu: Re-add support for remote submenus
- Date: Thu, 9 May 2013 21:52:07 +0000 (UTC)
commit b504463a064695be7c2ab524347a77f702b72585
Author: Jasper St. Pierre <jstpierre mecheye net>
Date: Thu May 9 17:32:52 2013 -0400
remoteMenu: Re-add support for remote submenus
js/ui/remoteMenu.js | 82 ++++++++++++++++++++++++++++++++++++--------------
1 files changed, 59 insertions(+), 23 deletions(-)
---
diff --git a/js/ui/remoteMenu.js b/js/ui/remoteMenu.js
index 13b6e4a..3ebebc5 100644
--- a/js/ui/remoteMenu.js
+++ b/js/ui/remoteMenu.js
@@ -34,6 +34,30 @@ const RemoteMenuSeparatorItemMapper = new Lang.Class({
},
});
+const RemoteMenuSubmenuItemMapper = new Lang.Class({
+ Name: 'RemoteMenuSubmenuItemMapper',
+
+ _init: function(trackerItem) {
+ this._trackerItem = trackerItem;
+ this.menuItem = new PopupMenu.PopupSubMenuMenuItem('');
+ this._trackerItem.connect('notify::label', Lang.bind(this, this._updateLabel));
+ this._updateLabel();
+
+ this._tracker = new RemoteMenuTracker(this._trackerItem.get_observable(),
+ this._trackerItem.get_submenu(),
+ this.menuItem.menu);
+ },
+
+ destroy: function() {
+ this._tracker.destroy();
+ this.parent();
+ },
+
+ _updateLabel: function() {
+ this.menuItem.label.text = stripMnemonics(this._trackerItem.label);
+ },
+});
+
const RemoteMenuItemMapper = new Lang.Class({
Name: 'RemoteMenuItemMapper',
@@ -94,47 +118,59 @@ const RemoteMenuItemMapper = new Lang.Class({
},
});
-const RemoteMenu = new Lang.Class({
- Name: 'RemoteMenu',
- Extends: PopupMenu.PopupMenu,
-
- _init: function(sourceActor, model, actionGroup) {
- this.parent(sourceActor, 0.0, St.Side.TOP);
-
- this._model = model;
- this._actionGroup = actionGroup;
- this._trackMenu(model, this);
- },
+const RemoteMenuTracker = new Lang.Class({
+ Name: 'RemoteMenuTracker',
- _trackMenu: function(model, item) {
- item._tracker = Shell.MenuTracker.new(this._actionGroup,
+ _init: function(actionGroup, model, menu) {
+ this._menu = menu;
+ this._tracker = Shell.MenuTracker.new(actionGroup,
model,
null, /* action namespace */
- Lang.bind(this, this._insertItem, item),
- Lang.bind(this, this._removeItem, item));
+ Lang.bind(this, this._insertItem),
+ Lang.bind(this, this._removeItem));
+ },
- item.connect('destroy', function() {
- item._tracker.destroy();
- item._tracker = null;
- });
+ destroy: function() {
+ this._tracker.destroy();
+ this._tracker = null;
},
- _insertItem: function(trackerItem, position, target) {
+ _insertItem: function(trackerItem, position) {
let item;
if (trackerItem.get_is_separator()) {
let mapper = new RemoteMenuSeparatorItemMapper(trackerItem);
item = mapper.menuItem;
+ } else if (trackerItem.get_submenu()) {
+ let mapper = new RemoteMenuSubmenuItemMapper(trackerItem);
+ item = mapper.menuItem;
} else {
let mapper = new RemoteMenuItemMapper(trackerItem);
item = mapper.menuItem;
}
- target.addMenuItem(item, position);
+ this._menu.addMenuItem(item, position);
},
- _removeItem: function(position, target) {
- let items = target._getMenuItems();
+ _removeItem: function(position) {
+ let items = this._menu._getMenuItems();
items[position].destroy();
},
});
+
+const RemoteMenu = new Lang.Class({
+ Name: 'RemoteMenu',
+ Extends: PopupMenu.PopupMenu,
+
+ _init: function(sourceActor, model, actionGroup) {
+ this.parent(sourceActor, 0.0, St.Side.TOP);
+
+ this._model = model;
+ this._tracker = new RemoteMenuTracker(actionGroup, model, this);
+ },
+
+ destroy: function() {
+ this._tracker.destroy();
+ this.parent();
+ }
+});
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]