« Return to Thread: textbuffer urls
To create a link:
* Create a TextTag with no name ("new TextTag(null)").
* Set the visual appearance you want (blue, underlined, etc.).
* Store the hyperlink target somewhere, probably a Dictionary<TextTag,
string> would be the most useful.
* Don't forget to add the tag to the TextBuffer.TagTable.
* Apply the tag to the text where you want the link.
Then during construction of the buffer you need to attach a handler to
the mouse movement signal (I forget what it's called) as well as the
clicked signal. When either are fired you will have to:
* Obtain the X,Y coordinates of the movement/click.
* Map these somehow to a TextIter.
Then, in the movement handler you will then want to conditionally set
the mouse pointer to the "hand" pointer or the normal one, based on
whether or not a hyperlink tag is present. You could use a LINQ query
to determine this, something like "bool hyperlink = (from i in
iter.Tags where dictionary.ContainsKey(i) select i).FirstOrDefault()
!= null;" (this is from memory, you may have to tweak it).
In the click handler you can do something like "TextTag linktag =
(from i in iter.Tags where dictionary.ContainsKey(i) select
i).FirstOrDefault();" and then if linktag != null you can do "string
url = dictionary[linktag];" to obtain the URL you stored and use it
however you wish.
Don't forget that when you remove text containing a link you should
remove the TextTag from the TextBuffer.TagTable and also
dictionary.Remove(tag).
Hope this helps!
--
Chris Howie
http://www.chrishowie.com
http://en.wikipedia.org/wiki/User:Crazycomputers
« Return to Thread: textbuffer urls
| Free embeddable forum powered by Nabble | Forum Help |