views:

245

answers:

2

Hi,

I am creating an eclipse plugin which should listen for and handle the event generated, when the user selects File > New > Project.

I am urgently in need of a solution for this. Please share with me the codes or ideas that you have as soon as possible.

+1  A: 

One good way to listen and react to a menu item selection is to add an handler.

A handler is the behavior of a command at a particular point in time.
A command can have zero or more handlers associated with it.
At any one point in time, however, a command will either have no active handler or one active handler.
The active handler is the one which is currently responsible for carrying out the behavior of the command. This is very similar to the concept of an action handler and a retargettable action.

So you have to find the Command id corresponding to File New Project, and make sure your extension is the default active handler, redirecting to the new project function by default, after doing your custom process.

More details on the Menu Contribution article.

VonC
Thanks a lot for your immediate reply. I really appreciate it. I am just a beginner, so please bare with me.I have found out the command id but i dont know how to make my extension as the default active handler.Will you please provide a sample code. Thank you very much in advance.
I have tried to look for sample when it comes to modify *existing* default active handler, but so far, I came empty...
VonC
I think you'd have to change contexts
jamesh
+1  A: 

File New Project is a well established action/command. If you are looking to replace it with your own, then I would guess you're in an RCP context, where you are free to do what you will. I would probably start with my own command, and then add it to the menu, toolbar, keybinding etc, as needed. There is an excellent set of tutorials/tips at eclipse-tips.

If you are writing plugins for Eclipse, the IDE, then you are almost certainly approaching the task from too low a level. In this case, I would guess you're wanting to contribute your own wizard, and things to come up when you right click in the package navigator view, under the New menu.

If this is the case, then I would go straight to the newWizards extension point,

jamesh