1

When you have a row highlighted, and left OR right click on the highlighted cell, it goes in edit mode (even after X seconds of no activity, so it's not a double click action).

I would like to disable this and make it so that it only works if you double click, even if you have already selected the cell.

If that is not possible, I would at least like to disable the right click to edit functionality, as I have my own context menu that I want to show, but right clicking on the text triggers the edit with it's own context menu, instead of the context menu I receive when I click outside the text but in the cell.

Any methods that I can use for this?

Note: I still want to allow editing via the enter key.

1 Answer 1

0

Did not check it, but perhaps you can implement -control:textShouldBeginEditing: in the delegate and read the current event inside:

- (BOOL)control:(NSControl *)control textShouldBeginEditing:(NSText *)fieldEditor
{
  NSEvent *currentEvent = [NSApp currentEvent];
  switch (currentEvent.type)
  {
    case NSLeftMouseUp:
      if (currentEvent.clickCount<2)
      {
        return NO;
      }
      return YES;
    case NSRightMouseUp:
      return NO;
    default:
      return YES;
  }

Just an idea. Go ahead!

4
  • Thanks, but this seems to only be called after the text field is displayed, and the user tries typing in it. Returning NO disables the typing. I looked at - (BOOL)tableView:(NSTableView *)aTableView shouldEditTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex instead, but this seems to be only available for NSCell based tableviews.. Not view based ones.
    – user429620
    Nov 26, 2014 at 16:50
  • Yes, this is only for cell-based views. Another delegate method? Nov 26, 2014 at 18:39
  • Unfortunately there doesn't appear to be one.
    – user429620
    Nov 26, 2014 at 20:55
  • Well, i ended up setting the tableCellView to uneditable by default, and listening to keyDown events instead (to capture enter key), to set editable to true and give it first responder.
    – user429620
    Nov 27, 2014 at 8:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.