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

From Eclipsepedia

Jump to: navigation, search
 
 
(One intermediate revision by one user not shown)
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>
+
 
  
  
Line 32: Line 32:
 
== See Also: ==
 
== See Also: ==
  
[[FAQ_How_do_I_build_menus_and_toolbars_programmatically%3F]]
+
[[FAQ How do I build menus and toolbars programmatically?]]
  
 
<hr><font size=-2>This FAQ was originally published in [http://www.eclipsefaq.org Official Eclipse 3.0 FAQs]. Copyright 2004, Pearson Education, Inc. All rights reserved. This text is made available here under the terms of the [http://www.eclipse.org/legal/epl-v10.html Eclipse Public License v1.0].</font>
 
<hr><font size=-2>This FAQ was originally published in [http://www.eclipsefaq.org Official Eclipse 3.0 FAQs]. Copyright 2004, Pearson Education, Inc. All rights reserved. This text is made available here under the terms of the [http://www.eclipse.org/legal/epl-v10.html Eclipse Public License v1.0].</font>

Latest revision as of 16:52, 24 September 2011

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

  • under the icon on the view’s tab item.

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.


  • in the view’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’s createPartControl method, adds a single action to the view’s menu and toolbar:

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


[edit] 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.