[gnome-shell] PopupMenu: fix addMenuItem with explicit position



commit 493844d0054f3df67ad01ae3151ecf8910da412c
Author: Giovanni Campagna <gcampagna src gnome org>
Date:   Mon Dec 20 19:10:43 2010 +0100

    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 files changed, 12 insertions(+), 5 deletions(-)
---
diff --git a/js/ui/popupMenu.js b/js/ui/popupMenu.js
index c36e956..91b412c 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);



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