Re: Programming Context Menu
Re: Programming Context Menu
- Subject: Re: Programming Context Menu
- From: Eli Bach <email@hidden>
- Date: Tue, 05 Apr 2011 00:10:45 -0600
On Apr 4, 2011, at 1:38 PM, Bing Li wrote:
> - (NSMenu*)menuForEvent: (NSEvent*)theEvent
> {
> NSPoint click = [self convertPoint: [theEvent locationInWindow]
> fromView: nil];
>
> NSMenuItem *locationMenuItem =
> [[NSMenuItem alloc] initWithTitle: NSStringFromPoint(click)
> action: NULL
> keyEquivalent: @""];
It COULD be this line (as setEnabled:NO ) should disable the menu item. You could try changing it to YES.
> [locationMenuItem setEnabled: NO];
> NSMenu *menu = [NSMenu new];
> [menu addItem: locationMenuItem];
> [locationMenuItem release];
> [menu addItem: [NSMenuItem separatorItem]];
> if (addItemsToMenuFromMenu(menu, [self menu]))
> {
> [menu addItem: [NSMenuItem separatorItem]];
> }
> addItemsToMenuFromMenu(menu, [[self class] defaultMenu]);
> return [menu autorelease];
> }
It COULD also be that the menu items are supposed to be auto-enabled by the responder chain [which according to <http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/MenuList/Articles/EnablingMenuItems.html> is different for contextual menus than it is for the menu bar.
I don't know if your example code uses it, but it probably does since by default NSMenu setAutoenablesItems defaults to YES.
Eli
_______________________________________________
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