on xenial help sign in
Merge clickOpenMenuClosesIt
48c3c78Albert Astals Cid
qml/ApplicationMenus/MenuBar.qml+8−1
@@ -114,6 +114,7 @@ Item {
114 function show() {
114 function show() {
115 if (!__popup) {
115 if (!__popup) {
116 __popup = menuComponent.createObject(root, { objectName: visualItem.objectName + "-menu" });
116 __popup = menuComponent.createObject(root, { objectName: visualItem.objectName + "-menu" });
117+ __popup.childActivated.connect(dismiss);
117 // force the current item to be the newly popped up menu
118 // force the current item to be the newly popped up menu
118 } else {
119 } else {
119 __popup.show();
120 __popup.show();
@@ -212,7 +213,13 @@ Item {
212 updateCurrentItemFromPosition(Qt.point(mouse.x, mouse.y))
213 updateCurrentItemFromPosition(Qt.point(mouse.x, mouse.y))
213 }
214 }
214 }
215 }
216+ onClicked: {
217+ var prevItem = d.currentItem;
215− onClicked: updateCurrentItemFromPosition(Qt.point(mouse.x, mouse.y))
218+ updateCurrentItemFromPosition(Qt.point(mouse.x, mouse.y))
219+ if (prevItem && d.currentItem == prevItem) {
220+ prevItem.hide();
221+ }
222+ }
216
223
217 function updateCurrentItemFromPosition(point) {
224 function updateCurrentItemFromPosition(point) {
218 var pos = mapToItem(row, point.x, point.y);
225 var pos = mapToItem(row, point.x, point.y);
qml/ApplicationMenus/MenuPopup.qml+19−5
@@ -26,6 +26,8 @@ UbuntuShape {
26 objectName: "menu"
26 objectName: "menu"
27 backgroundColor: theme.palette.normal.overlay
27 backgroundColor: theme.palette.normal.overlay
28
28
29+ signal childActivated()
30+
29 // true for submenus that need to show on the other side of their parent
31 // true for submenus that need to show on the other side of their parent
30 // if they don't fit when growing right
32 // if they don't fit when growing right
31 property bool substractWidth: false
33 property bool substractWidth: false
@@ -296,16 +298,22 @@ UbuntuShape {
296 return mapToItem(container, 0, y).y;
298 return mapToItem(container, 0, y).y;
297 })
299 })
298 });
300 });
301+ popup.retreat.connect(function() {
302+ popup.destroy();
303+ popup = null;
304+ menuItem.forceActiveFocus();
305+ });
306+ popup.childActivated.connect(function() {
307+ popup.destroy();
308+ popup = null;
309+ root.childActivated();
310+ });
299 } else if (popup) {
311 } else if (popup) {
300 popup.visible = true;
312 popup.visible = true;
301 }
313 }
302− popup.retreat.connect(function() {
303− popup.destroy();
304− popup = null;
305− menuItem.forceActiveFocus();
306− })
307 } else {
314 } else {
308 root.unityMenuModel.activate(__ownIndex);
315 root.unityMenuModel.activate(__ownIndex);
316+ root.childActivated();
309 }
317 }
310 }
318 }
311
319
@@ -413,6 +421,7 @@ UbuntuShape {
413 property bool substractWidth
421 property bool substractWidth
414 property var unityMenuModel: null
422 property var unityMenuModel: null
415 signal retreat()
423 signal retreat()
424+ signal childActivated()
416
425
417 onLoaded: {
426 onLoaded: {
418 item.unityMenuModel = Qt.binding(function() { return submenuLoader.unityMenuModel; });
427 item.unityMenuModel = Qt.binding(function() { return submenuLoader.unityMenuModel; });
@@ -424,6 +433,11 @@ UbuntuShape {
424
433
425 Keys.onLeftPressed: retreat()
434 Keys.onLeftPressed: retreat()
426
435
436+ Connections {
437+ target: item
438+ onChildActivated: childActivated();
439+ }
440+
427 Component.onCompleted: item.select(0);
441 Component.onCompleted: item.select(0);
428 onVisibleChanged: if (visible) { item.select(0); }
442 onVisibleChanged: if (visible) { item.select(0); }
429 }
443 }
tests/qmltests/ApplicationMenus/tst_MenuBar.qml+50
@@ -180,6 +180,41 @@ Item {
180 tryCompare(priv, "currentItem", menuItem);
180 tryCompare(priv, "currentItem", menuItem);
181 }
181 }
182
182
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+
183 function test_openAppMenuShortcut() {
218 function test_openAppMenuShortcut() {
184 var priv = findInvisibleChild(menuBar, "d");
219 var priv = findInvisibleChild(menuBar, "d");
185
220
@@ -192,5 +227,20 @@ Item {
192 keyClick(Qt.Key_F10, Qt.AltModifier);
227 keyClick(Qt.Key_F10, Qt.AltModifier);
193 compare(priv.currentItem, menuItem1, "First enabled item should be opened");
228 compare(priv.currentItem, menuItem1, "First enabled item should be opened");
194 }
229 }
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+ }
195 }
245 }
196}
246}