Community
Participate
Working Groups
I hope I'm missing something here, but I fear I am not. The Eclipse SDK IDE for Cocoa adds menu items for Window > Minimize, Window > Zoom, Window > Bring All To Front. These are responsible for the following warnings seen on startup, as the org.eclipse.e4.ui.workbench.renderers.swt.cocoa fragment doesn't (yet) provide definitions: !ENTRY org.eclipse.ui 4 4 2011-05-10 20:14:24.880 !MESSAGE Unable to create menu item "null", command "org.eclipse.ui.cocoa.minimizeWindow" not defined !ENTRY org.eclipse.ui 4 4 2011-05-10 20:14:24.881 !MESSAGE Unable to create menu item "null", command "org.eclipse.ui.cocoa.zoomWindow" not defined !ENTRY org.eclipse.ui 4 4 2011-05-10 20:14:24.881 !MESSAGE Unable to create menu item "null", command "org.eclipse.ui.cocoa.arrangeWindowsInFront" not defined I'm creating some Eclipse 4-based implementations, but having to define them programmatically (I can't define them in a fragment.e4xmi as we don't know the applicable application element ids). I'm trying to ensure that these definitions use translatable strings, if present. My initial attempt fails, however: MCommand zoom = MCommandsFactory.INSTANCE.createCommand(); zoom.setElementId(commandId); zoom.setCommandName("%command.zoom.name"); zoom.setDescription("%command.zoom.desc"); zoom.setContributorURI("platform:/fragment/org.eclipse.e4.ui.workbench.renderers.swt.cocoa"); app.getCommands().add(zoom); MHandler handler = MCommandsFactory.INSTANCE.createHandler(); handler.setContributionURI("platform:/plugin/org.eclipse.e4.ui.workbench.renderers.swt.cocoa/" + ZoomWindowHandler.class.getName()); handler.setContributorURI("platform:/fragment/org.eclipse.e4.ui.workbench.renderers.swt.cocoa"); handler.setElementId(ZoomWindowHandler.class.getName()); handler.setCommand(zoom); app.getHandlers().add(handler); But the menu items show up as "%command.zoom.name". It works if I instead use the injected TranslationService and explicitly perform the translation: command.setCommandName(translator == null ? name : translator.translate("%command.zoom.name", "platform:/fragment/org.eclipse.e4.ui.workbench.renderers.swt.cocoa")); command.setDescription(description == null ? description : translator.translate("%command.zoom.desc", "platform:/fragment/org.eclipse.e4.ui.workbench.renderers.swt.cocoa")); The BundleTranslationProvider does get called, except its contributorURI is null, and so no translation is attempted: BundleTranslationProvider.translate(String, String) line: 46 LocalizationHelper.getLocalized(String, MApplicationElement, IEclipseContext) line: 132 LocalizationHelper.getLocalized(String, MApplicationElement) line: 112 LocalizationHelper.getLocalizedLabel(MUIElement) line: 72 HandledMenuItemImpl(ItemImpl).getLocalizedLabel() line: 314 The problem is, I think, that the HandledMenuItem created takes its name from the command ("%command.zoon.name") but doesn't take the command's contributorURI, and instead has a null contributorURI. One solution might be to amend ItemImpl#getLocalizedLabel() and getLocalizedTooltip() to do something like this: public String getLocalizedLabel() { if(getContributorURI() == null && getLabel().equals(getCommand().getLabel()) { return LocalizationHelper.getLocalized(getLabel(), getCommand().getContributor()); } return LocalizationHelper.getLocalizedLabel(this); } (untested; it's a bit icky) Or alternatively, org.eclipse.ui.workbench's org.eclipse.ui.internal.menus.MenuHelper#createItem() should also set the newly-created menu item's contributorURI to the command's contributorURI? Or MHandledItem's implementation of #getContributorURI() should, if its contributorURI is null, return the command's contributorURI instead?
These menu items are defined in org.eclipse.ui.ide's org.eclipse.ui.internal.ide.WorkbenchActionBuilder.java: CommandContributionItemParameter minimizeParam = new CommandContributionItemParameter(window, null, "org.eclipse.ui.cocoa.minimizeWindow", CommandContributionItem.STYLE_PUSH); //$NON-NLS-1$ minimizeItem = new CommandContributionItem(minimizeParam); CommandContributionItemParameter zoomParam = new CommandContributionItemParameter(window, null, "org.eclipse.ui.cocoa.zoomWindow", CommandContributionItem.STYLE_PUSH); //$NON-NLS-1$ zoomItem = new CommandContributionItem(zoomParam); CommandContributionItemParameter arrangeWindowsParam = new CommandContributionItemParameter(window, null, "org.eclipse.ui.cocoa.arrangeWindowsInFront", CommandContributionItem.STYLE_PUSH); //$NON-NLS-1$ arrangeWindowsItem = new CommandContributionItem(arrangeWindowsParam);
Created attachment 195408 [details] patch to MenuHelper Change MenuHelper#createItem(MApplication, CommandContributionItem) to set the new item's contributorURI to the command instance's contributorURI.
Created attachment 195412 [details] MenuHelper patch v2 Fix other applicable locations too (createItem() and createToolItem())
Released to HEAD PW
I didn't switch it to REOPENED, and can't find the record in the history :-) Maybe when I switched assignee? If anybody would like to REOPEN, please feel free. PW