在自定义悬停内显示 link(Eclipse 插件开发)
Showing link inside custom hover (Eclipse plugin development)
我在 CDT 编辑器中有一个自定义悬停(请参阅 linked SO 问题),现在我想在我的 IAnnotationHover
悬停中显示 link:
public class MyAwesomeHover implements IAnnotationHover {
@Override
public String getHoverInfo(ISourceViewer sw, int ln) {
return "<a href='www.whosebug.com'>so</a>"
}
}
遗憾的是 link 未显示 - 悬停 window 仅显示简单文本(即 "so")。我试过的其他 HTML 元素工作正常(ul、li、p、font ...)。谁能帮帮我吗?
如评论中所述,RevisionHover
是一个很好的起点。神奇之处在于实施 IAnnotationHoverExtension
和创建自定义 AbstractReusableInformationControlCreator
。我正在发布一个代码片段,其中包含对我有用的解决方案。
public class MyHover implements IAnnotationHover, IAnnotationHoverExtension {
...
@Override
public IInformationControlCreator getHoverControlCreator() {
return new MyCreator();
}
...
@Override
public Object getHoverInfo(ISourceViewer sv, ILineRange lr, int vnl) {
return "<a href='www.whosebug.com'>so</a>";
}
...
private final class MyCreator extends AbstractReusableInformationControlCreator {
protected IInformationControl doCreateInformationControl(Shell parent) {
BrowserInformationControl control =
new BrowserInformationControl(
parent,
JFaceResources.DIALOG_FONT,
false);
control.addLocationListener(
new LocationAdapter() {
@Override
public void changing(LocationEvent ev) {
if (ev.location.startsWith("file:")) {
// !This opens the link!
openUrl(ev.location)
}
}
});
return control;
}
}
}
我在 CDT 编辑器中有一个自定义悬停(请参阅 linked SO 问题),现在我想在我的 IAnnotationHover
悬停中显示 link:
public class MyAwesomeHover implements IAnnotationHover {
@Override
public String getHoverInfo(ISourceViewer sw, int ln) {
return "<a href='www.whosebug.com'>so</a>"
}
}
遗憾的是 link 未显示 - 悬停 window 仅显示简单文本(即 "so")。我试过的其他 HTML 元素工作正常(ul、li、p、font ...)。谁能帮帮我吗?
如评论中所述,RevisionHover
是一个很好的起点。神奇之处在于实施 IAnnotationHoverExtension
和创建自定义 AbstractReusableInformationControlCreator
。我正在发布一个代码片段,其中包含对我有用的解决方案。
public class MyHover implements IAnnotationHover, IAnnotationHoverExtension {
...
@Override
public IInformationControlCreator getHoverControlCreator() {
return new MyCreator();
}
...
@Override
public Object getHoverInfo(ISourceViewer sv, ILineRange lr, int vnl) {
return "<a href='www.whosebug.com'>so</a>";
}
...
private final class MyCreator extends AbstractReusableInformationControlCreator {
protected IInformationControl doCreateInformationControl(Shell parent) {
BrowserInformationControl control =
new BrowserInformationControl(
parent,
JFaceResources.DIALOG_FONT,
false);
control.addLocationListener(
new LocationAdapter() {
@Override
public void changing(LocationEvent ev) {
if (ev.location.startsWith("file:")) {
// !This opens the link!
openUrl(ev.location)
}
}
});
return control;
}
}
}