The approach I used was overriding the "RightMouseDown" method [1, 2]. After attempting to do so in the NSOutlineView and the NSTableCellView with no luck, the trick was to do go down to the lower level in the hierarchy to the NSTextField. It turns out the NSWindow object uses SendEvent to dispatch events directly to the view that is closest to the mouse event [3], so the events proceed from innermost view to outermost view.
You can change the desired NSTextField in the OutlineView in Xcode to use this custom class:
public partial class CustomTextField : NSTextField
{
#region Constructors
// Called when created from unmanaged code
public CustomTextField (IntPtr handle) : base (handle)
{
Initialize ();
}
// Called when created directly from a XIB file
[Export ("initWithCoder:")]
public CustomTextField (NSCoder coder) : base (coder)
{
Initialize ();
}
// Shared initialization code
void Initialize ()
{
}
#endregion
public override void RightMouseDown (NSEvent theEvent)
{
NextResponder.RightMouseDown (theEvent);
}
}
Because "RightMouseDown" does not call base.RightMouseDown()
, the click is completely ignored by the NSTextField logic. Calling NextResponder.RightMouseDown() allows the event to percolate up through the view hierarchy so that it can still trigger the context menu.
[1]https://developer.apple.com/library/mac/documentation/cocoa/Reference/ApplicationKit/Classes/NSView_Class/Reference/NSView.html#//apple_ref/occ/instm/NSView/rightMouseDown: [2]https://developer.apple.com/library/mac/documentation/cocoa/conceptual/eventoverview/HandlingMouseEvents/HandlingMouseEvents.html [3]https://developer.apple.com/library/mac/documentation/cocoa/conceptual/eventoverview/EventArchitecture/EventArchitecture.html#//apple_ref/doc/uid/10000060i-CH3-SW21