Re: How to override [NSTextField paste:]
Re: How to override [NSTextField paste:]
- Subject: Re: How to override [NSTextField paste:]
- From: Kyle Sluder <email@hidden>
- Date: Fri, 15 Jun 2012 11:06:34 -0700
On Jun 14, 2012, at 11:04 PM, Graham Cox wrote:
> Is there a way to override the -paste: method of NSTextField, other than subclassing?
>
> I have a situation where I want to handle paste for several related text entry fields at once. I have implemented -paste: in the controller for these, but of course it goes to first responder which is the text field itself (or its editor) which isn't what I want. Subclassing the field is an option, but because of the Field Editor, I'm not sure it's what is really needed.
-paste: is handled by NSTextView (by virtue of being an NSText subclass), not by the NSTextField for which it is acting as a field editor.
Your best bet is probably to retarget the Paste menu item to use a different selector that is picked up by your window controller. Then also implement this selector on your NSApplication delegate (or subclass) to re-send -paste: as a backstop in case an instance of your window controller isn't in the responder chain.
// Warning: composed in Mail.app
@implementation MyWindowController
- (IBAction)myPaste:(id)sender {
[self.textView1 setString:…];
[self.textView2 setString:…];
}
@end
@implemenation MyAppDelegate
- (IBAction)myPaste:(id)sender {
[NSApp sendAction:@selector(paste:) to:nil from:sender];
}
@end
--Kyle Sluder
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden