Adding a menu at validateMenuItem
Adding a menu at validateMenuItem
- Subject: Adding a menu at validateMenuItem
- From: John Scalo <email@hidden>
- Date: Wed, 13 Nov 2002 23:26:19 -0800
I have a situation where if the user is pressing the Option key when a menu
is clicked, a new menu item is added to that menu and stays there from then
on. At least this is what I'm trying to do. I have this almost working by
doing the work in validateMenuItem: like such-
@interface Controller : NSObject
{
...
IBOutlet NSMenu *menu;
NSMenuItem *newMenuItem;
...
}
...
- (IBAction)changeMenuSelection:(id)sender;
...
@implementation Controller
...
- (BOOL)validateMenuItem:(NSMenuItem*)menuItem
{
if (!newMenuItem && IsOptionKeyDown())
{
newMenuItem = [menu addItemWithTitle:@"New item"
action:@selector(changeMenuSelection:) keyEquivalent:@""];
[newMenuItem setEnabled:YES];//shouldn't be needed
}
return YES;//because these are always available
}
- (IBAction)changeMenuSelection:(id)sender
{
[curItem setState:NSOffState];
[sender setState:NSOnState];
curItem = sender;
}
...
---
When the menu is first clicked with the Option key down, the new menu item
shows up and looks good. The problem is that the item is disabled (grayed
out) on every subsequent click of the menu. And some debugging reveals that
validateMenuItem never gets called for this menu item. However all the
properties of the new menu item look good when examined from gdb.
Why doesn't validateMenuItem get called for this new item?
Thanks!
John
_______________________________________________
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.