|Re: Best way to embed Links in Text [message #509528 is a reply to message #509324]
||Fri, 22 January 2010 17:08
| Grant Gayed
Registered: July 2009
Note that as of eclipse/swt 3.5, StyledText has support for specifying a
block of text as a Link, see
https://bugs.eclipse.org/bugs/show_bug.cgi?id=83408 . Using this should
ensure that your links appear/behave properly.
Regarding changing a link text to a url when copied to the clipboard, there
isn't a way to make this just happen. You'll need to implement your own
copy functionality which takes a copy of the StyledText's content, does the
necessary link name -> url changes, and writes the content to the clipboard.
Whether you're able to get in the way of the StyledText's copy functionality
depends on your context (eg.- perhaps adding a SWT.KeyDown filter to the
Display and looking for the platform-specific Copy shortcut? Or if you're
defining a view, does eclipse send some sort of "do copy" notification to
your view when triggered by the user?).
For info about using the Clipboard see:
swt's ClipboardExample in http://www.eclipse.org/swt/examples.php
"Christian" <email@example.com> wrote in message
> Hello Group,
> I am trying to implement special URI presentation for a chatprogram in
> SWT using StyledText.
> Problem is the following ...
> Requirement 1:
> Links should be clickable (Browser should open.. in short need a
> backcall when the links is clicked)
> 2. Links might need a presentation in a more readable format ... some
> special URI should be presented with a human readable text instead of
> the pure URI.
> 3. When text is selected and copied the URI should be in the clipboard.
> 1 is simple to get..
> So far I tried using StyleRanges to colour the URI. But that does not
> make the replacement with readable text possible.
> I also tried embedding a Link widget in the StyledText. Which makes
> replacement with readable text easy. This seemed ideal as one could lay
> the Link widget with the readable text directly over the URI in the
> text, resulting on text marked that the URI was copied.
> Though that didn't work too well. GlyphMetrics seems to be inaccurate
> with multiple characters. As one can only give the width per character a
> control spanning over several charadcters will allways fail to be the
> same length as the URI. so with embedding controls its important to have
> only one character below the control. Though with one character below
> Link widget, on copying, the URI is not in the clipboard.
> Anyone got an idea what I could do? Any good/siomple solution that I
> miss to see?
Powered by FUDForum
. Page generated in 0.02102 seconds