| Summary: | Support links in StyledText | ||
|---|---|---|---|
| Product: | [Eclipse Project] Platform | Reporter: | Veronika Irvine <veronika_irvine> |
| Component: | SWT | Assignee: | Felipe Heidrich <eclipse.felipe> |
| Status: | RESOLVED FIXED | QA Contact: | |
| Severity: | enhancement | ||
| Priority: | P3 | CC: | bpasero, bradleyjames, c.hauser, daniel_megert, dejan, eclipse, heath.borders, hjbingo19921216, michaelvanmeekeren, mlists, ovidr, scottf, snorthov, susan |
| Version: | 3.1 | ||
| Target Milestone: | 3.5 M4 | ||
| Hardware: | PC | ||
| OS: | All | ||
| Whiteboard: | |||
|
Description
Veronika Irvine
*** Bug 83429 has been marked as a duplicate of this bug. *** Post 3.1. [document from bug 83406] - an image can be a link: "A nice enhancement is support of images as links. This means: 1) Image links participate in tabbing order 2) Focus indication is drown around them when in focus 3) Mouse changes when over the image link 4) Image can be changed when mouse is over ('hover' image) 5) The same event is fired as for textual links for enter, exit and activation. Also, image should be selectable with the rest of the text. It should be ignored in simple text clipboard content type but added in RTF content type." In the textual editors we mimic similar support but don't show the links per default (too many and too expensive to compute) but only when the 'Ctrl' key is pressed and the mouse is over a detected link. For us this new feature would be interesting if existing simple text inside StyledText can be turned into a link on the fly. For the first cut, the thinking is to implement link as a regular html link (always blue, underline, cursor hover, click action), the same sort that you find in a browser and email rich text editor. Fixed in HEAD > 20081111
use TextStyle.underlineStyle = SWT.UNDERLINE_LINK
that sets single underline and sets the foreground to the native link color.
note that the foreground color can be overwritten by TextStyle.foreground, to overwrite the color only of the underline use TextStyle.underlineColor.
StyledText automatically sets the cursor during mouse move. But it doesn't provide an event for click on link.
One can use TextStyle.data field to store the href, for example:
public void handleMouseDown(Event event) {
int offset = styledText.getOffsetAtLocation(event.x, event.y);
StyleRange range styledText.getStyleRangeAtOffset(offset);
if (range != null && range.underlineStyle == SWT.UNDERLINE_LINK) {
String href = (String)range.data;
//do whatever you have to do
}
}
Tried to use it and it almost works ;-) The problem is that the native underline color isn't used if the text is already colored. To test 1. start the SWT Text Editor sample 2. add some text 3. give it a foreground color 4. mark it as link ==> native link color is not applied If you agree that this should work I'll open a bug. For me this is a hard requirement because otherwise I cannot apply the native link color as I don't have a handle on it. Just to clarify: I need the SWT.UNDERLINE_LINK together with these three variants: - color == null ==> use text color / don't apply a color - color != null ==> use color - NEW: some flag (or color) for native link coloring So either I need - a handle on the native link color or RGB (preferred) - a new style SWT.UNDERLINE_LINK_NATIVE which will always use native colors and ignore any given colors (underlineColor, foreground) and overwrites the existing text color Not sure I understood the problem but in my understanding you can implement all three cases with the current support: 1) link + default text color style.underline = true; style.underlineStyle = SWT.UNDERLINE_LINK; style.underlineColor = null; style.foreground = styledText.getForeground(); 2) link + native link color style.underline = true; style.underlineStyle = SWT.UNDERLINE_LINK; style.underlineColor = null; style.foreground = null; 3) link + custom color style.underline = true; style.underlineStyle = SWT.UNDERLINE_LINK; style.underlineColor = null; style.foreground = customColor; Is it possible for you to use link like this ? Problem is that the text is already colored and the editor framework simply merges the styles it collects from it clients, hence 'null' leave the text colored as is. What I need is bug 181592. (In reply to comment #8) > - a handle on the native link color or RGB (preferred) I like this option better. We have problem report for this: Bug 181592 OK, I have reworked my code a bit so that it behaves better when there's already an error/warning at the same place. This rework also removes the need for a separate link color. However, I find that the current native link color is too dark (I filed bug 255630) to track this. Recently I met a problem.I test my code with the following example The contents of styledtext are www.yahoo.com www.yahoo.com www.yahoo.com which are in separated lines. Thus, some of my offsets are duplicated and something is wrong with this sentense "m_text.setStyleRanges(ranges, styles);", where m_text is type of styledtext. How can I solve this problem? Any suggestion is welcome! |