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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to