Menu item validation problem
Menu item validation problem
- Subject: Menu item validation problem
- From: David Remahl <email@hidden>
- Date: Wed, 16 Jul 2003 08:32:52 +0200
Hi.
I have a problem with autoenabling of a menuitems in a programmatically
created menu hierarchy. The menu is created in code, as opposed to in
Interface Builder. It contains a number of items with submenus, and
each submenu contains a number of items. Each of these items have a nil
target and an action. The top level menu has been sent
setAutoenablesItems:YES, and so have each of the sub menus. The top
level menu is set as the sub menu of a top level menu item (an item
attached to the horizontal menu bar). The top level menu is a subclass
of NSMenu, but overrides none of the methods in NSMenu.
The application is document based, and has one window per document. The
NSDocument is set to be the window's delegate. In the NSDocument
subclass, I implement the method that is the action of each leaf menu
item. The NSDocument subclass does get validation messages for other
items with action = nil (first responder), but _not_ for the any of the
items in the programmatically created menu.
All the leaf items in the programmatically created menu stay disabled.
Even if I implement their action in the app delegate, they stay
disabled.
What could I possibly have missed!?
Some example code (non-authentic, actually written in Mail...):
@implementation DRMyMenu
- (id)initWithTitle:(NSString *)string
{
if( self = [super initWithTitle:string] )
{
int i, j;
for( i = 0; i < 5; i++ )
{
NSMenu *subMenu = [[[NSMenu alloc] initWithTitle:[NSString
stringWithFormat:@"%i",i]] autorelease];
NSMenuItem *subMenuOwner;
for( j = 0; j < 5; j++ )
{
NSMenuItem *menuItem = [[NSMenuItem alloc] initWithTitle:[NSString
stringWithFormat:@"%i", j]
action:@selector(myAction:) keyEquivalent:@""];
[subMenu addItem:menuItem];
[menuItem release];
}
subMenuOwner = [[NSMenuItem alloc] initWithTitle:[NSString
stringWithFormat:@"%i", i]
action:NULL keyEquivalent:@""];
[subMenuOwner setSubmenu:subMenu];
[self addItem:subMenuOwner];
[subMenuOwner release];
}
}
return self;
}
@end
@implementation AppController
- (IBAction)myAction:(id)sender
{
}
- (void)awakeFromNib
{
[topMenuItem setSubmenu:[[[DRMyMenu alloc] initWithTitle:@"TopMenu]
autorelease]];
}
@end
/ Thanks, David Remahl
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.