[英]Toolbar dissapears from custom hover in eclipse editor
I am working on an editor plugin for Eclipse that handles my own script language. 我正在为Eclipse编辑器插件,该插件可处理我自己的脚本语言。 In the editor, I have a hover that shows short information about element under the mouse cursor. 在编辑器中,我有一个鼠标悬停在鼠标指针下方显示有关元素的简短信息。 Now, I am trying to create a toolbar on the bottom of the hover and place a button there that will open a more detailed description online. 现在,我试图在悬停底部创建一个工具栏,并在此处放置一个按钮,该按钮将在网上打开更详细的描述。
I have written my code based on answer to that question . 我已经根据对该问题的答案编写了代码。 The button is visible and it works when it is clicked. 该按钮是可见的,单击后即可使用。 However, it disappears a short time after I move my mouse over the hover. 但是,在我将鼠标移到悬停鼠标后不久,它消失了。 Why is this happening and how can I prevent that? 为什么会发生这种情况,我该如何预防呢?
Here is the relevant part of my code: 这是我的代码的相关部分:
@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;
}
};
}
When hover is created with DefaultInformationControl(parent, tbm) then toolbar is visible. 当使用DefaultInformationControl(parent,tbm)创建悬停时,工具栏将可见。 However when you move mouse over the hover, then it gains focus. 但是,当您将鼠标移到悬停上时,它将获得焦点。 Then method getInformationPresenterControlCreator() from DefaultInformationControl is called. 然后,将调用DefaultInformationControl中的getInformationPresenterControlCreator()方法。
It looks like (from source code): 看起来像(从源代码):
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);
}
};
}
Look at return line. 看回车线。 It nulls your Toolbar manager. 它使您的工具栏管理器为空。 That is the reason is gone. 那是原因不见了。
Quick solution might be to create a new class which extends DefaultInformationControl and then in overrides 快速解决方案可能是创建一个新类,该类扩展DefaultInformationControl,然后进行覆盖
@Override
public IInformationControlCreator getInformationPresenterControlCreator() {
return new YourOwnInformationControlCreator();
}
This way you can pass correct ToolbarManager. 这样,您可以传递正确的ToolbarManager。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.