Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Best way to embed Links in Text
Best way to embed Links in Text [message #509324] Thu, 21 January 2010 23:30 Go to next message
Christian is currently offline ChristianFriend
Messages: 72
Registered: July 2009
Member
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?

regards
Christian
Re: Best way to embed Links in Text [message #509528 is a reply to message #509324] Fri, 22 January 2010 17:08 Go to previous messageGo to next message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2150
Registered: July 2009
Senior Member
Hi Christian,

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:

http://www.eclipse.org/articles/Article-SWT-DND/DND-in-SWT.h tml
http://www.eclipse.org/swt/snippets#clipboard
swt's ClipboardExample in http://www.eclipse.org/swt/examples.php

HTH,
Grant


"Christian" <fakemail@xyz.de> wrote in message
news:hjao28$ev1$1@build.eclipse.org...
> 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?
>
> regards
> Christian
Re: Best way to embed Links in Text [message #509585 is a reply to message #509528] Sat, 23 January 2010 10:53 Go to previous message
Christian is currently offline ChristianFriend
Messages: 72
Registered: July 2009
Member
Am 22.01.2010 18:08, schrieb Grant Gayed:
> 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?).
>

I am using eclipse's build in copy command (org.eclipse.ui.edit.copy) to
copy text assuming it just uses the copy() method of styled text for
copying text to the clipboard.
So I probably should just overwrite that copy() method. Though have to
check this.

Christian
Previous Topic:Developing on Windows, Running on OS X, Help!
Next Topic:Using EMF+ with SWT
Goto Forum:
  


Current Time: Thu Apr 25 03:42:33 GMT 2024

Powered by FUDForum. Page generated in 0.02936 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top