Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "FAQ How do I add actions to a view's menu and toolbar?"

Line 4: Line 4:
 
This menu contains layout and view-manipulation actions.
 
This menu contains layout and view-manipulation actions.
 
You don’t have any control over this menu; its actions are all added by the platform.
 
You don’t have any control over this menu; its actions are all added by the platform.
</li>
+
 
  
 
* ''in the view&#146;s toolbar''.
 
* ''in the view&#146;s toolbar''.
Line 11: Line 11:
 
is controlled by your view.  This menu will exist only if you add actions
 
is controlled by your view.  This menu will exist only if you add actions
 
to it.   
 
to it.   
</li>
+
 
  
  

Revision as of 16:52, 24 September 2011

Each view has a drop-down menu in two locations:

  • under the icon on the view&#146;s tab item.

This menu contains layout and view-manipulation actions. You don&#146;t have any control over this menu; its actions are all added by the platform.


  • in the view&#146;s toolbar.

The drop-down menu on the right-hand side, a small downward-pointing triangle, is controlled by your view. This menu will exist only if you add actions to it.


Actions are added to the menu and toolbar by using the IActionBars interface. This interface is used to access the standard JFace menu and toolbar manager objects used for creating menus throughout Eclipse. The following code, usually invoked from the view&#146;s createPartControl method, adds a single action to the view&#146;s menu and toolbar:

   Action action = ...;
   IActionBars actionBars = getViewSite().getActionBars();
   IMenuManager dropDownMenu = actionBars.getMenuManager();
   IToolBarManager toolBar = actionBars.getToolBarManager();
   dropDownMenu.add(action);
   toolBar.add(action);


See Also:

FAQ How do I build menus and toolbars programmatically?


This FAQ was originally published in Official Eclipse 3.0 FAQs. Copyright 2004, Pearson Education, Inc. All rights reserved. This text is made available here under the terms of the Eclipse Public License v1.0.

Back to the top