Re: Re: Respond to Click in TextView
Re: Re: Respond to Click in TextView
- Subject: Re: Re: Respond to Click in TextView
- From: "Michael Ash" <email@hidden>
- Date: Mon, 28 Aug 2006 00:27:35 -0400
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.
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.
Mike
_______________________________________________
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