From b5f18da11fb526a444d2550715d8b867b711e67a Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Thu, 30 Jun 2016 15:21:00 -0700 Subject: [PATCH] QCocoaMenuLoader: Remove NIB file Since 10.6, the first menu is always identified as the application menu. See remark about Nibless apps and the application menu in, https://developer.apple.com/library/prerelease/content/releasenotes/AppKit/RN-AppKitOlderNotes/index.html Therefore, we can get rid of the NIB file together with the loading logic we had in place (and which, incidentaly, was using deprecated API). Change-Id: I99bf0e9d8ea749a9be9295fa12602335abc6548e Reviewed-by: Jake Petroules --- .../platforms/cocoa/qcocoaintegration.mm | 1 - .../platforms/cocoa/qcocoamenuloader.h | 7 +- .../platforms/cocoa/qcocoamenuloader.mm | 191 ++++++++++-------- .../platforms/cocoa/qcocoaresources.qrc | 5 - .../platforms/cocoa/qt_menu.nib/classes.nib | 59 ------ .../platforms/cocoa/qt_menu.nib/info.nib | 18 -- .../cocoa/qt_menu.nib/keyedobjects.nib | Bin 5560 -> 0 bytes 7 files changed, 106 insertions(+), 175 deletions(-) delete mode 100644 src/plugins/platforms/cocoa/qt_menu.nib/classes.nib delete mode 100644 src/plugins/platforms/cocoa/qt_menu.nib/info.nib delete mode 100644 src/plugins/platforms/cocoa/qt_menu.nib/keyedobjects.nib diff --git a/src/plugins/platforms/cocoa/qcocoaintegration.mm b/src/plugins/platforms/cocoa/qcocoaintegration.mm index f6a3b3943f..b0b91c6633 100644 --- a/src/plugins/platforms/cocoa/qcocoaintegration.mm +++ b/src/plugins/platforms/cocoa/qcocoaintegration.mm @@ -332,7 +332,6 @@ QCocoaIntegration::QCocoaIntegration(const QStringList ¶mList) // Load the application menu. This menu contains Preferences, Hide, Quit. QCocoaMenuLoader *qtMenuLoader = [[QCocoaMenuLoader alloc] init]; - qt_mac_loadMenuNib(qtMenuLoader); [cocoaApplication setMenu:[qtMenuLoader menu]]; [newDelegate setMenuLoader:qtMenuLoader]; } diff --git a/src/plugins/platforms/cocoa/qcocoamenuloader.h b/src/plugins/platforms/cocoa/qcocoamenuloader.h index 6f58b2f24c..d1f47b18f0 100644 --- a/src/plugins/platforms/cocoa/qcocoamenuloader.h +++ b/src/plugins/platforms/cocoa/qcocoamenuloader.h @@ -68,6 +68,7 @@ NSMenuItem *hideAllOthersItem; NSMenuItem *showAllItem; } +- (instancetype)init; - (void)ensureAppMenuInMenu:(NSMenu *)menu; - (void)removeActionsFromAppMenu; - (NSMenu *)applicationMenu; @@ -92,10 +93,4 @@ QT_NAMESPACE_ALIAS_OBJC_CLASS(QCocoaMenuLoader); -QT_BEGIN_NAMESPACE - -void qt_mac_loadMenuNib(QCocoaMenuLoader *qtMenuLoader); - -QT_END_NAMESPACE - #endif // QCOCOAMENULOADER_P_H diff --git a/src/plugins/platforms/cocoa/qcocoamenuloader.mm b/src/plugins/platforms/cocoa/qcocoamenuloader.mm index e440a9080c..9b16999d48 100644 --- a/src/plugins/platforms/cocoa/qcocoamenuloader.mm +++ b/src/plugins/platforms/cocoa/qcocoamenuloader.mm @@ -55,86 +55,117 @@ QT_FORWARD_DECLARE_CLASS(QCFString) QT_FORWARD_DECLARE_CLASS(QString) - -QT_BEGIN_NAMESPACE - -/* - Loads and instantiates the main app menu from the menu nib file(s). - - The main app menu contains the Quit, Hide About, Preferences entries, and - The reason for having the nib file is that those can not be created - programmatically. To ease deployment the nib files are stored in Qt resources - and written to QDir::temp() before loading. (Earlier Qt versions used - to require having the nib file in the Qt GUI framework.) -*/ -void qt_mac_loadMenuNib(QCocoaMenuLoader *qtMenuLoader) -{ - // Create qt_menu.nib dir in temp. - QDir temp = QDir::temp(); - temp.mkdir("qt_menu.nib"); - QString nibDir = temp.canonicalPath() + QLatin1String("/") + QLatin1String("qt_menu.nib/"); - if (!QDir(nibDir).exists()) { - qWarning("qt_mac_loadMenuNib: could not create nib directory in temp"); - return; - } - - // Copy nib files from resources to temp. - QDir nibResource(":/qt-project.org/mac/qt_menu.nib/"); - if (!nibResource.exists()) { - qWarning("qt_mac_loadMenuNib: could not load nib from resources"); - return; - } - foreach (const QFileInfo &file, nibResource.entryInfoList()) { - QFileInfo destinationFile(nibDir + QLatin1String("/") + file.fileName()); - if (destinationFile.exists() && destinationFile.size() != file.size()) - QFile::remove(destinationFile.absoluteFilePath()); - - QFile::copy(file.absoluteFilePath(), destinationFile.absoluteFilePath()); - } - - // Load and instantiate nib file from temp - NSURL *nibUrl = [NSURL fileURLWithPath : QCFString::toNSString(nibDir)]; - NSNib *nib = [[NSNib alloc] initWithContentsOfURL : nibUrl]; - [nib autorelease]; - if(!nib) { - qWarning("qt_mac_loadMenuNib: could not load nib from temp"); - return; - } - bool ok = [nib instantiateNibWithOwner : qtMenuLoader topLevelObjects : nil]; - if (!ok) { - qWarning("qt_mac_loadMenuNib: could not instantiate nib"); - } -} - -QT_END_NAMESPACE - @implementation QCocoaMenuLoader -- (void)awakeFromNib +- (instancetype)init { - servicesItem = [[appMenu itemWithTitle:@"Services"] retain]; - hideAllOthersItem = [[appMenu itemWithTitle:@"Hide Others"] retain]; - showAllItem = [[appMenu itemWithTitle:@"Show All"] retain]; + if ((self = [super init])) { + NSString *appName = qt_mac_applicationName().toNSString(); - // Get the names in the nib to match the app name set by Qt. - const NSString *appName = qt_mac_applicationName().toNSString(); - [quitItem setTitle:[[quitItem title] stringByReplacingOccurrencesOfString:@"NewApplication" - withString:const_cast(appName)]]; - [hideItem setTitle:[[hideItem title] stringByReplacingOccurrencesOfString:@"NewApplication" - withString:const_cast(appName)]]; - [aboutItem setTitle:[[aboutItem title] stringByReplacingOccurrencesOfString:@"NewApplication" - withString:const_cast(appName)]]; - // Disable the items that don't do anything. If someone associates a QAction with them - // They should get synced back in. - [preferencesItem setEnabled:NO]; - [preferencesItem setHidden:YES]; + // Menubar as menu. Title as set in the NIB file + theMenu = [[NSMenu alloc] initWithTitle:@"Main Menu"]; - // should set this in the NIB - [preferencesItem setTarget: self]; - [preferencesItem setAction: @selector(qtDispatcherToQPAMenuItem:)]; + // Application menu. Since 10.6, the first menu + // is always identified as the application menu. + NSMenuItem *appItem = [[[NSMenuItem alloc] init] autorelease]; + appItem.title = appName; + [theMenu addItem:appItem]; + appMenu = [[NSMenu alloc] initWithTitle:appName]; + appItem.submenu = appMenu; - [aboutItem setEnabled:NO]; - [aboutItem setHidden:YES]; + // About Application + aboutItem = [[NSMenuItem alloc] initWithTitle:[@"About " stringByAppendingString:appName] + action:@selector(orderFrontStandardAboutPanel:) + keyEquivalent:@""]; + aboutItem.target = self; + // Disable until a QAction is associated + aboutItem.enabled = NO; + aboutItem.hidden = YES; + [appMenu addItem:aboutItem]; + + // About Qt (shameless self-promotion) + aboutQtItem = [[NSMenuItem alloc] init]; + aboutQtItem.title = @"About Qt"; + // Disable until a QAction is associated + aboutQtItem.enabled = NO; + aboutQtItem.hidden = YES; + [appMenu addItem:aboutQtItem]; + + [appMenu addItem:[NSMenuItem separatorItem]]; + + // Preferences + preferencesItem = [[NSMenuItem alloc] initWithTitle:@"Preferences…" + action:@selector(qtDispatcherToQPAMenuItem:) + keyEquivalent:@","]; + preferencesItem.target = self; + // Disable until a QAction is associated + preferencesItem.enabled = NO; + preferencesItem.hidden = YES; + [appMenu addItem:preferencesItem]; + + [appMenu addItem:[NSMenuItem separatorItem]]; + + // Services item and menu + servicesItem = [[NSMenuItem alloc] init]; + servicesItem.title = @"Services"; + NSApplication *app = [NSApplication sharedApplication]; + app.servicesMenu = [[[NSMenu alloc] initWithTitle:@"Services"] autorelease]; + servicesItem.submenu = app.servicesMenu; + [appMenu addItem:servicesItem]; + + [appMenu addItem:[NSMenuItem separatorItem]]; + + // Hide Application + hideItem = [[NSMenuItem alloc] initWithTitle:[@"Hide " stringByAppendingString:appName] + action:@selector(hide:) + keyEquivalent:@"h"]; + hideItem.target = self; + [appMenu addItem:hideItem]; + + // Hide Others + hideAllOthersItem = [[NSMenuItem alloc] initWithTitle:@"Hide Others" + action:@selector(hideOtherApplications:) + keyEquivalent:@"h"]; + hideAllOthersItem.target = self; + hideAllOthersItem.keyEquivalentModifierMask = NSCommandKeyMask | NSAlternateKeyMask; + [appMenu addItem:hideAllOthersItem]; + + // Show All + showAllItem = [[NSMenuItem alloc] initWithTitle:@"Show All" + action:@selector(unhideAllApplications:) + keyEquivalent:@""]; + showAllItem.target = self; + [appMenu addItem:showAllItem]; + + [appMenu addItem:[NSMenuItem separatorItem]]; + + // Quit Application + quitItem = [[NSMenuItem alloc] initWithTitle:[@"Quit " stringByAppendingString:appName] + action:@selector(terminate:) + keyEquivalent:@"q"]; + quitItem.target = self; + [appMenu addItem:quitItem]; + } + + return self; +} + +- (void)dealloc +{ + [theMenu release]; + [appMenu release]; + [aboutItem release]; + [aboutQtItem release]; + [preferencesItem release]; + [servicesItem release]; + [hideItem release]; + [hideAllOthersItem release]; + [showAllItem release]; + [quitItem release]; + + [lastAppSpecificItem release]; + + [super dealloc]; } - (void)ensureAppMenuInMenu:(NSMenu *)menu @@ -179,18 +210,6 @@ QT_END_NAMESPACE [item setTag:0]; } -- (void)dealloc -{ - [servicesItem release]; - [hideAllOthersItem release]; - [showAllItem release]; - - [lastAppSpecificItem release]; - [theMenu release]; - [appMenu release]; - [super dealloc]; -} - - (NSMenu *)menu { return [[theMenu retain] autorelease]; diff --git a/src/plugins/platforms/cocoa/qcocoaresources.qrc b/src/plugins/platforms/cocoa/qcocoaresources.qrc index 9e0640db7d..4255bfba9d 100644 --- a/src/plugins/platforms/cocoa/qcocoaresources.qrc +++ b/src/plugins/platforms/cocoa/qcocoaresources.qrc @@ -9,9 +9,4 @@ images/leopard-unified-toolbar-on.png - -qt_menu.nib/classes.nib -qt_menu.nib/info.nib -qt_menu.nib/keyedobjects.nib - diff --git a/src/plugins/platforms/cocoa/qt_menu.nib/classes.nib b/src/plugins/platforms/cocoa/qt_menu.nib/classes.nib deleted file mode 100644 index 78941153c2..0000000000 --- a/src/plugins/platforms/cocoa/qt_menu.nib/classes.nib +++ /dev/null @@ -1,59 +0,0 @@ - - - - - IBClasses - - - ACTIONS - - hide - id - hideOtherApplications - id - orderFrontStandardAboutPanel - id - qtDispatcherToQPAMenuItem - id - terminate - id - unhideAllApplications - id - - CLASS - QCocoaMenuLoader - LANGUAGE - ObjC - OUTLETS - - aboutItem - NSMenuItem - aboutQtItem - NSMenuItem - appMenu - NSMenu - hideItem - NSMenuItem - preferencesItem - NSMenuItem - quitItem - NSMenuItem - theMenu - NSMenu - - SUPERCLASS - NSResponder - - - CLASS - FirstResponder - LANGUAGE - ObjC - SUPERCLASS - NSObject - - - IBVersion - 1 - - diff --git a/src/plugins/platforms/cocoa/qt_menu.nib/info.nib b/src/plugins/platforms/cocoa/qt_menu.nib/info.nib deleted file mode 100644 index 02e5cca562..0000000000 --- a/src/plugins/platforms/cocoa/qt_menu.nib/info.nib +++ /dev/null @@ -1,18 +0,0 @@ - - - - - IBFramework Version - 672 - IBOldestOS - 5 - IBOpenObjects - - 57 - - IBSystem Version - 9L31a - targetFramework - IBCocoaFramework - - diff --git a/src/plugins/platforms/cocoa/qt_menu.nib/keyedobjects.nib b/src/plugins/platforms/cocoa/qt_menu.nib/keyedobjects.nib deleted file mode 100644 index 67207ca62836fa2c75630f5a7004fb5dc4757c3d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5560 zcmai22Y3|K7Cz_B?#xch+(eKL0Rkk_dx;^05(tolus}i$n`9tMlHIVoA)p9XkfMl) zh`j-#A}AoDqNs?yJsTim!}9FqSrL)PJ2RVvi2A+oeN4IMp7NjnoO5SOsw;!hSg&4( z0D*x79`J$;3TQ{9!~z0$@(rMa0llF=41fzE1F~QgOoACu2{o_)YGE;40!!dh zSOF{Ha<~Gnf(>vjY=L`WJM4hH@DMx&FTr6r0&l~6@F9ExpTSq~HGB)d!fE&~oIwSB zXd%ZIn2hbQ19rp|Ov4MXJNCi8I0y&hP|U=UI10z&IGli!aSBd@BUp-MXk!rPVHm5i z1{dHJxE8O%tMN|UhyTLY@O69x-^91@5FW-O_% z1f8J^q(T~809~OQbcY_$6MD_e^XCPs?C6w0WsMzm)0H33U;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