• 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
Re: Respond to Click in TextView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Respond to Click in TextView


  • Subject: Re: Respond to Click in TextView
  • From: Michael Terry <email@hidden>
  • Date: Sun, 27 Aug 2006 22:46:23 -0700


On Aug 27, 2006, at 9:27 PM, Michael Ash wrote:

On 8/27/06, Michael Terry <email@hidden> wrote:

On Aug 27, 2006, at 5:46 AM, Michael Ash wrote:
> Now, solutions:
>
> 1) If what you care about is moving the insertion point around or
> changing the selection, look at
> NSTextViewDidChangeSelectionNotification. The insertion point is
> counted as a zero-size selection, so this gets fired for moving the
> insertion point too.
>
> 2) If you really need all mouse down events, even the ones that don't
> move the insertion point, subclass NSView and override mouseDown:.
> Don't forget to call super in the cases where you need the default
> behavior.


Thanks very much. I intend to change the background color of any text
selected by a shift click. Unless you have any better idea, it looks
like option 2 will work.

I'm sure you've thought of this, but in case you haven't, this is a pretty nonstandard sort of user interface. Normally shift-clicks just extend the selection and don't trigger any sort of action. Perhaps a better approach would be to have a button or menu command that acts on the current selection.

You could be right. I implemented it today using menu/button and I'll see whether it annoys me in regular use.



Anyway, it's generally better to use a notification or delegate method rather than subclassing when it's possible. In this case it should be possible. NSTextViewDidChangeSelectionNotification gets triggered whenever the selection changed. In your notification method you can ask NSApp or your window for the current event and make decisions based on that. If you only want to take action when the shift key is down, check the modifiers. If you only want to do something on mouse events, check the event type.

In the end it's possible that the notification approach would end up
being overcomplicated, but from where I see it now, it seems like the
better way.

Ok, good, that's what I'll do, if I do do it. Everything I read takes such pains to warn me off of subclassing that I'm dreading ever having to. Also, I didn't realize getting the modifiers would be easy using a notification. Glad someone reads the list on Sundays!


Michael
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Re: Respond to Click in TextView
      • From: "Michael Ash" <email@hidden>
References: 
 >Respond to Click in TextView (From: Michael Terry <email@hidden>)
 >Re: Respond to Click in TextView (From: "Michael Ash" <email@hidden>)
 >Re: Respond to Click in TextView (From: Michael Terry <email@hidden>)
 >Re: Re: Respond to Click in TextView (From: "Michael Ash" <email@hidden>)

  • Prev by Date: Re: Problem with NSWorkspaceDidMountNotification and FSResolveAlias()
  • Next by Date: Re: Creating stop motion movies
  • Previous by thread: Re: Re: Respond to Click in TextView
  • Next by thread: Re: Re: Respond to Click in TextView
  • Index(es):
    • Date
    • Thread