|Re: Action Set vs command Hdler for main menu. [message #555414 is a reply to message #555391]
||Thu, 26 August 2010 14:23
|| Mickael Istria
Registered: July 2009
Location: Grenoble, France
actionSets combine too much things in one extension: a location in a menu, the code to execute and so on.
Using menu, command and handlers allows you to do the same things as an actionSet, with the following advantages:
* Handlers are simple classes that you attach to a document. You can easily re-use them and it is easier to write/compose/create inheritance between them.
* A command is an abstract definition which is a placeholder for several implementations (handlers). When you add an handler to a command, you can specify some conditions to know whether it is relevant or not, such as filtering on the selected item.
You can use it to define keyboard shortcuts, and then you just add to it some handlers. It is easy to configure.
There is an ICommandService to handle commands programmatically when necessary.
* using menus is simply about manipulating the menus and associating commands to entries.
Let's imagine you have an editor, and you want to implement an undo on it. Using command would make your undo work as the same way than the normal "Undo", you automatically get the Ctrl-Z shortcut, and all traditional menu entries will work for your undo. It would not be the case with actionSets.
In our product, we discovered after several month that using actionSets conflicted with some existing commands and caused troubles in menu activation and keyboard shortcuts (for example, Ctrl-Z was cancelling the operation from another editor...), Replacing them with Handlers for existing commands, and some other new commands made everything work well.
I hope I am clear ;) But if I am not clear enough, trust me: commands are the best way to go.
Mickael Istria -- BonitaSoft S.A.
Powered by FUDForum
. Page generated in 0.01870 seconds