I am new to this technology , I want to display different Context Menu on Right click
of Parent Node and Child Node..
Asked
Active
Viewed 2,322 times
1

Himanshu
- 31,810
- 31
- 111
- 133

Bhavesh Modi
- 303
- 6
- 18
2 Answers
2
Subclass NSOutlineView
and implement - (NSMenu *)menuForEvent:(NSEvent *)theEvent
.
-(NSMenu*)menuForEvent:(NSEvent*)evt
{
NSLog(@"menuForEvent %@ %@",self, [self delegate]);
NSPoint pt = [self convertPoint:[evt locationInWindow] fromView:nil];
int row=[self rowAtPoint:pt];
// create menu ...
return menu;
}
On Mac OS 10.5 and above, create NSMenu in nib and set delegate and implement:
-(void)menuNeedsUpdate:(NSMenu *)menu

pkamb
- 33,281
- 23
- 160
- 191

Parag Bafna
- 22,812
- 8
- 71
- 144
1
Swift Version:
class SubclassOutlineView: NSOutlineView {
override func menu(for event: NSEvent) -> NSMenu? {
let point = convert(event.locationInWindow, from: nil)
let row = self.row(at: point)
let item = self.item(atRow: row)
let menu = NSMenu()
// ...
return menu
}
}
The bit I was missing was item(atRow:
, which gives you the needed data source item. Found that at this related question:
How do you add context senstive menu to NSOutlineView (ie right click menu)

pkamb
- 33,281
- 23
- 160
- 191