Reputation: 3319
I have a toolbar in my eclipse rcp application, it contains three buttons,
the code create them :
ToolBar tb = new ToolBar(toolBarComp, SWT.NONE);
fd = new FormData();
fd.right = new FormAttachment(100, -10);
tb.setLayoutData(fd);
homeBtn = new ToolItem(tb, SWT.PUSH);
homeBtn.setImage(ResourceManager.getImage(ResourceClass.class, "home.png"));
homeBtn.setToolTipText("返回主页");
backBtn = new ToolItem(tb, SWT.PUSH);
backBtn.setImage(ResourceManager.getImage(ResourceClass.class, "back.png"));
backBtn.setToolTipText("返回至上一页");
backBtn.setEnabled(false);
backBtn.addSelectionListener(new SelectionAdapter(){
public void widgetSelected(SelectionEvent e) {
CompositePageRender.this.controler.goBack();
}
});
forwardBtn = new ToolItem(tb, SWT.PUSH);
forwardBtn.setImage(ResourceManager.getImage(ResourceClass.class, "forward.png"));
forwardBtn.setToolTipText("前进至下一页");
forwardBtn.setEnabled(false);
forwardBtn.addSelectionListener(new SelectionAdapter(){
public void widgetSelected(SelectionEvent e) {
CompositePageRender.this.controler.goFroward();
}
});
I wan to bind ALT+H with the home button, is that possible ? how to do?
Upvotes: 0
Views: 887
Reputation: 10654
Within an SWT application you can use mnemonics to simulate pressing Buttons.
But if you mean an RCP application with ToolItems in a toolbar, you need to use the command framework to use keybindings.
You define a command, and then use a handle to implement the behaviour. Then you have both your ToolItem and keybinding ALT+H point to the same command.
See Workbench extension points using Commands for more information.
Upvotes: 2