Eclipse RCP:Eclipse 4.6 工具栏中搜索文本的高度

Eclipse RCP: Height of a search text in the toolbar in Eclipse 4.6

我有一个 Eclipse 3.8 RCP 应用程序,它 运行 在 Eclipse 4.4 平台上使用 compatibility layer。 在工具栏中有一个搜索文本,如下所示:

但是当我 运行 Eclipse 4.6 上的应用程序时,它看起来像这样:

搜索文本是通过 plugin.xml 中的以下扩展点添加的:

<extension point="org.eclipse.ui.menus">
<menuContribution
    locationURI="toolbar:org.eclipse.ui.trim.command2">
    <toolbar id="search.toolbar">
    <control 
        class="app.SearchText"
        id="app.SearchText">
    </control>
    </toolbar>
</menuContribution>
</extension>

SearchText class 看起来像这样:

public class SearchText extends WorkbenchWindowControlContribution {

// ...

@Override
protected Control createControl(Composite parent) {
    parent.setLayout(new FillLayout());
    log.trace("create search text control");
    Composite composite = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    layout.horizontalSpacing = 5;
    layout.marginHeight = 0;
    layout.marginWidth = 5;
    layout.verticalSpacing = 0;
    composite.setLayout(layout);
    text = new Text(composite, SWT.BORDER | SWT.SEARCH);
    // ...
    return composite;
}

// ...

我尝试了布局参数但没有成功,我不知道如何 这可以修复。感谢您对此的任何帮助!

我刚才报告了一个错误:main toolbar control contributions is cut off

解决方法如下:

class 应该扩展 ControlContribution 而不是 WorkbenchWindowControlContribution

YourApplicationNameActionBarAdvisor.fillCoolBar()(替换 YourApplicationName)中添加:toolbar.add(new SearchText());



这里报告的错误的打印屏幕,必须是同一个问题。

使用 Eclipse Luna (4.4.2) 进行测试

使用 Eclipse Mars (4.5.0) 进行测试

对于 Eclipse Oxygen (4.7),this issue 上发布的以下解决方法对我有用:

public class MyWorkbenchWindowControlContribution extends
    WorkbenchWindowControlContribution {

  @Override
  protected Control createControl(Composite parent) {
    parent.getParent().setRedraw(true);
    ....
  }

  @Override
  public boolean isDynamic() {
    return true;
  }
  ...