How do you add the ability to right click on a row in an NSOutlineView so you can say delete an object or some other activity. (ie Like when you right click on a folder in t
Here is a Swift 2.0 example which uses a subclass and extends the default NSOutlineDelegate so you can define your menus in the delegate.
protocol MenuOutlineViewDelegate : NSOutlineViewDelegate {
func outlineView(outlineView: NSOutlineView, menuForItem item: AnyObject) -> NSMenu?
}
class MenuOutlineView: NSOutlineView {
override func menuForEvent(event: NSEvent) -> NSMenu? {
let point = self.convertPoint(event.locationInWindow, fromView: nil)
let row = self.rowAtPoint(point)
let item = self.itemAtRow(row)
if (item == nil) {
return nil
}
return (self.delegate() as! MenuOutlineViewDelegate).outlineView(self, menuForItem: item!)
}
}