• 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
Understanding how to display a context menu
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Understanding how to display a context menu


  • Subject: Understanding how to display a context menu
  • From: Jacob Rhoden <email@hidden>
  • Date: Tue, 10 Mar 2009 22:40:59 +1100

Hey guys,

I'm trying to understand the Apple docs for adding a context menu to
an NSOutlineView:

http://developer.apple.com/documentation/Cocoa/Conceptual/MenuList/Articles/DisplayContextMenu.html#//apple_ref/doc/uid/TP40004968

I am a bit stuck at how do you make it truly context sensitive, ie I'm trying to
make a menu that has "Add new person" and "Remove <name>", where
<name> is the content of the row selected?


I am guessing I need to talk back to the controller object which has the data?
Perhaps somehow calling back to the "data source" object to ask it to build
the menu (but I am not sure how to do that or if I should do that).


This allows me to at least show the row number in the menu:

@implementation NSContextOutlineView
- (NSMenu *)defaultMenu {
if([self selectedRow] < 0) return nil;
NSMenu *theMenu = [[[NSMenu alloc] initWithTitle:@"Website context menu"] autorelease];
[theMenu insertItemWithTitle:@"Add new person" action:@selector(addSite:) keyEquivalent:@"" atIndex:0];
NSString* deleteItem = [NSString stringWithFormat: @"Remove '%i'", [self selectedRow]];
[theMenu insertItemWithTitle: deleteItem action:@selector(removeSite:) keyEquivalent:@"" atIndex:1];
return theMenu;
}
- (NSMenu *)menuForEvent:(NSEvent *)theEvent {
return [self defaultMenu]; }
@end


Any help much appreciated!

Thanks,
Jacob

_______________________________________________

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


  • Prev by Date: Re: Problem in save and open on Core Data Document Based application
  • Next by Date: Re: [ANN] InspectorKit (framework/IB-plugin)
  • Previous by thread: Fwd: Problem in save and open on Core Data Document Based application
  • Next by thread: launching IPhone App Via terminal in IPhone Simulator
  • Index(es):
    • Date
    • Thread