• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
[SOLVED] Re: How to override [NSTextField paste:]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[SOLVED] Re: How to override [NSTextField paste:]


  • Subject: [SOLVED] Re: How to override [NSTextField paste:]
  • From: Graham Cox <email@hidden>
  • Date: Sat, 16 Jun 2012 09:23:03 +1000

On 16/06/2012, at 4:06 AM, Kyle Sluder wrote:

> Your best bet is probably to retarget the Paste menu item to use a different selector that is picked up by your window controller.

Thanks Kyle,

Unfortunately the standard paste: selector is used extensively elsewhere in my app, so this simple solution would not be so simple. This is an otherwise very self-contained modal dialog that doesn't have much to do.

I solved it as follows:


My window controller, which is the window's delegate, implements -windowWillReturnFieldEditor:forObject:. I return a subclass of NSTextView which overrides -paste: and adds a property, -pasteDelegate: which I set to be the window controller. (I believe the FE's nextResponder is usually also the windowController, but I wasn't entirely sure I could rely on that, so I just added an extra property to hook it up). Then I just punt -paste to the -pasteDelegate (and also -validateMenuItem for that action).

Works great. In conjunction with some text editing delegate methods I have excellent control over the text fields and the subclassing was absolutely minimal.


--Graham



_______________________________________________

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

  • Follow-Ups:
    • Re: [SOLVED] Re: How to override [NSTextField paste:]
      • From: Kyle Sluder <email@hidden>
References: 
 >How to override [NSTextField paste:] (From: Graham Cox <email@hidden>)
 >Re: How to override [NSTextField paste:] (From: Kyle Sluder <email@hidden>)

  • Prev by Date: Re: NSTextField Selection
  • Next by Date: Re: [SOLVED] Re: How to override [NSTextField paste:]
  • Previous by thread: Re: How to override [NSTextField paste:]
  • Next by thread: Re: [SOLVED] Re: How to override [NSTextField paste:]
  • Index(es):
    • Date
    • Thread