Novice Question: Getting Menu selections
Novice Question: Getting Menu selections
- Subject: Novice Question: Getting Menu selections
- From: Christopher Kempke <email@hidden>
- Date: Thu, 13 Sep 2007 22:20:11 -0700
I'm a Cocoa novice, converting my aging Carbon application framework
to Cocoa. I'm building my interfaces directly, not using IB (the
framework has it's own builder tools), and using Objective C++.
In Carbon, my menu items had a command code associated with them,
which I'd snag when the Carbon Event fired and send off for
handling. I'm trying to duplicate that functionality here.
So, I've created a Menu Controller object:
#if (UT_TARGET_COCOA)
@interface MenuController : NSObject
-(id)init;
-(void)menuItemSelected:(id)sender;
@end
#endif
And it's implementation:
@implementation MenuController
-(id)init
{
return [super init];
}
-(void)menuItemSelected:(id)sender
{
CroPL::CPFGetApplication()->HandleCommand([sender tag]);
}
@end
I create a static instance of it:
static MenuController* sMenuController = [[MenuController alloc] init];
And when I create the menus, I set the tag to the "command code" from
my old architecture, the target to the static menu controller, and
the action to the MenuItemSelected: message:
void InsertItemIntoMenu(platformMenu menu, const UtString& text,
sInt16 before)
{
CFStringRef inText = text.ToCFStringRef();
NSMenuItem* theItem = [menu insertItemWithTitle: (NSString*)inText
action: nil keyEquivalent: @"" atIndex: before];
[theItem setTarget:sMenuController];
[theItem setAction:@selector(testItemSelected:)];
CFRelease(inText);
}
PlatformMenu here is NSMenu*, and UTString is private string class
that knows how to convert to CFStringRef (bridged to NSString*).
This doesn't work. A breakpoint on the menuItemSelected: method
never fires, and the debugger console tells me only:
2007-09-13 22:05:19.269 UnitTest[1908] *** +[NSWindow
orderedWindows]: selector not recognized
I've verified that neither the static MenuController nor the created
item are nil as of when I insert.
I've been poking at this for days without luck. I'm probably
completely missing some important step. Can anyone take pity on me?
--Chris
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden