簡體   English   中英

如何將工具欄添加到Java文本懸停蝕

[英]How to add toolbar to java text hover eclipse

我正試圖為Eclipse創建自己的文本懸停插件。 我成功地在懸停中編寫了自己的代碼,但是我嘗試將工具欄添加到懸停中(在打開的新工具提示中)。 我讀到我需要使用getHoverControlCreator函數,並設法添加了在運行插件時打開文本懸停時看到的工具欄管理器,在調試器中我可以看到ToolBarManger的ToolBar帶有ToolItems,但是當我打開它時,我無法在真實文本懸停中看到它們。

這是我的代碼:

public IInformationControlCreator getHoverControlCreator() {
        return new IInformationControlCreator() {
            public IInformationControl createInformationControl(Shell parent) {
                ToolBar tb = new ToolBar(parent, SWT.HORIZONTAL);
                ToolBarManager tbm = new ToolBarManager(tb);
                DefaultInformationControl dic = new DefaultInformationControl(parent, tbm);
                ToolItem ti = new ToolItem(tb, SWT.PUSH);
                ti.setText("hello");
    tb.update();
    tb.redraw();
    tbm.update(true);
    parent.update();
    parent.redraw();

    parent.layout();

                return dic;
            }

這是Eclipse懸停控件之一的作用:

@Override
public IInformationControl doCreateInformationControl(Shell parent) {
    ToolBarManager tbm = new ToolBarManager(SWT.FLAT);

    DefaultInformationControl iControl = new DefaultInformationControl(parent, tbm);

    IAction action = new MyAction();
    tbm.add(action);

    tbm.update(true);

    return iControl;
}

因此,它不會創建ToolBar ,而是保留它為DefaultInformationControl 它在工具欄中使用一個Action ,並在創建DefaultInformationControl之后將其添加。 它只是在最后調用update(true)

(這是org.eclipse.jdt.internal.ui.text.java.hover.NLSStringHover的一部分的修改版)

MyAction將類似於:

private class MyAction extends Action
{
  MyAction()
  {
    super("Title", .. image descriptor ..);

    setToolTipText("Tooltip");
  }

  @Override
  public void run()
  {
    // TODO your code for the action
  }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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