Cocoa: application menu items sometimes get duplicated
Under some circumstances, the same menu item appears several times in the application menu in the menu bar. This can be seen in Qt creator, where "About Qt Creator" appears twize. The reason is that QCocoaMenu::syncMenuItem does not take into account that merged items cannot be found in the QCocoaMenu that owns the menuItem, but rather inside the application menu. And because of this, it fails cleaning up the old item when it changes from e.g TextHeuristicRole to ApplicationRole. This patch will fix this. Change-Id: Ia84f552d1788d80d778c7dded3393412b9d2d8cb Reviewed-by: Chris Meyer <cmeyer1969@gmail.com> Reviewed-by: Morten Johan Sørvig <morten.sorvig@digia.com>
This commit is contained in:
parent
9cdcd2f639
commit
85ff27d9ec
@ -45,6 +45,13 @@
|
|||||||
#include "qcocoaautoreleasepool.h"
|
#include "qcocoaautoreleasepool.h"
|
||||||
|
|
||||||
#include <QtCore/QtDebug>
|
#include <QtCore/QtDebug>
|
||||||
|
#include "qcocoaapplication.h"
|
||||||
|
#include "qcocoamenuloader.h"
|
||||||
|
|
||||||
|
static inline QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *getMenuLoader()
|
||||||
|
{
|
||||||
|
return [NSApp QT_MANGLE_NAMESPACE(qt_qcocoamenuLoader)];
|
||||||
|
}
|
||||||
|
|
||||||
@interface QT_MANGLE_NAMESPACE(QCocoaMenuDelegate) : NSObject <NSMenuDelegate> {
|
@interface QT_MANGLE_NAMESPACE(QCocoaMenuDelegate) : NSObject <NSMenuDelegate> {
|
||||||
QCocoaMenu *m_menu;
|
QCocoaMenu *m_menu;
|
||||||
@ -215,12 +222,19 @@ void QCocoaMenu::syncMenuItem(QPlatformMenuItem *menuItem)
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool wasMerged = cocoaItem->isMerged();
|
bool wasMerged = cocoaItem->isMerged();
|
||||||
NSMenuItem *oldItem = [m_nativeMenu itemWithTag:(NSInteger) cocoaItem];
|
NSMenu *oldMenu = wasMerged ? [getMenuLoader() applicationMenu] : m_nativeMenu;
|
||||||
|
NSMenuItem *oldItem = [oldMenu itemWithTag:(NSInteger) cocoaItem];
|
||||||
|
|
||||||
if (cocoaItem->sync() != oldItem) {
|
if (cocoaItem->sync() != oldItem) {
|
||||||
// native item was changed for some reason
|
// native item was changed for some reason
|
||||||
if (!wasMerged && oldItem)
|
if (oldItem) {
|
||||||
[m_nativeMenu removeItem:oldItem];
|
if (wasMerged) {
|
||||||
|
[oldItem setEnabled:NO];
|
||||||
|
[oldItem setHidden:YES];
|
||||||
|
} else {
|
||||||
|
[m_nativeMenu removeItem:oldItem];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QCocoaMenuItem* beforeItem = itemOrNull(m_menuItems.indexOf(cocoaItem) + 1);
|
QCocoaMenuItem* beforeItem = itemOrNull(m_menuItems.indexOf(cocoaItem) + 1);
|
||||||
insertNative(cocoaItem, beforeItem);
|
insertNative(cocoaItem, beforeItem);
|
||||||
|
Loading…
Reference in New Issue
Block a user