Bind a custom SWT button to command / handler [message #644549] |
Mon, 13 December 2010 03:50  |
Eclipse User |
|
|
|
Hello all,
I face the following problem :
I have a command and a handler which I use in a key binding for a text editor.
In this editor, I have a toolbar on top where there are some action button which need to do the same action as the key binding.
Since I got a command and a handler for the key binding, I would like to trigger the same code when the user pushes one of the toolbar button.
I need to mention that I do not want the controls to be on the main toolbar (though I don't want to use ActionBarContributor), I want those controls to be INSIDE the editor.
Ideally, I would love to contribute commands to editor toolbar exactly as I can do with views (through "toolbar:viewId?after=additions") but it seems not to be supported.
Alternatively, I look for a way to bind my own SWT button to an existing command so that its handler would be called when pressed.
Is there a way to achieve this ?
Thank you for any help,
Christophe
http://www.nextep-softwares.com
|
|
|
|
Re: Bind a custom SWT button to command / handler [message #644673 is a reply to message #644601] |
Mon, 13 December 2010 12:37  |
Eclipse User |
|
|
|
Thank you, it works like a charm !
In case others interested, here is the working code :
final ToolBar tb = new ToolBar(parent, SWT.NONE);
tb.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
tbm = new ToolBarManager(tb);
tbm.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
final IMenuService menuService = (IMenuService) getSite().getService(IMenuService.class);
menuService.populateContributionManager(tbm, "toolbar:" + EDITOR_ID);
// Explicit update needed otherwise contributions not displayed
tbm.update(true);
Christophe.
http://www.nextep-softwares.com
|
|
|
Powered by
FUDForum. Page generated in 0.07684 seconds