Re: Programming Context Menu

2011-04-04 Thread Graham Cox
On 05/04/2011, at 1:37 PM, Bing Li wrote: > I noticed that no IBAction/IBOutlet is available for the items in the code. > Should I make some connections for them? Yes, but the outlets aren't visible to code because 'IBOutlet' is an IB thing. You need to call -setTarget: on the menu items with t

Re: Programming Context Menu

2011-04-04 Thread Eli Bach
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 = >[[NS

Re: Programming Context Menu

2011-04-04 Thread Stephen J. Butler
On Tue, Apr 5, 2011 at 12:10 AM, Chris Hanson wrote: > On Apr 4, 2011, at 12:38 PM, Bing Li wrote: > >>        if (nil == defaultMenu) >>        { >>                @synchronized(self) >>                { >>                        if (nil == defaultMenu) > > Don't do this. I don't mean just in Co

Re: Programming Context Menu

2011-04-04 Thread Chris Hanson
On Apr 4, 2011, at 12:38 PM, Bing Li wrote: >if (nil == defaultMenu) >{ >@synchronized(self) >{ >if (nil == defaultMenu) Don't do this. I don't mean just in Cocoa either, I mean don't do it ever. It's an anti-pattern called

Re: Programming Context Menu

2011-04-04 Thread Bing Li
Dear Volker, I noticed that no IBAction/IBOutlet is available for the items in the code. Should I make some connections for them? I just connect the context menu with the class of ContextMenuView and connect the NSView in the Window with ContextMenuView. Thanks, LB On Tue, Apr 5, 2011 at 4:06

Programming Context Menu

2011-04-04 Thread Bing Li
Dear all, I am now learning programming on Cocoa following the book, Cocoa Programming Developers Handbook. When programming Context Menus (Page 237), I got a problem. Although the context menu can be shown, it is weird that all of the items in the context menu are disabled. However, when running