Jump to: navigation, search

Talk:Menu Contributions

Revision as of 12:48, 14 August 2007 by Eu.md.pp.ru (Talk | contribs)

Text editor popup action

How does one targetall registered context menus? One of the significant problems with the 3.2 eclipse is creeping IDE inconsistency, esp for popup menus. This inconsistency is a consequence of plugin dependent function. Having file-type dependent popups is a nice optional feature, but more critical for users is to have core function always available. There does not seem to be a mechanism to add menu items to all popups or to remove items on user preference. (I think these abilities are available for the menu bar and tool bars but I never use them, they are too slow). An example of the consequences is the AnyEdit plugin, which has pages of XML attempting to enumerate all editors in all versions of eclipse! One approach would allow regular expressions in the targetID (in the current scheme) for actions and urge editor plugin writers to adopt a uniform naming scheme. A better solution would allow users to configure global settings on popups for editors.


Johnjbarton.johnjbarton.com comments moved from document (Oct 20th, 2006)

Part of this exercise will split up menu item placement from menu item visibility. You would be able to place an item in all context menus, and then specify its visibility.
--Pwebster.ca.ibm.com 21:01, 23 October 2006 (EDT)


IMenuService

The article references IMenuService, which seems to be an undocumented internal API. It even took me a while to realize this. --Johnjbarton.johnjbarton.com 23:46, 6 November 2006 (EST)

Note: this is proposed design

Warning: This page describes design ideas, not how eclipse works. (At least I think so) --Johnjbarton.johnjbarton.com 23:49, 6 November 2006 (EST)

Any chance to update these examples for the final 3.3 API?

Also, I wasn't been able to figure out how to initialize trim contribution programmatically. I've tried both plugin startup and IStartup extension point, but they both initialize after trim manager load extension points.

What I need is to do the following from the Java code (actually I only need to be able to change icon for the org.eclipse.mylyn.tasks.ui.trim command, but I wasn't been able retrieve corresponding contribution item contributed by the extension point):

 <extension point="org.eclipse.ui.menus">
   <menuContribution locationURI="menu:org.eclipse.mylyn.tasks.ui.trim">
     <dynamic
        class="org.eclipse.mylyn.internal.tasks.ui.TaskHistoryDropDown"
        id="org.eclipse.mylyn.tasks.ui.trim.dropdown"/>
   </menuContribution>
   <menuContribution locationURI="toolbar:org.eclipse.ui.trim.command2?after">
     <toolbar id="org.eclipse.mylyn.tasks.ui.trim.container">
       <command
           id="org.eclipse.mylyn.tasks.ui.trim"
           commandId="org.eclipse.mylyn.tasks.ui.trim.command"
           label="Previous Task"
           icon="icons/etool16/navigate-previous.gif"
           style="pulldown">
       </command>
       <control
          class="org.eclipse.mylyn.internal.tasks.ui.TaskTrimWidget"
          id="org.eclipse.mylyn.tasks.ui.trim.control"/>
     </toolbar>
   </menuContribution>
 </extension>

Here is what I've tried to write in Java, but strangely createContributionItems() is never being invoked:

 IMenuService menuService = (IMenuService) PlatformUI.getWorkbench().getService(IMenuService.class);
 AbstractContributionFactory contributionFactory = new AbstractContributionFactory(
 		"toolbar:org.eclipse.ui.trim.command2?after", null) {
   public void createContributionItems(final IServiceLocator serviceLocator, IContributionRoot additions) {
     IContributionItem item = new CompoundContributionItem("org.eclipse.mylyn.tasks.ui.trim.container") {
       protected IContributionItem[] getContributionItems() {
         IContributionItem[] items = new IContributionItem[2];
         items[0] = new CommandContributionItem(serviceLocator,  // service locator 
           "org.eclipse.mylyn.tasks.ui.trim",
           "org.eclipse.mylyn.tasks.ui.trim.command",
           Collections.EMPTY_MAP,  // parameter map
           SandboxUiPlugin.getImageDescriptor("icons/etool16/navigate-previous.gif"),
           null,  // disabled icon
           null,  // hover icon
           "Previous Task",
           null,  // menmonic
           null,  // tooltip
           CommandContributionItem.STYLE_PULLDOWN);
         items[1] = new TaskTrimWidget();
         return items;
       }
     };
     additions.addContributionItem(item, null);				
   }
 };
 menuService.addContributionFactory(contributionFactory);