« xDev Magazine Issue 1… | Home | MBS Xojo / Real Studi… »

Tip of the day: Adding links to Textarea on OS X

A recent question was how to put a link into a textarea. You can do this with MBS Plugin like the snippets below.
The first snippet here checks to see if current cursor position has a link set:
dim n as NSTextViewMBS = textarea1.NSTextViewMBS dim a as NSAttributedStringMBS = n.textStorage if a.Length > 0 then dim d as Dictionary = n.selectedTextAttributes dim r as NSRangeMBS = n.selectedRange if r.Location < a.Length then dim l as string = a.attributeAtIndex(a.NSLinkAttributeName, r.Location) InputField.Text = l Return end if end if InputField.Text = ""
Second snippet shows how to remove/add a link to the current selection:
dim n as NSTextViewMBS = TextArea1.NSTextViewMBS dim a as NSMutableAttributedStringMBS = n.textStorage if InputField.Text = "" then // remove link a.removeAttribute(a.NSLinkAttributeName, n.selectedRange) else // add one a.addAttribute(a.NSLinkAttributeName, InputField.text, n.selectedRange) end if
The biggest plugin in space...
09 07 15 - 03:19