on xenial help sign in
Fixed focus issues
94dd7a5Nick Dedekind
qml/ApplicationMenus/MenuBar.qml+2−3
@@ -102,13 +102,13 @@ Item {
102 __popup = menuComponent.createObject(root, { objectName: visualItem.objectName + "-menu" });
102 __popup = menuComponent.createObject(root, { objectName: visualItem.objectName + "-menu" });
103 // force the current item to be the newly popped up menu
103 // force the current item to be the newly popped up menu
104 } else {
104 } else {
105− __popup.visible = true;
105+ __popup.show();
106 }
106 }
107 d.currentItem = visualItem;
107 d.currentItem = visualItem;
108 }
108 }
109 function hide() {
109 function hide() {
110 if (__popup) {
110 if (__popup) {
111− __popup.visible = false;
111+ __popup.hide();
112
112
113 if (d.currentItem === visualItem) {
113 if (d.currentItem === visualItem) {
114 d.currentItem = null;
114 d.currentItem = null;
@@ -139,7 +139,6 @@ Item {
139 unityMenuModel: root.unityMenuModel.submenu(visualItem.__ownIndex)
139 unityMenuModel: root.unityMenuModel.submenu(visualItem.__ownIndex)
140
140
141 Component.onCompleted: reset();
141 Component.onCompleted: reset();
142− onVisibleChanged: if (visible) { reset(); }
143 }
142 }
144 }
143 }
145
144
qml/ApplicationMenus/MenuPopup.qml+22−16
@@ -40,27 +40,32 @@ UbuntuShape {
40 readonly property real __maximumWidth: Screen.width * 0.7
40 readonly property real __maximumWidth: Screen.width * 0.7
41 readonly property real __maximumHeight: Screen.height * 0.7
41 readonly property real __maximumHeight: Screen.height * 0.7
42
42
43+ function show() {
44+ visible = true;
45+ focusScope.forceActiveFocus();
46+ }
47+
48+ function hide() {
49+ visible = false;
50+ d.currentItem = null;
51+ }
52+
43 function select(index) {
53 function select(index) {
44 d.select(index)
54 d.select(index)
45 }
55 }
46
56
47 function reset() {
57 function reset() {
48 d.currentItem = null;
58 d.currentItem = null;
59+ dismiss();
49 }
60 }
50
61
51 function dismiss() {
62 function dismiss() {
52− d.dismissAll()
63+ d.dismissAll();
53 }
64 }
54
65
55 implicitWidth: container.width
66 implicitWidth: container.width
56 implicitHeight: MathUtils.clamp(listView.contentHeight, __ajustedMinimumHeight, __maximumHeight)
67 implicitHeight: MathUtils.clamp(listView.contentHeight, __ajustedMinimumHeight, __maximumHeight)
57
68
58− onVisibleChanged: {
59− if (!visible) {
60− d.currentItem = null;
61− }
62− }
63−
64 MenuNavigator {
69 MenuNavigator {
65 id: d
70 id: d
66 objectName: "d"
71 objectName: "d"
@@ -85,7 +90,7 @@ UbuntuShape {
85 }
90 }
86 }
91 }
87
92
88− FocusScope {
93+ Item {
89 id: focusScope
94 id: focusScope
90 anchors.fill: parent
95 anchors.fill: parent
91 focus: visible
96 focus: visible
@@ -250,7 +255,7 @@ UbuntuShape {
250 } else if (popup) {
255 } else if (popup) {
251 popup.visible = true;
256 popup.visible = true;
252 }
257 }
253− popup.dismiss.connect(function() {
258+ popup.retreat.connect(function() {
254 popup.destroy();
259 popup.destroy();
255 popup = null;
260 popup = null;
256 menuItem.forceActiveFocus();
261 menuItem.forceActiveFocus();
@@ -267,6 +272,12 @@ UbuntuShape {
267 popup.visible = false;
272 popup.visible = false;
268 }
273 }
269 }
274 }
275+ onDismissAll: {
276+ if (popup) {
277+ popup.destroy();
278+ popup = null;
279+ }
280+ }
270 }
281 }
271 }
282 }
272 }
283 }
@@ -325,7 +336,7 @@ UbuntuShape {
325 source: "MenuPopup.qml"
336 source: "MenuPopup.qml"
326
337
327 property var unityMenuModel: null
338 property var unityMenuModel: null
328− signal dismiss()
339+ signal retreat()
329
340
330 Binding {
341 Binding {
331 target: item
342 target: item
@@ -339,12 +350,7 @@ UbuntuShape {
339 value: submenuLoader.objectName + "menu"
350 value: submenuLoader.objectName + "menu"
340 }
351 }
341
352
342− Connections {
343− target: d
344− onDismissAll: submenuLoader.dismiss()
345− }
346−
347− Keys.onLeftPressed: dismiss()
353+ Keys.onLeftPressed: retreat()
348
354
349 Component.onCompleted: item.select(0);
355 Component.onCompleted: item.select(0);
350 onVisibleChanged: if (visible) { item.select(0); }
356 onVisibleChanged: if (visible) { item.select(0); }
tests/qmltests/ApplicationMenus/tst_MenuPopup.qml+5−2
@@ -41,7 +41,6 @@ Item {
41
41
42 MenuPopup {
42 MenuPopup {
43 id: page
43 id: page
44− focus: true
45
44
46 anchors {
45 anchors {
47 left: parent.left
46 left: parent.left
@@ -68,7 +67,11 @@ Item {
68 when: windowShown
67 when: windowShown
69
68
70 function init() {
69 function init() {
71− page.dismiss();
70+ page.show();
71+ }
72+
73+ function cleanup() {
74+ page.reset();
72 wait(100); // let the page dismiss
75 wait(100); // let the page dismiss
73 activatedSpy.clear();
76 activatedSpy.clear();
74 }
77 }