on xenial help sign in
fixed menu navigation
commitf7a888f64636f017732da7983d11dd18f18c98c3 authorNick Dedekind <nick.dedekind@canonical.com> dateFri 7 Oct 2016, 11:01 (10 years ago) parent054e55e
6 files changed+72−56
qml/ApplicationMenus/MenuBarLoader.qml+21−16 qml/ApplicationMenus/MenuItemLoader.qml+2−1 qml/ApplicationMenus/MenuLoader.qml+31−15 qml/Panel/Panel.qml+6 tests/qmltests/ApplicationMenuDataLoader.qml+7−6 tests/qmltests/Panel/tst_Panel.qml+5−18
qml/ApplicationMenus/MenuBarLoader.qml+21−16
@@ -33,6 +33,10 @@ Item {
3333 implicitWidth: row.width + units.gu(1)
3434 height: parent.height
3535
36+ function dismiss() {
37+ d.dismissAll();
38+ }
39+
3640 WindowInputFilter {
3741 id: altFilter
3842 property bool altPressed: false
@@ -70,17 +74,7 @@ Item {
7074 acceptedButtons: Qt.LeftButton | Qt.MiddleButton | Qt.RightButton
7175 anchors.fill: parent
7276 enabled: d.currentItem != null
73− onPressed: {
74− if (d.currentItem) {
75− d.currentItem.dismiss();
76− }
77− }
78− }
79−
80− ActionContext {
81− id: menuBarContext
82− objectName: "menuBarContext"
83− active: true
77+ onPressed: d.dismissAll()
8478 }
8579
8680 Row {
@@ -89,6 +83,12 @@ Item {
8983 height: parent.height
9084 spacing: units.gu(2)
9185
86+ ActionContext {
87+ id: menuBarContext
88+ objectName: "barContext"
89+ active: !d.currentItem
90+ }
91+
9292 Repeater {
9393 id: rowRepeater
9494
@@ -108,7 +108,7 @@ Item {
108108
109109 function show() {
110110 if (!__popup) {
111− __popup = menuComponent.createObject(visualItem);
111+ __popup = menuComponent.createObject(root);
112112 } else {
113113 __popup.visible = true;
114114 }
@@ -126,10 +126,15 @@ Item {
126126 }
127127 }
128128
129+ Connections {
130+ target: d
131+ onDismissAll: visualItem.dismiss()
132+ }
133+
129134 Component {
130135 id: menuComponent
131136 MenuLoader {
132− x: -units.gu(1)
137+ x: visualItem.x - units.gu(1)
133138 anchors.top: parent.bottom
134139 unityMenuModel: root.unityMenuModel.submenu(visualItem.__index)
135140 }
@@ -203,6 +208,8 @@ Item {
203208 property Item hoveredItem: null
204209 property Item prevCurrentItem: null
205210
211+ signal dismissAll()
212+
206213 onCurrentItemChanged: {
207214 if (prevCurrentItem && prevCurrentItem != currentItem) {
208215 if (currentItem) {
@@ -238,8 +245,6 @@ Item {
238245 return false;
239246 if (d.currentItem != d.hoveredItem) {
240247 d.currentItem = d.hoveredItem;
241−// if (d.currentItem) d.currentItem.hide();
242−// if (d.hoveredItem) d.hoveredItem.show();
243248 }
244249 }
245250 return true;
@@ -247,7 +252,7 @@ Item {
247252 }
248253
249254 Keys.onEscapePressed: {
250− if (d.currentItem) d.currentItem.hide()
255+ d.dismissAll();
251256 event.accepted = true;
252257 }
253258
qml/ApplicationMenus/MenuItemLoader.qml+2−1
@@ -58,7 +58,8 @@ ActionItem {
5858 Keys.onRightPressed: {
5959 if (hasSubmenu) {
6060 root.trigger(action && action.checkable ? !action.checked : undefined);
61− event.accepted = true;
61+ } else {
62+ event.accepted = false;
6263 }
6364 }
6465 Keys.onEnterPressed: {
qml/ApplicationMenus/MenuLoader.qml+31−15
@@ -47,8 +47,15 @@ UbuntuShape {
4747 implicitHeight: MathUtils.clamp(listView.contentHeight, __ajustedMinimumHeight, __maximumHeight)
4848
4949 focus: true
50+
5051 Keys.onUpPressed: d.selectPrevious(d.currentIndex)
5152 Keys.onDownPressed: d.selectNext(d.currentIndex)
53+ Keys.onRightPressed: {
54+ // Don't let right keypresses fall through if the current item has a visible popup.
55+ if (!d.currentItem || !d.currentItem.popup || !d.currentItem.popup.visible) {
56+ event.accepted = false;
57+ }
58+ }
5259
5360 onVisibleChanged: {
5461 if (!visible) {
@@ -133,12 +140,6 @@ UbuntuShape {
133140 }
134141 }
135142
136− ActionContext {
137− id: menuContext
138− objectName: "menuContext"
139− active: true
140− }
141−
142143 ColumnLayout {
143144 id: container
144145 objectName: "container"
@@ -238,11 +239,26 @@ UbuntuShape {
238239 }
239240 }
240241
242+ ActionContext {
243+ id: menuBarContext
244+ objectName: "menuContext"
245+ active: {
246+ if (!root.visible) return false;
247+ if (d.currentItem && d.currentItem.popup && d.currentItem.popup.visible) {
248+ return false;
249+ }
250+ return true;
251+ }
252+ }
253+
241254 delegate: Loader {
242255 id: loader
243− width: root.width
244256
257+ property int __ownIndex: index
258+
259+ width: root.width
245260 enabled: model.isSeparator ? false : model.sensitive
261+ Keys.forwardTo: [ item ]
246262
247263 sourceComponent: {
248264 if (model.isSeparator) {
@@ -250,9 +266,8 @@ UbuntuShape {
250266 }
251267 return menuItemComponent;
252268 }
253− property int __ownIndex: index
254269
255− Keys.forwardTo: [ item ]
270+ property Item popup: null
256271
257272 Component {
258273 id: menuItemComponent
@@ -260,9 +275,9 @@ UbuntuShape {
260275 id: menuItem
261276 menuData: model
262277
263− property Item popup: null
264−
265278 action.onTriggered: {
279+ d.currentItem = loader;
280+
266281 if (hasSubmenu) {
267282 if (!popup) {
268283 var model = root.unityMenuModel.submenu(__ownIndex);
@@ -288,8 +303,8 @@ UbuntuShape {
288303 Connections {
289304 target: d
290305 onCurrentIndexChanged: {
291− if (menuItem.popup && d.currentIndex != __ownIndex) {
292− menuItem.popup.visible = false;
306+ if (popup && d.currentIndex != __ownIndex) {
307+ popup.visible = false;
293308 }
294309 }
295310 }
@@ -302,7 +317,6 @@ UbuntuShape {
302317 }
303318 }
304319 }
305−
306320 } // ListView
307321
308322 // FIXME use ListView.footer - tried but was flaky with positionViewAtIndex.
@@ -358,8 +372,10 @@ UbuntuShape {
358372 value: submenuLoader.unityMenuModel
359373 }
360374
361− onLoaded: item.select(0)
362375 Keys.onLeftPressed: dismiss()
376+
377+ Component.onCompleted: item.select(0);
378+ onVisibleChanged: if (visible) { item.select(0); }
363379 }
364380 }
365381}
qml/Panel/Panel.qml+6
@@ -337,9 +337,15 @@ Item {
337337 property bool menusRequested: menuBarLoader.item ? menuBarLoader.item.showRequested : false
338338
339339 sourceComponent: MenuBarLoader {
340+ id: bar
340341 height: menuBarLoader.height
341342 enableKeyFilter: valid && PanelState.decorationsVisible
342343 unityMenuModel: fakeApplicationMenus.model
344+
345+ Connections {
346+ target: fakeApplicationMenus
347+ onHide: bar.dismiss();
348+ }
343349 }
344350 }
345351
tests/qmltests/ApplicationMenuDataLoader.qml+7−6
@@ -11,15 +11,16 @@ Object {
1111 var fakeMenuPath = "/" + surface.persistentId.replace(/\W+/g, "");
1212
1313 ApplicationMenuRegistry.RegisterSurfaceMenu(surface.persistentId, fakeMenuPath, fakeMenuPath, ":1");
14− Indicators.UnityMenuModelCache.setCachedModelData(fakeMenuPath, generateTestData(5, 3, 3, "menu"));
14+ Indicators.UnityMenuModelCache.setCachedModelData(fakeMenuPath, generateTestData(5, 3, 2, 3, "menu"));
1515 }
1616 onSurfaceDestroyed: {
1717 ApplicationMenuRegistry.UnregisterSurfaceMenu(persistentSurfaceId, "/app");
1818 }
1919 }
2020
21− function generateTestData(length, depth, separatorInterval, prefix) {
21+ function generateTestData(length, depth, submenuInterval, separatorInterval, prefix, root) {
2222 var data = [];
23+ if (root === undefined) root = true;
2324
2425 if (prefix === undefined) prefix = "menu"
2526
@@ -27,7 +28,7 @@ Object {
2728
2829 var menuCode = String.fromCharCode(i+65);
2930
30− var isSeparator = separatorInterval > 0 && ((i+1) % separatorInterval == 0);
31+ var isSeparator = !root && separatorInterval > 0 && ((i+1) % separatorInterval == 0);
3132 var row = {
3233 "rowData": { // 1
3334 "label": prefix + "&" + menuCode,
@@ -43,9 +44,9 @@ Object {
4344 "shortcut": ""
4445 }
4546 }
46− if (!isSeparator && depth > 1) {
47− var submenu = generateTestData(length, depth-1, separatorInterval, prefix + menuCode + ".");
48− row["submenu"] = submenu;
47+ var isSubmenu = root === undefined || root === true || (submenuInterval > 0 && ((i+1) % submenuInterval == 0));
48+ if (isSubmenu && !isSeparator && depth > 1) {
49+ row["submenu"] = generateTestData(length, depth-1, submenuInterval, separatorInterval, prefix + menuCode + ".", false);
4950 }
5051 data[i] = row;
5152 }
tests/qmltests/Panel/tst_Panel.qml+5−18
@@ -21,8 +21,7 @@ import Unity.Test 0.1
2121import Ubuntu.Components 1.3
2222import Ubuntu.Components.ListItems 1.3 as ListItem
2323import Unity.Application 0.1
24−import Unity.ApplicationMenu 0.1
25−import Unity.Indicators 0.1 as Indicators
24+import QMenuModel 0.1
2625import Ubuntu.Telephony 0.1 as Telephony
2726import AccountsService 0.1
2827import Unity.InputInfo 0.1
@@ -80,7 +79,10 @@ PanelTest {
8079 applicationMenuWidth: parent.width > units.gu(60) ? units.gu(40) : parent.width
8180
8281 applicationMenus {
83− model: sharedAppModel.model
82+ model: UnityMenuModel {
83+ modelData: appMenuData.generateTestData(5, 4, 2, 3, "menu")
84+ }
85+
8486 hides: [ panel.indicators ]
8587 }
8688
@@ -88,14 +90,6 @@ PanelTest {
8890 model: root.indicatorsModel
8991 hides: [ panel.applicationMenus ]
9092 }
91−
92− Indicators.SharedUnityMenuModel {
93− id: sharedAppModel
94−
95− busName: ":1"
96− menuObjectPath: "/DialerswindowtitleId"
97− actions: { "unity": "/DialerswindowtitleId" }
98− }
9993 }
10094 }
10195 }
@@ -175,13 +169,6 @@ PanelTest {
175169 color: "black"
176170 }
177171
178− ApplicationCheckBox {
179− id: applicationCheckBox
180− Layout.fillWidth: true
181− appId: "dialer-app"
182− onCheckedChanged: PanelState.focusedPersistentSurfaceId = checked ? "Dialers window titleId" : "";
183− }
184−
185172 Rectangle {
186173 Layout.preferredHeight: units.dp(1);
187174 Layout.fillWidth: true;