From 626e962e03bac6834ee04fe3be2df6e412f6a42e Mon Sep 17 00:00:00 2001 From: Giovanni Campagna Date: Mon, 17 Oct 2011 14:43:08 +0200 Subject: [PATCH] Network Menu: fix pulling out the first element from the More... submenu. PopupMenu.firstMenuItem returns a PopupMenuItem, not an apObj. We need to retrive the latter using the _apObj property. Also, somehow the property from the number of elements in a menu was changed from .length to .numMenuItems, and this broke the destruction of the menu upon emptying it. https://bugzilla.gnome.org/show_bug.cgi?id=659277 --- js/ui/status/network.js | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/js/ui/status/network.js b/js/ui/status/network.js index aa9b27759..435852d0f 100644 --- a/js/ui/status/network.js +++ b/js/ui/status/network.js @@ -1307,17 +1307,21 @@ NMDeviceWireless.prototype = { // we removed an item in the main menu, and we have a more submenu // we need to extract the first item in more and move it to the submenu - let apObj = this._overflowItem.menu.firstMenuItem; - if (apObj.item) { - apObj.item.destroy(); + let item = this._overflowItem.menu.firstMenuItem; + if (item && item._apObj) { + item.destroy(); + // clear the cycle, and allow the construction of the new item + item._apObj.item = null; - this._createNetworkItem(apObj, NUM_VISIBLE_NETWORKS-1); + this._createNetworkItem(item._apObj, NUM_VISIBLE_NETWORKS-1); + } else { + log('The more... menu was existing and empty! This should not happen'); } } // This can happen if the removed connection is from the overflow // menu, or if we just moved the last connection out from the menu - if (this._overflowItem.menu.length == 0) { + if (this._overflowItem.menu.numMenuItems == 0) { this._overflowItem.destroy(); this._overflowItem = null; } @@ -1494,18 +1498,16 @@ NMDeviceWireless.prototype = { } if(apObj.connections.length > 0) { - if (apObj.connections.length == 1) + if (apObj.connections.length == 1) { apObj.item = this._createAPItem(apObj.connections[0], apObj, false); - else { + } else { let title = apObj.ssidText; apObj.item = new PopupMenu.PopupSubMenuMenuItem(title); - apObj.item._apObj = apObj; for (let i = 0; i < apObj.connections.length; i++) apObj.item.menu.addMenuItem(this._createAPItem(apObj.connections[i], apObj, true)); } } else { apObj.item = new NMNetworkMenuItem(apObj.accessPoints); - apObj.item._apObj = apObj; apObj.item.connect('activate', Lang.bind(this, function() { let accessPoints = sortAccessPoints(apObj.accessPoints); if ( (accessPoints[0]._secType == NMAccessPointSecurity.WPA2_ENT) @@ -1520,6 +1522,8 @@ NMDeviceWireless.prototype = { } })); } + apObj.item._apObj = apObj; + if (position < NUM_VISIBLE_NETWORKS) { apObj.isMore = false; this.section.addMenuItem(apObj.item, position);