Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jun 9, 2009, 09:20 AM   #1
webdrive
macrumors newbie
 
Join Date: Mar 2009
Location: Annapolis
How to change menu items and window name based on target_name

Hi,
I have a Cocoa project that has two targets, WebDrive and GroupDrive. The functionality is the same, but the product name changes based on how it's built.

I have one MainMenu.xib file that has all my resources in it; menu, main window, etc, they all say WebDrive.

I would like that to change based on which target is built, or I would like to change it dynamically at runtime.

In the main awakeFromNib I tried

#ifdef _OEM_GROUPDRIVE_
[[NSApp mainWindow] setTitle:@"GroupDrive"];
#else
[[NSApp mainWindow] setTitle:@"WebDrive"];
#endif

but that did not update the main window Title.

Is there some way in IB to use ${TARGET_NAME} or ${PRODUCT_NAME} in the menus or window titles to have them set automatically?

thanks!
webdrive is offline   0 Reply With Quote
Old Jun 9, 2009, 09:27 AM   #2
kainjow
Moderator emeritus
 
kainjow's Avatar
 
Join Date: Jun 2000
You could use [[NSProcessInfo processInfo] processName] to get the name, or read it from the .app's info.plist file (through NSBundle). I would suggest not using [NSApp mainWindow], but instead do this in your window's controller and call [self window] instead.

For the menus, you could leave them as they are in the original nib, and then loop through each menu and its menu items, finding ones with a certain tag in their title and replacing that with your app name.
kainjow is offline   0 Reply With Quote
Old Jun 9, 2009, 02:12 PM   #3
Sayer
macrumors 6502a
 
Sayer's Avatar
 
Join Date: Jan 2002
Location: Austin, TX
Prolly the easiest and non-code way is to just make two sets of XIB files, with the different names in them. Put them in two different folders that you name logically so you can distinguish which set is which.

In your active target you can edit the "Copy Bundle Resources" phase and add the correct set of XIBs. Or in the file list in the editor window (that view that slides down above the text editor view) un/check the XIBs that only apply to the specific target.

This is the whole point of keeping UI elements and translatable text in discrete files; you can edit them to match the user's default language or to change the name based on use (if you make one app that is customized for different customers or project names).
__________________
Obama is a true statesman whose experience as a state senator, half-term US Senator & guest lecturer in a Constitutional Law class has fully prepared him to take control of our nuclear arsenal.-Me
Sayer is offline   0 Reply With Quote
Old Jun 9, 2009, 05:08 PM   #4
webdrive
Thread Starter
macrumors newbie
 
Join Date: Mar 2009
Location: Annapolis
I'm trying to enumerate the menu to replace the item titles and it seems that I just get the raw system menu. The following code fetches...

NSMenu* pMenu = [NSApp mainMenu];
NSLog(@"%@",pMenu);

2009-06-09 18:04:25.975 GroupDrive[216:813] <NSMenu: 0x151370>
Title: AMainMenu
Supermenu: 0x0 (None), autoenable: YES, change messages enabled: YES
Items: (
<MenuItem: 0x1513d0 , submenu: 0x1465e0 (Apple)>,
<MenuItem: 0x151450 File, submenu: 0x1487f0 (File)>,
<MenuItem: 0x1514d0 Edit, submenu: 0x14e3c0 (Edit)>,
<MenuItem: 0x151550 Format, submenu: 0x1515d0 (Format)>,
<MenuItem: 0x1517c0 View, submenu: 0x14f550 (View)>,
<MenuItem: 0x151840 Window, submenu: 0x150250 (Window)>,
<MenuItem: 0x1512f0 Help, submenu: 0x14d8e0 (Help)>
)

I should see the main WebDrive menu between (Apple) and (File).
webdrive is offline   0 Reply With Quote
Old Jun 9, 2009, 05:50 PM   #5
webdrive
Thread Starter
macrumors newbie
 
Join Date: Mar 2009
Location: Annapolis
Btw, I did manage to get the Title updating correctly. I derived my own class from NSWindow and then in the awakeFromNib I issued a call to setTitle using the CFBundleName from the main bundle.
webdrive is offline   0 Reply With Quote
Old Jun 9, 2009, 06:22 PM   #6
webdrive
Thread Starter
macrumors newbie
 
Join Date: Mar 2009
Location: Annapolis
Ok, I figured it out. Here's some code that will traverse a menu and substitute text:

-(void)fixupMenu:(NSMenu*)myMenu
{
if ( myMenu )
{
NSString* strOld = @"Old";
NSString* strNew = @"New";

int iCount = [myMenu numberOfItems];
for ( int i=0; i<iCount; i++ )
{
NSMenuItem* pItem = [myMenu itemAtIndex:i];
if ( pItem )
{
NSString* str = [pItem title];
[pItem setTitle:[str stringByReplacingOccurrencesOfString:strOld withString:strNew]];
[self fixupMenu:[pItem submenu]];//process submenu
}
}
}
}

Thanks for the help folks!

Michael
webdrive is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
How to change menu and tab bar color in Safari? iSayuSay Mac Applications and Mac App Store 2 Jul 15, 2011 10:21 AM
How to Change my Iphone 4 carrier name ):? XxpikachuxX Jailbreaks and iOS Hacks 5 Dec 10, 2010 10:23 PM
Where to change version number and company name in XCode? hzxu iPhone/iPad Programming 2 Jan 4, 2010 09:18 AM
How to change menu bar icon colors? technohobbit17 Mac Basics and Help 1 Mar 28, 2009 11:50 PM
How to change Final Cut Studio 2 names? SDAVE Mac Applications and Mac App Store 1 May 25, 2008 03:01 AM


All times are GMT -5. The time now is 11:52 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC