on xenial help sign in
Merge
commitb6b936742c9a3a1eda669756bf6c23b2e0512066 authorAlbert Astals Cid <albert.astals@canonical.com> dateThu 26 Jan 2017, 10:30 (10 years ago) parent7d03beb48c3c78
3 files changed+77−6
qml/ApplicationMenus/MenuBar.qml+8−1 qml/ApplicationMenus/MenuPopup.qml+19−5 tests/qmltests/ApplicationMenus/tst_MenuBar.qml+50
qml/ApplicationMenus/MenuBar.qml+8−1
@@ -114,6 +114,7 @@ Item {
114114 function show() {
115115 if (!__popup) {
116116 __popup = menuComponent.createObject(root, { objectName: visualItem.objectName + "-menu" });
117+ __popup.childActivated.connect(dismiss);
117118 // force the current item to be the newly popped up menu
118119 } else {
119120 __popup.show();
@@ -212,7 +213,13 @@ Item {
212213 updateCurrentItemFromPosition(Qt.point(mouse.x, mouse.y))
213214 }
214215 }
215− onClicked: updateCurrentItemFromPosition(Qt.point(mouse.x, mouse.y))
216+ onClicked: {
217+ var prevItem = d.currentItem;
218+ updateCurrentItemFromPosition(Qt.point(mouse.x, mouse.y))
219+ if (prevItem && d.currentItem == prevItem) {
220+ prevItem.hide();
221+ }
222+ }
216223
217224 function updateCurrentItemFromPosition(point) {
218225 var pos = mapToItem(row, point.x, point.y);
qml/ApplicationMenus/MenuPopup.qml+19−5
@@ -26,6 +26,8 @@ UbuntuShape {
2626 objectName: "menu"
2727 backgroundColor: theme.palette.normal.overlay
2828
29+ signal childActivated()
30+
2931 // true for submenus that need to show on the other side of their parent
3032 // if they don't fit when growing right
3133 property bool substractWidth: false
@@ -307,16 +309,22 @@ UbuntuShape {
307309 return mapToItem(container, 0, y).y;
308310 })
309311 });
312+ popup.retreat.connect(function() {
313+ popup.destroy();
314+ popup = null;
315+ menuItem.forceActiveFocus();
316+ });
317+ popup.childActivated.connect(function() {
318+ popup.destroy();
319+ popup = null;
320+ root.childActivated();
321+ });
310322 } else if (popup) {
311323 popup.visible = true;
312324 }
313− popup.retreat.connect(function() {
314− popup.destroy();
315− popup = null;
316− menuItem.forceActiveFocus();
317− })
318325 } else {
319326 root.unityMenuModel.activate(__ownIndex);
327+ root.childActivated();
320328 }
321329 }
322330
@@ -424,6 +432,7 @@ UbuntuShape {
424432 property bool substractWidth
425433 property var unityMenuModel: null
426434 signal retreat()
435+ signal childActivated()
427436
428437 onLoaded: {
429438 item.unityMenuModel = Qt.binding(function() { return submenuLoader.unityMenuModel; });
@@ -435,6 +444,11 @@ UbuntuShape {
435444
436445 Keys.onLeftPressed: retreat()
437446
447+ Connections {
448+ target: item
449+ onChildActivated: childActivated();
450+ }
451+
438452 Component.onCompleted: item.select(0);
439453 onVisibleChanged: if (visible) { item.select(0); }
440454 }
tests/qmltests/ApplicationMenus/tst_MenuBar.qml+50
@@ -180,6 +180,41 @@ Item {
180180 tryCompare(priv, "currentItem", menuItem);
181181 }
182182
183+ function test_menuActivateClosesMenu() {
184+ menuBackend.modelData = appMenuData.generateTestData(3,3,0,0,"menu");
185+ var priv = findInvisibleChild(menuBar, "d");
186+
187+ var menuItem = findChild(menuBar, "menuBar-item0");
188+ menuItem.show();
189+ compare(priv.currentItem, menuItem, "CurrentItem should be set to item 0");
190+ compare(priv.currentItem.popupVisible, true, "Popup should be visible");
191+
192+ var actionItem = findChild(menuBar, "menuBar-item0-menu-item0-actionItem");
193+ mouseClick(actionItem);
194+ compare(priv.currentItem, null, "CurrentItem should be null");
195+ }
196+
197+ function test_subMenuActivateClosesMenu() {
198+ menuBackend.modelData = appMenuData.generateTestData(3,4,1,0,"menu");
199+ var priv = findInvisibleChild(menuBar, "d");
200+
201+ var menuItem = findChild(menuBar, "menuBar-item0");
202+ menuItem.show();
203+ compare(priv.currentItem, menuItem, "CurrentItem should be set to item 0");
204+ compare(priv.currentItem.popupVisible, true, "Popup should be visible");
205+
206+ var actionItem = findChild(menuBar, "menuBar-item0-menu-item0-actionItem");
207+ mouseClick(actionItem);
208+
209+ actionItem = findChild(menuBar, "menuBar-item0-menu-item0-menu-item0-actionItem");
210+ mouseClick(actionItem);
211+
212+ actionItem = findChild(menuBar, "menuBar-item0-menu-item0-menu-item0-menu-item0-actionItem");
213+ mouseClick(actionItem);
214+
215+ compare(priv.currentItem, null, "CurrentItem should be null");
216+ }
217+
183218 function test_openAppMenuShortcut() {
184219 var priv = findInvisibleChild(menuBar, "d");
185220
@@ -192,5 +227,20 @@ Item {
192227 keyClick(Qt.Key_F10, Qt.AltModifier);
193228 compare(priv.currentItem, menuItem1, "First enabled item should be opened");
194229 }
230+
231+ function test_clickOpenMenuClosesMenu() {
232+ menuBackend.modelData = appMenuData.generateTestData(3,3,0,0,"menu");
233+ var priv = findInvisibleChild(menuBar, "d");
234+
235+ var menuItem = findChild(menuBar, "menuBar-item0");
236+ waitForRendering(menuItem);
237+ mouseClick(menuItem);
238+ compare(priv.currentItem, menuItem, "CurrentItem should be set to item 0");
239+ compare(priv.currentItem.popupVisible, true, "Popup should be visible");
240+
241+ waitForRendering(menuItem);
242+ mouseClick(menuItem);
243+ compare(priv.currentItem, null, "CurrentItem should be null");
244+ }
195245 }
196246}