on xenial help sign in
Make sure we destroy the popups when the item goes away

Another way of doing this would be changing the parent in the createObject calls but if we change that we have to change the x,y logic and since that's quite delicate i decided to go the easy route to not cause regressions (LP: #1670338) Approved by: Lukáš Tinkl, Unity8 CI Bot

commitab451353db4bcb72a23a827275882a13bc46e08e authorAlbert Astals Cid <albert.astals@canonical.com> dateTue 28 Mar 2017, 21:45 (10 years ago) parent66efbd0fa66182
3 files changed+42−1
qml/ApplicationMenus/MenuBar.qml+7 qml/ApplicationMenus/MenuPopup.qml+10−1 tests/qmltests/ApplicationMenus/tst_MenuBar.qml+25
qml/ApplicationMenus/MenuBar.qml+7
@@ -230,6 +230,13 @@ Item {
230230 }
231231 }
232232 }
233+
234+ Component.onDestruction: {
235+ if (__popup) {
236+ __popup.destroy();
237+ __popup = null;
238+ }
239+ }
233240 } // Item ( delegate )
234241 } // Repeater
235242 } // Row
qml/ApplicationMenus/MenuPopup.qml+10−1
@@ -297,6 +297,8 @@ UbuntuShape {
297297
298298 width: MathUtils.clamp(implicitWidth, d.__minimumWidth, d.__maximumWidth)
299299
300+ property Item popup: null
301+
300302 action.onTriggered: {
301303 submenuHoverTimer.stop();
302304
@@ -351,6 +353,13 @@ UbuntuShape {
351353 }
352354 }
353355 }
356+
357+ Component.onDestruction: {
358+ if (popup) {
359+ popup.destroy();
360+ popup = null;
361+ }
362+ }
354363 }
355364 }
356365
@@ -373,7 +382,7 @@ UbuntuShape {
373382 id: loader
374383 objectName: root.objectName + "-item" + __ownIndex
375384
376− property Item popup: null
385+ readonly property var popup: item ? item.popup : null
377386 property var __menuData: model
378387 property int __ownIndex: index
379388 property bool __isSeparator: model.isSeparator
tests/qmltests/ApplicationMenus/tst_MenuBar.qml+25
@@ -339,6 +339,31 @@ Item {
339339 }, true);
340340 }
341341
342+ function test_stray_submenus() {
343+ menuBackend.modelData = appMenuData.generateTestData(3,4,1,0,"menu");
344+ var priv = findInvisibleChild(menuBar, "d");
345+
346+ var menuItem = findChild(menuBar, "menuBar-item0");
347+ menuItem.show();
348+ compare(priv.currentItem, menuItem, "CurrentItem should be set to item 0");
349+ compare(priv.currentItem.popupVisible, true, "Popup should be visible");
350+
351+ var actionItem = findChild(menuBar, "menuBar-item0-menu-item0-actionItem");
352+ mouseClick(actionItem);
353+
354+ actionItem = findChild(menuBar, "menuBar-item0-menu-item0-menu-item0-actionItem");
355+ mouseClick(actionItem);
356+
357+ actionItem = findChild(menuBar, "menuBar-item0-menu-item0-menu-item0-menu-item0-actionItem");
358+
359+ // There's one popup
360+ tryCompareFunction(function() { return findChildsByType(root, "MenuPopup").length; }, 3);
361+
362+ menuBackend.modelData = null;
363+
364+ tryCompareFunction(function() { return findChildsByType(root, "MenuPopup").length; }, 0);
365+ }
366+
342367 function test_firstDisabled() {
343368 var data = appMenuData.generateTestData(10,5,2,3);
344369 data[0].submenu[1].submenu[0].rowData.sensitive = false;