在TextHover中显示超链接

时间:2019-08-12 18:57:28

标签: java eclipse eclipse-plugin

我正在尝试编写一个自定义的eclipse插件,以为通用编辑器扩展一些新语言的功能。该语言具有大量内置的原始函数(例如+或-),并且由于大多数用户都不知道所有这些原始函数,因此我尝试实现ITextHover,当将鼠标悬停在其中的一个上时,它将显示信息。原语。特别是,它应该提供指向在线语言参考的链接。

我已经能够显示带有一些基本格式的html的文本悬停了(请参见下面的代码),但是它不会显示任何超链接。

有什么想法可以做,以便正确显示链接吗?

public class HoverProvider implements ITextHover, ITextHoverExtension {


    @Override
    public IRegion getHoverRegion(ITextViewer tv, int off) {
        return new Region(off, 0);
    }

    @Override
    public String getHoverInfo(ITextViewer tv, IRegion r) {
        try {
            DocumentHandler document = new DocumentHandler(tv.getDocument());
            char ch = document.getCharAt(r.getOffset());
            if (ch == 'D') {
                return "<h1>Information</h1> <a href="http://google.com">http://google.com</a>";
            }
                return "";
        } catch (Exception e) {
            return "";
        }
    }

    @Override
    public IInformationControlCreator getHoverControlCreator() {
        return new IInformationControlCreator() {
            @Override
            public IInformationControl createInformationControl(Shell parent) {
                DefaultInformationControl dic = new DefaultInformationControl(parent,
                    EditorsUI.getTooltipAffordanceString());
                dic.setBackgroundColor(new Color(Display.getCurrent(), new RGB(254, 255, 204)));
                return dic;
            }
        };
    }
}

0 个答案:

没有答案
相关问题