From 493844d0054f3df67ad01ae3151ecf8910da412c Mon Sep 17 00:00:00 2001 From: Giovanni Campagna Date: Mon, 20 Dec 2010 19:10:43 +0100 Subject: [PATCH] PopupMenu: fix addMenuItem with explicit position Only real menu items should be considered, fix this using the new API in StBoxLayout. https://bugzilla.gnome.org/show_bug.cgi?id=637681 --- js/ui/popupMenu.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/js/ui/popupMenu.js b/js/ui/popupMenu.js index c36e95684..91b412c03 100644 --- a/js/ui/popupMenu.js +++ b/js/ui/popupMenu.js @@ -631,15 +631,22 @@ PopupMenuBase.prototype = { }, addMenuItem: function(menuItem, position) { - if (position == undefined) + let before_item = null; + if (position == undefined) { this.box.add(menuItem.actor); - else - this.box.insert_actor(menuItem.actor, position); + } else { + let items = this.getMenuItems(); + if (position < items.length) { + before_item = items[position].actor; + this.box.insert_before(menuItem.actor, before_item); + } else + this.box.add(menuItem.actor); + } if (menuItem instanceof PopupSubMenuMenuItem) { - if (position == undefined) + if (before_item == null) this.box.add(menuItem.menu.actor); else - this.box.insert_actor(menuItem.menu.actor, position + 1); + this.box.insert_before(menuItem.menu.actor, before_item); menuItem._subMenuActivateId = menuItem.menu.connect('activate', Lang.bind(this, function() { this.emit('activate'); this.close(true);