gngrwzrd

NSTextField Edit In Place on Double Click

Apr 21st, 2015
313
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #import <Cocoa/Cocoa.h>
  2. @interface EditTextField : NSTextField <NSTextDelegate>
  3. @end
  4.  
  5. ---
  6.  
  7. #import "EditTextField.h"
  8.  
  9. @implementation EditTextField
  10.  
  11. - (void) mouseDown:(NSEvent *)theEvent {
  12.     if(theEvent.clickCount == 2) {
  13.         self.editable = TRUE;
  14.         NSText * fieldEditor = [self.window fieldEditor:TRUE forObject:self];
  15.         [self.cell editWithFrame:self.bounds inView:self editor:fieldEditor delegate:self event:theEvent];
  16.     } else {
  17.         [super mouseDown:theEvent];
  18.     }
  19. }
  20.  
  21. - (void) cancelOperation:(id)sender { //cancel key triggers cancelOperation on firstResponder.
  22.     NSText * fieldEditor = [self.window fieldEditor:TRUE forObject:self];
  23.     [self.cell endEditing:fieldEditor];
  24.     self.editable = FALSE;
  25. }
  26.  
  27. @end
Advertisement
Add Comment
Please, Sign In to add comment