From 8c538d10da618add00aba1acbc8d8dc2f24445b4 Mon Sep 17 00:00:00 2001 From: Timur Pocheptsov Date: Fri, 10 Oct 2014 14:00:44 +0200 Subject: OS X: rename special menu items instead of duplicating Two-part fix: QCocoaMenu::syncMenuItem, when selecting the "old" menu, if an item was merged, 'applicationMenu' was always selected, but this is wrong for any item with a role >= CutRole (such an item still can be "merged", but it's not in the application menu). QCocoaMenuItem::sync - item can be merged with itself: after item's role detected, the search for an item to merge with can find exactly the same item we've just detected the role for (since a data-member is modified) - try to avoid this. Task-number: QTBUG-39934 Change-Id: Ibe1df9e92973380652101143067e14922afdfb9e Reviewed-by: Shawn Rutledge --- src/plugins/platforms/cocoa/qcocoamenu.mm | 9 +++++++-- src/plugins/platforms/cocoa/qcocoamenuitem.mm | 11 +++++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/plugins/platforms/cocoa/qcocoamenu.mm b/src/plugins/platforms/cocoa/qcocoamenu.mm index 736e02a3ca..d849389907 100644 --- a/src/plugins/platforms/cocoa/qcocoamenu.mm +++ b/src/plugins/platforms/cocoa/qcocoamenu.mm @@ -366,9 +366,14 @@ void QCocoaMenu::syncMenuItem(QPlatformMenuItem *menuItem) } bool wasMerged = cocoaItem->isMerged(); - NSMenu *oldMenu = wasMerged ? [getMenuLoader() applicationMenu] : m_nativeMenu; - NSMenuItem *oldItem = [oldMenu itemWithTag:(NSInteger) cocoaItem]; + NSMenu *oldMenu = m_nativeMenu; + if (wasMerged) { + QPlatformMenuItem::MenuRole role = cocoaItem->effectiveRole(); + if (role >= QPlatformMenuItem::ApplicationSpecificRole && role < QPlatformMenuItem::CutRole) + oldMenu = [getMenuLoader() applicationMenu]; + } + NSMenuItem *oldItem = [oldMenu itemWithTag:(NSInteger) cocoaItem]; if (cocoaItem->sync() != oldItem) { // native item was changed for some reason if (oldItem) { diff --git a/src/plugins/platforms/cocoa/qcocoamenuitem.mm b/src/plugins/platforms/cocoa/qcocoamenuitem.mm index 3d3b6bf598..791b0805d0 100644 --- a/src/plugins/platforms/cocoa/qcocoamenuitem.mm +++ b/src/plugins/platforms/cocoa/qcocoamenuitem.mm @@ -256,8 +256,8 @@ NSMenuItem *QCocoaMenuItem::sync() if (depth == 3 || !menubar) break; // Menu item too deep in the hierarchy, or not connected to any menubar - m_detectedRole = detectMenuRole(m_text); - switch (m_detectedRole) { + MenuRole newDetectedRole = detectMenuRole(m_text); + switch (newDetectedRole) { case QPlatformMenuItem::AboutRole: if (m_text.indexOf(QRegExp(QString::fromLatin1("qt$"), Qt::CaseInsensitive)) == -1) mergeItem = [loader aboutMenuItem]; @@ -271,12 +271,15 @@ NSMenuItem *QCocoaMenuItem::sync() mergeItem = [loader quitMenuItem]; break; default: - if (m_detectedRole >= CutRole && m_detectedRole < RoleCount && menubar) - mergeItem = menubar->itemForRole(m_detectedRole); + if (newDetectedRole >= CutRole && newDetectedRole < RoleCount && menubar) + mergeItem = menubar->itemForRole(newDetectedRole); if (!m_text.isEmpty()) m_textSynced = true; break; } + + m_detectedRole = newDetectedRole; + break; } -- cgit v1.2.3