views:

23

answers:

1

hey there i am trying to capture user selections from the menu bar , for example if the user pressed File in the menu, my plug-in gonna print "File pressed". i figured out how to listen to view selections by IselectionService , but still has no clue how to do it with the main menu bars(or toolbars).

thanx for help


More details :

I gonna explain my problem a little bit more precisely :
I would like capture top-level menus actions and toolbar, the problem is I really don't know how to create and attach the listener.
Here is the ISelectionListener of the plugin.
My purpose is to listen to the workbench top-level menu selections and toolbar.
Thanx for help

// the listener we register with the selection service 
private ISelectionListener listener = new ISelectionListener() {
  public void selectionChanged(IWorkbenchPart sourcepart, ISelection selection) {
    // we ignore our own selections
    if (sourcepart != SelectionView.this) {
      showSelection(sourcepart, selection);
    }
  }
};
...
...
public void createPartControl(Composite parent) {
  ...
  getSite().getWorkbenchWindow().getSelectionService().addSelectionListener(listener);

P.S : Most what I found about menu listener were SWT stuff for some view or windows I had created, thats not what I meant, I need listener to the main top level menu and toolbars in eclipse workbench.

+1  A: 

If you know the location uri (which you can check with a PluginSpy), you can add an handler in order to react to that menu event.

Note: The Menu Contribution article mentions the locationURI for:

  • main menu is "org.eclipse.ui.main.menu"
  • main toolbor is "org.eclipse.ui.main.toolbar"
VonC
hey, thanx for the fast reply :)
amir farah
please look again at my question, i edited it!
amir farah
@amir: I have looked at your question again (and edited it actually), but have no new elements to add just now. Still looking.
VonC
thanx man :)....if you got some place or book to read it from (i searched a lot of books,still nothing), just let me know .
amir farah