Re: Formatters and TextViews
Re: Formatters and TextViews
- Subject: Re: Formatters and TextViews
- From: Rob Rix <email@hidden>
- Date: Mon, 10 Sep 2001 17:45:10 -0400
To handle links in an NSTextView, assign the relevant range the attribute
NSLinkAttributeName with some appropriate value. When the user clicks in
this range, the NSTextView will have its method
Okay, this is excellent, but after an extreme amount of searching through
the documentation (both on and offline, the later with the aid of
MTLibrarian), I am unable to figure out how I'm supposed to use
NSLinkAttributeName.
You say some appropriate value...does this mean that there is a class I
should be using there, or should I just make my own class that handles
links?
Later, you mention the delegate method of NSTextView that handles clicking
on links, which seems to suggest that I should make my own link class.
So, to reiterate, to assign the NSLinkAttributeName attribute, I should
use NSMutableAttributedString's -addAttributes:range: method on the
textStorage object of my NSTextView, and pass it a dictionary with the
entry:
key: NSLinkAttributeName
object: myGroovyLinkObject
Am I understanding this correctly?
- (void)clickedOnLink:(id)link atIndex:(unsigned)charIndex;
called, which will first try to call the delegate method (if implemented)
- (BOOL)textView:(NSTextView *)textView clickedOnLink:(id)link
atIndex:(unsigned)charIndex;
If that method is not implemented or returns NO, then it will try to
interpret the value of the link attribute as an NSURL or as an NSString
whose contents represent an URL, and if successful it will try to open
that URL.
If you use something other than absolute URLs as the values of your
NSLinkAttributeName, or if you want to do the opening yourself, then you
will probably need to implement the delegate method.
Okay, this is absolutely excellent. I'll be able to use both URLs and my
own links in my application now. Thanks very much for the help, Douglas!
-- Rob
Witticism forthcoming.