I have an NSTableView (with editable text cells) and a contextual menu. When a row is selected and I right click on a different row, this functionality works as intended (selected row changes to right-clicked row and my contextual menu pops up).
When the currently selected row is right-clicked then the text cell under the mouse changes to edit mode and the contextual menu for text editing (not defined by me) pops up. This is not the intended functionality.
Intended Functionality
- Text edit mode will only occur when a text cell is left clicked which that row is selected (this works correctly).
- Right click will only invoke my contextual menu.
It doesn't feel like this should be a difficult problem - perhaps even a problem that could be solved in Interface Builder - but I can't quite work out the solution.
I thought it might be one where I need to validateProposedFirstResponder
, so I added that to the superview - but that didn't work (and, with hindsight, I can see why)
- (BOOL)validateProposedFirstResponder:(NSResponder *)responder forEvent:(NSEvent *)event {
if ([responder isKindOfClass:[NSTextFieldCell class]] || [responder isKindOfClass:[NSTableCellView class]] || [responder isKindOfClass:[NSTextField class]] ) {
return NO;
}
return [super validateProposedFirstResponder:responder forEvent:event];
}
As you can see, I kind of chucked everything at the wall - but the only responder class that it can 'see' being clicked is NSTableView
I guess then (and it feels like a clunky solution), I need to subclass one of NSTextFieldCell, NSTableCellView or NSTextField class and implement validateProposedFirstResponder
there. Can anyone advise me which one though, or propose a better solution?