• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Programming Context Menu
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Programming Context Menu


  • Subject: Re: Programming Context Menu
  • From: Bing Li <email@hidden>
  • Date: Tue, 05 Apr 2011 11:37:47 +0800

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 AM, Volker in Lists <email@hidden>wrote:

> Hi,
>
> have you connected the menu items in interface builder with their commands?
> Then they will get active, if the responder is also available.
>
> volker
> Am 04.04.2011 um 21:38 schrieb 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 the sample provided by the book,
> > the items are enabled. I think I follow the book restrictedly. I could
> NOT
> > get the solution. The major code is as follows, which is completely from
> the
> > book. Could you please give me a hint?
> >
> > Thanks so much!
> > LB
> >
> > import "ContextMenuView.h"
> >
> > static NSMenu *defaultMenu;
> >
> > @implementation ContextMenuView
> > + (NSMenu*)defaultMenu
> > {
> >        if (nil == defaultMenu)
> >        {
> >                @synchronized(self)
> >                {
> >                        if (nil == defaultMenu)
> >                        {
> >                                defaultMenu = [NSMenu new];
> >                                [defaultMenu addItemWithTitle: @"Copy"
> >
> > action: @selector(copy:)
> >
> > keyEquivalent: @"c"];
> >                                [defaultMenu addItemWithTitle: @"Paste"
> >
> > action: @selector(paste:)
> >
> > keyEquivalent: @"v"];
> >                        }
> >                }
> >        }
> >        return defaultMenu;
> > }
> > static BOOL addItemsToMenuFromMenu(NSMenu *menu, NSMenu *template)
> > {
> >        for (NSMenuItem *item in [template itemArray])
> >        {
> >                NSMenuItem *itemCopy = [item copy];
> >                [menu addItem: itemCopy];
> >                [itemCopy release];
> >        }
> >        return [menu numberOfItems] > 0;
> > }
> > - (NSMenu*)menuForEvent: (NSEvent*)theEvent
> > {
> >        NSPoint click = [self convertPoint: [theEvent locationInWindow]
> >                                                          fromView: nil];
> >
> >        NSMenuItem *locationMenuItem =
> >        [[NSMenuItem alloc] initWithTitle: NSStringFromPoint(click)
> >                                                           action: NULL
> >                                                keyEquivalent: @""];
> >        [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];
> > }
> > @end
> > _______________________________________________
> >
> > 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
>
>
_______________________________________________

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

  • Follow-Ups:
    • Re: Programming Context Menu
      • From: Graham Cox <email@hidden>
References: 
 >Programming Context Menu (From: Bing Li <email@hidden>)

  • Prev by Date: Re: NSString, stringByAppendingPathComponent, and Canonicalization
  • Next by Date: Re: Adding a 'usro' resource
  • Previous by thread: Programming Context Menu
  • Next by thread: Re: Programming Context Menu
  • Index(es):
    • Date
    • Thread