![](/img/trans.png)
[英]How to create an Error Hover for Syntax Errors in a custom Eclipse Editor
[英]Toolbar dissapears from custom hover in eclipse editor
我正在为Eclipse编辑器插件,该插件可处理我自己的脚本语言。 在编辑器中,我有一个鼠标悬停在鼠标指针下方显示有关元素的简短信息。 现在,我试图在悬停底部创建一个工具栏,并在此处放置一个按钮,该按钮将在网上打开更详细的描述。
我已经根据对该问题的答案编写了代码。 该按钮是可见的,单击后即可使用。 但是,在我将鼠标移到悬停鼠标后不久,它消失了。 为什么会发生这种情况,我该如何预防呢?
这是我的代码的相关部分:
@Override
public IInformationControlCreator getHoverControlCreator() {
return new IInformationControlCreator() {
@Override
public IInformationControl createInformationControl(final Shell parent) {
ToolBarManager tbm = new ToolBarManager(SWT.FLAT);
DefaultInformationControl defaultInformationControl = new DefaultInformationControl(parent, tbm);
Action action = new Action() {
@Override
public void run() {
MessageDialog.openInformation(parent, "omg", "It works.");
}
};
action.setText("123 test 321");
Bundle bundle = FrameworkUtil.getBundle(this.getClass());
URL url = FileLocator.find(bundle, new Path("icons/test.gif"), null);
action.setImageDescriptor(ImageDescriptor.createFromURL(url));
tbm.add(action);
tbm.update(true);
return defaultInformationControl;
}
};
}
当使用DefaultInformationControl(parent,tbm)创建悬停时,工具栏将可见。 但是,当您将鼠标移到悬停上时,它将获得焦点。 然后,将调用DefaultInformationControl中的getInformationPresenterControlCreator()方法。
看起来像(从源代码):
public IInformationControlCreator getInformationPresenterControlCreator() {
return new IInformationControlCreator() {
/*
* @see org.eclipse.jface.text.IInformationControlCreator#createInformationControl(org.eclipse.swt.widgets.Shell)
*/
public IInformationControl createInformationControl(Shell parent) {
return new DefaultInformationControl(parent,
(ToolBarManager) null, fPresenter);
}
};
}
看回车线。 它使您的工具栏管理器为空。 那是原因不见了。
快速解决方案可能是创建一个新类,该类扩展DefaultInformationControl,然后进行覆盖
@Override
public IInformationControlCreator getInformationPresenterControlCreator() {
return new YourOwnInformationControlCreator();
}
这样,您可以传递正确的ToolbarManager。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.