简体   繁体   English

带有Eclipse Look的Eclipse RCP工具栏按钮

[英]Eclipse RCP Toolbar buttons with the Eclipse Look

In Eclipse, its easy to specify buttons for your toolbar using the ActionSets extension point. 在Eclipse中,使用ActionSets扩展点可以轻松为工具栏指定按钮。 However, when I need to specify some items programmatically, I can't get the same look. 但是,当我需要以编程方式指定一些项目时,我不会得到相同的外观。 I don't believe that the framework is using native buttons for these, but so far, I can't find the right recipe to match the Eclipse look. 我不认为该框架会使用本机按钮,但是到目前为止,我找不到适合Eclipse外观的正确配方。 I wanted to see if anyone has found the right snippet to duplicate this functionality in code. 我想看看是否有人找到了正确的代码段来复制此功能。

It's difficult to tell from your question, but it sounds like you may be attempting to add a ControlContribution to the toolbar and returning a Button. 从您的问题很难分辨,但是听起来您可能正在尝试向工具栏添加ControlContribution并返回Button。 This would make the button on the toolbar appear like a native button like you seem to be describing. 这将使工具栏上的按钮看起来像您似乎正在描述的本机按钮。 This would look something like this: 看起来像这样:

IToolBarManager toolBarManager = actionBars.getToolBarManager();
toolBarManager.add(new ControlContribution("Toggle Chart") {
    @Override
    protected Control createControl(Composite parent)
    {
        Button button = new Button(parent, SWT.PUSH);
        button.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
                // Perform action
            }
        });
     }
});

Instead you should add an Action to the toolbar. 相反,您应该向工具栏添加一个动作。 This will create a button on the toolbar that matches the standard eclipse toolbar buttons. 这将在工具栏上创建一个与标准Eclipse工具栏按钮匹配的按钮。 This would look something like this: 看起来像这样:

Action myAction = new Action("", imageDesc) {
    @Override
    public void run() {
        // Perform action
    }
};

IToolBarManager toolBarManager = actionBars.getToolBarManager();
toolBarManager.add(myAction);

Could you perhaps put in an extract of the code you have for adding actions programmatically to the toolbar? 您能否摘录一下要以编程方式向工具栏添加动作的代码的一部分? I assume you do this in an ApplicationActionBarAdvisor class? 我假设您在ApplicationActionBarAdvisor类中执行此操作? Their should be no difference in the look of buttons you add declaratively vs those you add programatically. 在以声明方式添加的按钮和以编程方式添加的按钮的外观上,它们应该没有区别。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM