Viti
Viti

Reputation: 13

Eclipse plug-in: How to create a new menu for eclipse plugin with key combination?

I've been looking about this question but I couldn't find it. I need to create a new "popup menu" and assign a key pressed (in other words, I need press "F3+right-click" (for example) and this action will be appear a new popup menu, with my actions in my workbench). I don't need a submenu for my right-click... i need a new and alone menu

Example, in eclipse, when i right-click with my mouse over workbench I see a popmenu with: "undo, revert file, save, cut, copy..." and more, but i need create a new menu instead of eclipse menu, so, when I press "F3+right-click" (example) i need see my popup-menu with my actions... this is my problem, i need to create a new menu and call it with key/mouse combination...

I've been reading the forums but i don't know where to post this question and I don't know where to search (maybe i write a wrong question in the search... i think...).

I hope someone can help me.

Thank you very much;)

Upvotes: 1

Views: 9208

Answers (1)

Andrew Eisenberg
Andrew Eisenberg

Reputation: 28737

I assume that you would like to see this menu in an editor (rather than in a view because that would be slightly different). Most of what you need to do here is to extend eclipse extension points through declaring them in the plugin.xml for your plugin.

Thankfully, Eclipse ships with a few extension point wizards to help you get started with this. To get there, do the following

  1. Open the plugin.xml for your plugin
  2. Go to the extensions page
  3. Click on Add...
  4. Click on Extension Wizards
  5. The "Popup Menu" wizard
  6. After filling in all the details, there are still a few more pieces that you need to do.
  7. The wizard creates an Object contribution, that will add the new popup menu to an object of a specified type in all views. You can change this to being an editor contribution, so that the menu item will show in editors instead.
  8. The final step is to connect this menu item with a key-binding. For that, you need to create a new Command extension.
  9. Start with the Command extension point wizard.
  10. After filling in the details, you get a command, a handler, and a binding. You can remove the handler, since you will connect your action created previously to the command you just created.
  11. From here, you need to fill in all of the stub Java classes created by the wizards and you should be in business.

This is a very rough set of steps you need to do to implement the keybindinds (and, yes, it is way more complicated than it needs to be). For more detail, you can go here:

http://www.vogella.de/articles/EclipseCommands/article.html

Upvotes: 5

Related Questions