簡體   English   中英

在Eclipse編輯器中,自定義懸停顯示工具欄

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM