DSClickableURLTextField is a subclass of NSTextField that does one thing: allow links to be clicked on and opened.
To use this class, all you need to do is set the text field's attributed string value, with some portion of it being a link, and the text field will do the rest. You'll get the “pointy hand” cursor over the link, and clicking on it will open that link.
Note that the class only works if it is non-editable and non-selectable. This is setup by default, but I wanted to mention it so nobody wastes time trying to figure out why the text field is acting the way it is.
Returns if the text field allows copying of URLs to the clipboard.
If the text field allows copying of URLs, returns YES, otherwise returns NO.
If the text field allows copying of URLs, it will pop up a menu allowing the user to copy the URL to the clipboard.
By default, this is set to NO.
Action used to copy an URL to the clipboard.
The menu item the user selected in the pop up menu.
This is the action method called by the “Copy URL” menu item in the pop up menu shown to the user. You should never call this method directly — the URL is set as the menu item's represented object and is referenced that way.
Resets the cursor rects used to show the cursor over links.
Resets the cursor rects used to show the “pointy hand” cursor over links. Note that unless the text field is empty or you're running on 10.2 or earlier, this method doesn't call to super.
This method is called automatically; there should be no need to call it directly.
Sets the text field's attributed string value.
The attributed string you wish the text field to display.
This method sets the attributed string value and resets the text field's cursor rects.
Sets if the text field will allow copying of URLs to the clipboard.
If YES, the text field will allow copying URLs to the clipboard.
Sets the text field's string value.
The string you wish the text field to display.
This method converts the string to an attributed string, then calls —setAttributedStringValue: with it.
Note that if you set a simple string value, the text field will have no links.
Returns the link at the given mouse coordinates.
The mouse event that generated the event.
Returns the link under the mouse position, or nil if there is no link at that position.
This method must only be called by -mouseDown: or -mouseUp:, never directly.
Lets the text field's delegate handle an URL.
The text field being clicked on.
The link being clicked on.
If the delegate handles the URL, return YES otherwise return NO.
You can use this method to handle custom URL schemes or open an URL in a different manner than the default (passing it to NSWorkspace to open the URL).