on xenial help sign in
merged with closeMenusOnClick
15bf2d0Nick Dedekind
qml/ApplicationMenus/MenuBar.qml+1
@@ -119,6 +119,7 @@ Item {
119 function show() {
119 function show() {
120 if (!__popup) {
120 if (!__popup) {
121 __popup = menuComponent.createObject(root, { objectName: visualItem.objectName + "-menu" });
121 __popup = menuComponent.createObject(root, { objectName: visualItem.objectName + "-menu" });
122+ __popup.childActivated.connect(dismiss);
122 // force the current item to be the newly popped up menu
123 // force the current item to be the newly popped up menu
123 } else {
124 } else {
124 __popup.show();
125 __popup.show();
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 property alias unityMenuModel: repeater.model
31 property alias unityMenuModel: repeater.model
30
32
31 function show() {
33 function show() {
@@ -274,16 +276,22 @@ UbuntuShape {
274 return mapToItem(container, 0, y).y;
276 return mapToItem(container, 0, y).y;
275 })
277 })
276 });
278 });
279+ popup.retreat.connect(function() {
280+ popup.destroy();
281+ popup = null;
282+ menuItem.forceActiveFocus();
283+ });
284+ popup.childActivated.connect(function() {
285+ popup.destroy();
286+ popup = null;
287+ root.childActivated();
288+ });
277 } else if (popup) {
289 } else if (popup) {
278 popup.visible = true;
290 popup.visible = true;
279 }
291 }
280− popup.retreat.connect(function() {
281− popup.destroy();
282− popup = null;
283− menuItem.forceActiveFocus();
284− })
285 } else {
292 } else {
286 root.unityMenuModel.activate(__ownIndex);
293 root.unityMenuModel.activate(__ownIndex);
294+ root.childActivated();
287 }
295 }
288 }
296 }
289
297
@@ -399,6 +407,7 @@ UbuntuShape {
399
407
400 property var unityMenuModel: null
408 property var unityMenuModel: null
401 signal retreat()
409 signal retreat()
410+ signal childActivated()
402
411
403 Binding {
412 Binding {
404 target: item
413 target: item
@@ -414,6 +423,11 @@ UbuntuShape {
414
423
415 Keys.onLeftPressed: retreat()
424 Keys.onLeftPressed: retreat()
416
425
426+ Connections {
427+ target: item
428+ onChildActivated: childActivated();
429+ }
430+
417 Component.onCompleted: item.select(0);
431 Component.onCompleted: item.select(0);
418 onVisibleChanged: if (visible) { item.select(0); }
432 onVisibleChanged: if (visible) { item.select(0); }
419 }
433 }
tests/qmltests/ApplicationMenus/tst_MenuBar.qml+35
@@ -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