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 <shawn.rutledge@digia.com>
This commit is contained in:
parent
9bbf08fcf3
commit
8c538d10da
@ -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) {
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user