带有Eclipse Look的Eclipse RCP工具栏按钮 [英] Eclipse RCP Toolbar buttons with the Eclipse Look
问题描述
在Eclipse中,可以使用ActionSets扩展点轻松为您的工具栏指定按钮.但是,当我需要以编程方式指定一些项目时,我不会得到相同的外观.我不相信该框架正在使用本机按钮,但是到目前为止,我找不到适合Eclipse外观的正确配方.我想看看是否有人找到了正确的代码段来复制此功能.
In Eclipse, its easy to specify buttons for your toolbar using the ActionSets extension point. 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. I wanted to see if anyone has found the right snippet to duplicate this functionality in code.
推荐答案
很难从您的问题中分辨出来,但是听起来您可能正在尝试将ControlContribution添加到工具栏并返回Button.这将使工具栏上的按钮看起来像您似乎正在描述的本机按钮.看起来像这样:
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. 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
}
});
}
});
相反,您应该在工具栏上添加一个动作.这将在工具栏上创建一个与标准Eclipse工具栏按钮匹配的按钮.看起来像这样:
Instead you should add an Action to the toolbar. This will create a button on the toolbar that matches the standard eclipse toolbar buttons. This would look something like this:
Action myAction = new Action("", imageDesc) {
@Override
public void run() {
// Perform action
}
};
IToolBarManager toolBarManager = actionBars.getToolBarManager();
toolBarManager.add(myAction);
这篇关于带有Eclipse Look的Eclipse RCP工具栏按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!