Re: How do I implement contextual-menu to NSTableView/NSOutlineView
Re: How do I implement contextual-menu to NSTableView/NSOutlineView
- Subject: Re: How do I implement contextual-menu to NSTableView/NSOutlineView
- From: Ondra Cada <email@hidden>
- Date: Tue, 29 Jan 2002 19:44:53 +0100
Gore,
>
>>>>> Gore (G) wrote at Tue, 29 Jan 2002 17:36:31 +0200:
G> I would like to have a NSMenu to be displayed as a contextual-menu when
G> right-clicking on an item in the table view/outline view. Is this
G> possible ?
Yep, and quite easily -- just like more or less anything in Cocoa ;).
You have to re-implement menuForEvent: of the TableView. My own solution
(which uses a delegate to provide the actual menu for an appropriate cell)
looks like this -- use it freely should you want to:
@implementation NSTableView (DateSelection)
-(NSMenu*)menuForEvent:(NSEvent*)evt {
NSPoint pt=[self convertPoint:[evt locationInWindow] fromView:nil];
int column=[self columnAtPoint:pt],row=[self rowAtPoint:pt];
if (column>=0 && row>=0 && [[self delegate]
respondsToSelector:@selector(menuForTableColumn:row:)])
return [[self delegate] menuForTableColumn:[[self tableColumns]
objectAtIndex:column] row:row];
return nil;
}
@end
---
Ondra Cada
OCSoftware: email@hidden
http://www.ocs.cz
2K Development: email@hidden
http://www.2kdevelopment.cz
private email@hidden
http://www.ocs.cz/oc