Is it possible to handle a mouse click in an NSTextView without subclassing it?

  • Good day all!

    I need to handle a mouse click in an NSTextView, so that action is
    taken when a user clicks on any particular character in it.
    I've read that it is done by creating a custom TextView.
    Are there any simpler variants available?

    Yours truly,
    Damian/Three-eyed Fish
  • I wouldn't exactly say it's a good day here, it's raining. ;)

    I don't think there is an easier way. Subclassing is very easy but if
    you are doing a lot of it it can get unmanageable. But still, there is
    no easier way.

    Good luck, Alan

    --
    // Quotes from yours truly -------------------------
    "You don't forget, you just don't remember."
    "Maturity resides in the mind."
    "Silence is the Universe's greatest gift."
    "When the World realizes that religion really is unimportant, then it
    shall evolve."
  • On 20 okt 2006, at 16.37, Damian Terentyev wrote:

    > Good day all!
    >
    > I need to handle a mouse click in an NSTextView, so that action is
    > taken when a user clicks on any particular character in it.
    > I've read that it is done by creating a custom TextView.
    > Are there any simpler variants available?
    >
    > Yours truly,
    > Damian/Three-eyed Fish
    >
    Can't you use delegation?

    ------------------------------------------------------
    "Home is not where you are born, but where your heart finds peace" -
    Tommy Nordgren, "The dying old crone"
    <tommy.nordgren...>
  • On Friday, October 20, 2006, at 09:39AM, Damian Terentyev <threeeyedfish...> wrote:

    > I need to handle a mouse click in an NSTextView, so that action is
    > taken when a user clicks on any particular character in it.
    > I've read that it is done by creating a custom TextView.
    > Are there any simpler variants available?

    Depending upon what you're actually putting in the text view (e.g. are the clickable characters part of links?), you could use delegate methods like textView:clickedOnLink:atIndex:

    You could even use text attachments too.

    If it's the case where your text view will just contain raw text and you need to handle mouse-down in general, then I think you'll need to subclass.

    --
    Rick Sharp
    Instant Interactive(tm)
  • On Oct 20, 2006, at 9:12 AM, Ricky Sharp wrote:

    > Depending upon what you're actually putting in the text view (e.g.
    > are the clickable characters part of links?), you could use
    > delegate methods like textView:clickedOnLink:atIndex:
    >
    > You could even use text attachments too.
    >
    > If it's the case where your text view will just contain raw text
    > and you need to handle mouse-down in general, then I think you'll
    > need to subclass.

    It really depends on what you want to do.  The delegate methods are
    generally at a higher level of abstraction--for example, there is a
    delegate method for changes in the selection, and most clicks on the
    text will change the selection.

    Douglas DAvidson
  • Thank you!
    It really was *that* easy!

    Damian/Three-eyed Fish

    On Oct 20, 2006, at 19:01, Alan Smith wrote:

    > I wouldn't exactly say it's a good day here, it's raining. ;)
    >
    > I don't think there is an easier way. Subclassing is very easy but if
    > you are doing a lot of it it can get unmanageable. But still, there is
    > no easier way.
    >
    > Good luck, Alan
    >
    >
    > --
    > // Quotes from yours truly -------------------------
    > "You don't forget, you just don't remember."
    > "Maturity resides in the mind."
    > "Silence is the Universe's greatest gift."
    > "When the World realizes that religion really is unimportant, then it
    > shall evolve."
    >
previous month october 2006 next month
MTWTFSS
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          
Go to today