on xenial help sign in
merged with closeMenusOnClick
commit15bf2d05a3bfc7093db6441071760b1af7d178f9 authorNick Dedekind <nick.dedekind@canonical.com> dateMon 30 Jan 2017, 14:45 (10 years ago) parent20e4c2b76f6525
3 files changed+55−5
qml/ApplicationMenus/MenuBar.qml+1 qml/ApplicationMenus/MenuPopup.qml+19−5 tests/qmltests/ApplicationMenus/tst_MenuBar.qml+35
qml/ApplicationMenus/MenuBar.qml+1
@@ -119,6 +119,7 @@ Item {
119119 function show() {
120120 if (!__popup) {
121121 __popup = menuComponent.createObject(root, { objectName: visualItem.objectName + "-menu" });
122+ __popup.childActivated.connect(dismiss);
122123 // force the current item to be the newly popped up menu
123124 } else {
124125 __popup.show();
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 property alias unityMenuModel: repeater.model
3032
3133 function show() {
@@ -274,16 +276,22 @@ UbuntuShape {
274276 return mapToItem(container, 0, y).y;
275277 })
276278 });
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+ });
277289 } else if (popup) {
278290 popup.visible = true;
279291 }
280− popup.retreat.connect(function() {
281− popup.destroy();
282− popup = null;
283− menuItem.forceActiveFocus();
284− })
285292 } else {
286293 root.unityMenuModel.activate(__ownIndex);
294+ root.childActivated();
287295 }
288296 }
289297
@@ -399,6 +407,7 @@ UbuntuShape {
399407
400408 property var unityMenuModel: null
401409 signal retreat()
410+ signal childActivated()
402411
403412 Binding {
404413 target: item
@@ -414,6 +423,11 @@ UbuntuShape {
414423
415424 Keys.onLeftPressed: retreat()
416425
426+ Connections {
427+ target: item
428+ onChildActivated: childActivated();
429+ }
430+
417431 Component.onCompleted: item.select(0);
418432 onVisibleChanged: if (visible) { item.select(0); }
419433 }
tests/qmltests/ApplicationMenus/tst_MenuBar.qml+35
@@ -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