【问题标题】:Toolbar dissapears from custom hover in eclipse editor工具栏从 Eclipse 编辑器中的自定义悬停中消失
【发布时间】:2018-02-13 13:59:24
【问题描述】:

我正在为处理我自己的脚本语言的 Eclipse 开发一个编辑器插件。在编辑器中,我有一个悬停显示鼠标光标下元素的简短信息。 现在,我正在尝试在悬停的底部创建一个工具栏,并在那里放置一个按钮,该按钮将在线打开更详细的描述。

我已经根据answer to that question 编写了我的代码。该按钮是可见的,并在单击时起作用。 但是,在我将鼠标移到悬停上后不久,它就会消失。为什么会发生这种情况,我该如何预防?

这是我的代码的相关部分:

@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;
        }
    };
}

【问题讨论】:

    标签: java eclipse eclipse-plugin editor mousehover


    【解决方案1】:

    当使用 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。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-02-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多