@@ -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}