Monday, October 30, 2006

Place command in menus in eclipse 3.2

In eclipse 3.2, there is good support for keybindings, commands, and handlers. There are some snippets available at Platform Command Framework.

But it's not obvious how to link your command+handler implementation to a menu or toolbar item. The <action/> elements have a definitionId attribute that can link the action to a command, but that allows the action's IActionDelegate to be linked to the keybinding (through the command). It turns the action's IActionDelegate into a handler for keybinding purposes through the use of an ActionHandler proxy class.

But what if you would prefer to implement your commands and handlers, and then just have the command called from your menus the same way it is through keybindings.

As it turns out, there is public API that will allow you to create a GenericCommandActionDelegate. I have an example available on the Platform Command Framework page.

The implementation takes advantage of the fact that the action element is created through IConfigurationElement#createExecutableExtension(*), which means that your action delegate can implement IExecutableExtension and receive extra configuration information from the plugin.xml.

It's not a perfect solution for 3.2 (there would need to be more work to support something like checked state or radio buttons), but it will allow you to focus on creating command and handlers, and then using the action based extensions to execute your commands.

The same strategy could be used for 3.1 as well, although some modifications would have to be made. In 3.1, you have to build your own ExecutionEvent and call the Command#execute*(*) method yourself.


Thursday, June 22, 2006

What can the Command framework do for you?

In 3.2 much more of the eclipse action infrastructure has moved onto the command framework. It is based on 4 extension points.

org.eclipse.ui.commands and the ICommandService create the abstract user command (like COPY). org.eclipse.ui.handlers and the IHandlerService allow plugins and interested parts to provide an implementation for the COPY command.

org.eclipse.ui.bindings can map key sequences to commands, and IBindingService can programmatically review those keybindings. org.eclipse.ui.contexts and the IContextService can activate contexts, which can be used to scope the keybindings.

The IBindingService can be used to programmatically add new keybindings ... but not easily. There was some example code and discussion on the newsgroup:

Re: Action accelerators

In 3.2 there is still no replacement for placing the command in a menu or toolbar. <actions/> (which should always be linked to commands, BTW) are still used, and the work is done in 4 extension points. org.eclipse.ui.actionSets, org.eclipse.ui.editorActions, org.eclipse.ui.viewActions, and org.eclipse.ui.popupMenus.

Providing this replacement will be part of the command framework work for 3.3.

I'm still wondering if this information should be captured on a wiki for updating (until it can make it into the 3.3 documentation), or just left floating around the newsgroups ...


Saturday, June 03, 2006

Eclipse, you say? Very interesting.

It's been just over a year since I joined the Eclipse team. I've been hearing about these blog postings that other Eclipse committers and Eclipse Foundation members maintain, and thought I would add my 2 cents into the pot.

But later, this first post was very tiring :-)