summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/cocoa/qcocoamenu.mm
diff options
context:
space:
mode:
authorGabriel de Dietrich <gabriel.dedietrich@qt.io>2017-10-20 17:39:08 +0700
committerGabriel de Dietrich <gabriel.dedietrich@qt.io>2017-11-05 01:39:30 +0000
commit385589ef458715fcaa533bbd01ca421dc1040eba (patch)
tree1c7f88ee91ad1277e400a54aac252159e765c734 /src/plugins/platforms/cocoa/qcocoamenu.mm
parentb35a27676bec7f79761be83b2a7764ac0470e789 (diff)
QCocoaMenu: Attach menu items when updating the menubar
Instead of waiting for the menu delegate to update each item, we can attach an NSMenu to its NSMenuItem as soon as we update the current window's menubar. This is safe to do because we know that this is going to be the main menubar right after, so we're not orphaning any NSMenuItem from its NSMenu at the wrong moment. By doing this, we also ensure that all menus from the active menubar are reachable by the key-equivalent dispatching logic, even before we display the actual menu. This was shown in BigMenuCreator where, under the menubar's ASP and SAP menus, all A*S submenus would be disabled. Furthermore, on the same menus, SAP would show the same issue. Added test in Menurama as well. Change-Id: If6e7311072e6b53ad1cbced73623d1832aa0df8e Task-number: QTBUG-57076 Task-number: QTBUG-63712 Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
Diffstat (limited to 'src/plugins/platforms/cocoa/qcocoamenu.mm')
-rw-r--r--src/plugins/platforms/cocoa/qcocoamenu.mm16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoamenu.mm b/src/plugins/platforms/cocoa/qcocoamenu.mm
index 3a11023a4d..8bdd0512de 100644
--- a/src/plugins/platforms/cocoa/qcocoamenu.mm
+++ b/src/plugins/platforms/cocoa/qcocoamenu.mm
@@ -435,6 +435,11 @@ void QCocoaMenu::timerEvent(QTimerEvent *e)
void QCocoaMenu::syncMenuItem(QPlatformMenuItem *menuItem)
{
+ syncMenuItem_helper(menuItem, false /*menubarUpdate*/);
+}
+
+void QCocoaMenu::syncMenuItem_helper(QPlatformMenuItem *menuItem, bool menubarUpdate)
+{
QMacAutoReleasePool pool;
QCocoaMenuItem *cocoaItem = static_cast<QCocoaMenuItem *>(menuItem);
if (!m_menuItems.contains(cocoaItem)) {
@@ -444,8 +449,9 @@ void QCocoaMenu::syncMenuItem(QPlatformMenuItem *menuItem)
const bool wasMerged = cocoaItem->isMerged();
NSMenuItem *oldItem = cocoaItem->nsItem();
+ NSMenuItem *syncedItem = cocoaItem->sync();
- if (cocoaItem->sync() != oldItem) {
+ if (syncedItem != oldItem) {
// native item was changed for some reason
if (oldItem) {
if (wasMerged) {
@@ -463,6 +469,14 @@ void QCocoaMenu::syncMenuItem(QPlatformMenuItem *menuItem)
// when an item's enabled state changes after menuWillOpen:
scheduleUpdate();
}
+
+ // This may be a good moment to attach this item's eventual submenu to the
+ // synced item, but only on the condition we're all currently hooked to the
+ // menunbar. A good indicator of this being the right moment is knowing that
+ // we got called from QCocoaMenuBar::updateMenuBarImmediately().
+ if (menubarUpdate)
+ if (QCocoaMenu *submenu = cocoaItem->menu())
+ submenu->setAttachedItem(syncedItem);
}
void QCocoaMenu::syncSeparatorsCollapsible(bool enable)