Not able to extend the Help menu - eclipse

I want to add from an eclipse plugin a Request Support button to the Help menu.
I tried first from a *.e4xmi file and now I tried from the plugin.xml but still can't make a button to appear under the Help menu.
I got the menu URI with the help of Eclipse Spy Plug-in.
The content of plugin.xml:
<extension
point="org.eclipse.ui.menus">
<menuContribution
allPopups="false" (tried with true and same result)
locationURI="menu:help?after=about">
<menu
commandId="com.plugin.RequestSupport"
id="requestSupport"
label="Request Support">
</menu>
</menuContribution>
</extension>
<extension
point="org.eclipse.ui.commands">
<command
defaultHandler="com.plugin.handlers.RequestSupportHandler"
description="Opens up default e-mail client with preset basic informations"
id="com.plugin.RequestSupport"
name="Request Support">
</command>
</extension>
What am I missing?
SOLUTION from greg's answer:
<extension
point="org.eclipse.ui.menus">
<menuContribution
allPopups="false" (tried with true and same result)
locationURI="menu:help?after=about">
<menu
commandId="com.plugin.RequestSupport"
id="requestSupport"
label="Request Support">
</menu>
<command
commandId="com.plugin.RequestSupport"
id="requestSupport"
label="Request Support"
style="push">
</command>
</menuContribution>
</extension>

This is what 'Check for Updates' uses:
<extension
point="org.eclipse.ui.menus">
<menuContribution
locationURI="menu:help?after=additions">
<command
commandId="org.eclipse.equinox.p2.ui.sdk.update"
mnemonic="%Update.command.mnemonic"
id="org.eclipse.equinox.p2.ui.sdk.update"
icon="icons/obj/iu_update_obj.png">
</command>
Which is adding after the 'additions' location.
The code which creates the help menu defines a lot of locations:
private MenuManager createHelpMenu() {
MenuManager menu = new MenuManager(IDEWorkbenchMessages.Workbench_help, IWorkbenchActionConstants.M_HELP);
addSeparatorOrGroupMarker(menu, "group.intro"); //$NON-NLS-1$
// See if a welcome or intro page is specified
if (introAction != null) {
menu.add(introAction);
} else if (quickStartAction != null) {
menu.add(quickStartAction);
}
menu.add(new GroupMarker("group.intro.ext")); //$NON-NLS-1$
addSeparatorOrGroupMarker(menu, "group.main"); //$NON-NLS-1$
menu.add(helpContentsAction);
menu.add(helpSearchAction);
menu.add(dynamicHelpAction);
addSeparatorOrGroupMarker(menu, "group.assist"); //$NON-NLS-1$
// See if a tips and tricks page is specified
if (tipsAndTricksAction != null) {
menu.add(tipsAndTricksAction);
}
// HELP_START should really be the first item, but it was after
// quickStartAction and tipsAndTricksAction in 2.1.
menu.add(new GroupMarker(IWorkbenchActionConstants.HELP_START));
menu.add(new GroupMarker("group.main.ext")); //$NON-NLS-1$
addSeparatorOrGroupMarker(menu, "group.tutorials"); //$NON-NLS-1$
addSeparatorOrGroupMarker(menu, "group.tools"); //$NON-NLS-1$
addSeparatorOrGroupMarker(menu, "group.updates"); //$NON-NLS-1$
menu.add(new GroupMarker(IWorkbenchActionConstants.HELP_END));
addSeparatorOrGroupMarker(menu, IWorkbenchActionConstants.MB_ADDITIONS);
// about should always be at the bottom
menu.add(new Separator("group.about")); //$NON-NLS-1$
ActionContributionItem aboutItem = new ActionContributionItem(aboutAction);
aboutItem.setVisible(!Util.isMac());
menu.add(aboutItem);
menu.add(new GroupMarker("group.about.ext")); //$NON-NLS-1$
return menu;
}
(from org.eclipse.ui.internal.ide.WorkbenchActionBuilder)
All the addSeparatorOrGroupMarker, new Separator and new GroupMaker calls define ids to can add after.

Related

How to add a command to an editor context menu in Eclipse only if text is selected

I would like to add an item to the eclipse context menu only if a text is marked as selected
below is my XML relevant snippet:
<menuContribution
allPopups="false"
locationURI="popup:org.eclipse.ui.popup.any">
<command
commandId="com.test.ide.menu.commands.sampleCommand"
icon="icons/sample.png"
id="com.test.ide.menu.toolbars.sampleCommand"
tooltip="Popup test">
<visibleWhen>
<with variable="selection">
<instanceof value="org.eclipse.jface.text.ITextSelection"/>
</with>
</visibleWhen>
</command>
</menuContribution>
I tried the solution in How do you contribute a command to an editor context menu in Eclipse which does not resolve the issue
What am i missing?
Can you help?
ThanksAvner
Excuse my detailed question, I am a newb to eclipse programming
i tried:
<extension
point="org.eclipse.core.expressions.propertyTesters">
<propertyTester
class="com.test.ide.TextSelectedPropertyTester"
id="com.test.ide.propertyTester1"
namespace="tested"
properties="textSelected"
type="org.eclipse.jface.text.ITextSelection">
</propertyTester>
</extension>
<menuContribution
allPopups="false"
locationURI="popup:org.eclipse.ui.popup.any">
<command
commandId="com.test.ide.menu.commands.sampleCommand"
icon="icons/sample.png"
id="com.test.ide.menu.toolbars.sampleCommand"
tooltip="Popup test">
<visibleWhen>
<with variable="selection">
<adapt type="org.eclipse.jface.text.ITextSelection">
<test
property="tested.textSelected">
</test>
</adapt>
</with>
</visibleWhen>
</command>
</menuContribution>
created a new package - com.test.ide in it created a new class TextSelectedPropertyTester
however the class is never invoked
package com.test.ide;
import org.eclipse.core.expressions.PropertyTester;
import org.eclipse.jface.text.ITextSelection;
public class TextSelectedPropertyTester extends PropertyTester
{
#Override
public boolean test(Object receiver, String property, Object [] args, Object expectedValue)
{
System.out.println("testing");
if (receiver instanceof ITextSelection) {
return ((ITextSelection)receiver).getLength() > 0;
}
return false;
}
}
however the class is never used
what am I missing?
The problem is that editors normally always have a text selection set - it will just be zero length if no characters are selected.
I can't see a way to test this using existing expressions so it may be necessary to define your own property tester using the org.eclipse.core.expressions.propertyTester extension point.
<extension
point="org.eclipse.core.expressions.propertyTesters">
<propertyTester
class="tested.TextSelectedPropertyTester"
id="tested.propertyTester1"
namespace="tested"
properties="textSelected"
type="org.eclipse.jface.text.ITextSelection">
</propertyTester>
</extension>
use like this:
<visibleWhen>
<with variable="selection">
<adapt type="org.eclipse.jface.text.ITextSelection">
<test
property="tested.textSelected"
forcePluginActivation="true">
</test>
</adapt>
</with>
</visibleWhen>
The property tester is very simple:
public class TextSelectedPropertyTester extends PropertyTester
{
#Override
public boolean test(Object receiver, String property, Object [] args, Object expectedValue)
{
if (receiver instanceof ITextSelection textSel) {
return textSel.getLength() > 0;
}
return false;
}
}
Note as shown the if statement uses a Java 16 instanceof type pattern, if you need to run with an older Java use:
if (receiver instanceof ITextSelection) {
return ((ITextSelection)receiver).getLength() > 0;
}

EclipseRCP, Add Context Menu Item for project

in my custom RCP plugin, I want to add a context menu with command to the project view.
So when I right click the project, then the new context menu item should be shown.
But I do not know how to achieve this, via adding an extension point to plugin.xml?
<extension point="org.eclipse.ui.menus">
<menuContribution locationURI="popup:org.eclipse.ui.navigator.ProjectExplorer#PopupMenu?after=additions">
<command commandId="com.itemis.test.MyOpenCommand"
label="Open My" style="push" tooltip="Open My Editor.">
</command>
</menuContribution>
<extension point="org.eclipse.ui.commands">
<command id="com.itemis.test.MyOpenCommand" name="Open My"
description="Open My Editor.">
</command>
</extension>
<extension point="org.eclipse.ui.handlers">
<handler commandId="com.itemis.test.MyOpenCommand"
class="com.itemis.test.MyOpenHandler">
</handler>
</extension>
package com.itemis.test;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
public class MyOpenHandler extends AbstractHandler {
#Override
public Object execute(ExecutionEvent event) throws ExecutionException {
return null;
}
}

Hide/Remove a perspective provided by another plugin - eclipse

I noticed that I had dependencies on some of the Eclipse JDT and Plugin development features and due to this the RCP was showing some other perspective from the other ui plugins, which is unnecessary entries in my product of Preference Perspective.
I tried with the below snippet, but still the perspective is showing in the preference perspective.
Call the removeUnWantedPerspectives() (attached below) method from postWindowCreate() method of your RCP’s WorkbenchWindowAdvisor extension class –
private String[] IGNORE_PERSPECTIVES = new String[] {
"com.abc.xyz.ui.calibrationPerspective" };
/**
* Removes the unwanted perspectives from your RCP application
*/
private void removeUnWantedPerspectives() {
IPerspectiveRegistry perspectiveRegistry = PlatformUI.getWorkbench().getPerspectiveRegistry();
IPerspectiveDescriptor[] perspectiveDescriptors = perspectiveRegistry.getPerspectives();
List ignoredPerspectives = Arrays.asList(GenericConstants.IGNORE_PERSPECTIVES);
List removePerspectiveDesc = new ArrayList();
// Add the perspective descriptors with the matching perspective ids to the list
for (IPerspectiveDescriptor perspectiveDescriptor : perspectiveDescriptors) {
if(ignoredPerspectives.contains(perspectiveDescriptor.getId())) {
removePerspectiveDesc.add(perspectiveDescriptor);
}
}
// If the list is non-empty then remove all such perspectives from the IExtensionChangeHandler
if(perspectiveRegistry instanceof IExtensionChangeHandler && !removePerspectiveDesc.isEmpty()) {
IExtensionChangeHandler extChgHandler = (IExtensionChangeHandler) perspectiveRegistry;
extChgHandler.removeExtension(null, removePerspectiveDesc.toArray());
}
}
I tried with activities extension also, but this dosen't works for me
<extension
id="com.abc.xyz.pmse.application.activities.hideperspective"
name="Hide Perspectives"
point="org.eclipse.ui.activities">
<activityPatternBinding
activityId="com.abc.xyz.pmse.application.activities.hideperspective"
pattern=".*/com.abc.xyz.ui.calibrationperspective">
</activityPatternBinding>
<activityPatternBinding
activityId="com.abc.xyz.pmse.application.activities.hideperspective"
pattern=".*/com.abc.xyz.ui.varianthandlingperspective">
</activityPatternBinding>
</extension>
My working activities extension snippet looks like
<extension
point="org.eclipse.ui.activities">
<activity
id="com.abc.xyz.svn.ui.activity.hideunwantedperspective"
name="Hide UnwantedPerspective">
<enabledWhen>
<equals
value="false">
</equals>
</enabledWhen>
</activity>
<activityPatternBinding
activityId="com.abc.xyz.svn.ui.activity.hideunwantedperspective"
isEqualityPattern="true"
pattern="com.abc.xyz.ui.parameter.impl/com.abc.xyz.ui.calibrationperspective">
</activityPatternBinding>
<activityPatternBinding
activityId="com.abc.xyz.svn.ui.activity.hideunwantedperspective"
isEqualityPattern="true"
pattern="com.abc.xyz.ui.dcmmapping/com.abc.xyz.ui.varianthandlingperspective">
</activityPatternBinding>
<activityPatternBinding
activityId="com.abc.xyz.svn.ui.activity.hideunwantedperspective"
isEqualityPattern="true"
pattern="com.abc.xyz.ui.dcmmapping/com.abc.xyz.ui.varianthandlingperspectivenew">
</activityPatternBinding>
</extension>

Eclipse plugins - Add a menucontribution to Toolbar dynamically

Is it possible to add menucontribution, basically a new button, to the toolbar:org.eclipse.ui.main.toolbar dynamically?
I tried with AbstractContributionFactory but it seems to be bugged, since the createContributionItems is never called.
My code so far tries to add a new button to the Eclipse toolbar after pressing another button. The thing is that the createContributionItems is never called so "Creating Stuff" never appears:
//If a certain button is pressed run will be executed
public void run(IAction action) {
MessageDialog.openInformation(
window.getShell(),
"Runtimecommands",
"Hello, Eclipse world");
IMenuService menuService = (IMenuService) PlatformUI.getWorkbench().getService(IMenuService.class);
AbstractContributionFactory factory = new AbstractContributionFactory("toolbar:org.eclipse.ui.main.toolbar", null)
#Override
public void createContributionItems(IServiceLocator serviceLocator, IContributionRoot additions) {
System.out.println("Creating Stuff");
};
menuService.addContributionFactory(factory);
}
And my current plugin.xml
<plugin>
<extension
point="org.eclipse.ui.actionSets">
<actionSet
label="Sample Action Set"
visible="true"
id="com.dynamo.actionSet">
<menu
label="Sample &Menu"
id="sampleMenu">
<separator
name="sampleGroup">
</separator>
</menu>
<action
label="&Sample Action"
icon="icons/sample.gif"
class="com.dynamo.actions.SampleAction"
tooltip="Hello, Eclipse world"
menubarPath="sampleMenu/sampleGroup"
toolbarPath="sampleGroup"
id="com.dynamo.actions.SampleAction">
</action>
</actionSet>
</extension>
</plugin>
Tks for your attention.

Eclipse: Disable property tab contributed from navigator plugin

I need to hide propery tab called "Resources" contributed by plugin org.eclipse.ui.navigator.resources
This tab looks like this:
The description of this tab from plugin:
<extension
point="org.eclipse.ui.views.properties.tabbed.propertyContributor">
<propertyContributor
contributorId="org.eclipse.ui.navigator.ProjectExplorer"
labelProvider="org.eclipse.ui.internal.navigator.resources.workbench.TabbedPropertySheetTitleProvider">
<propertyCategory category="general"/>
<propertyCategory category="core"/>
<propertyCategory category="appearance"/>
<propertyCategory category="resource"/>
<propertyCategory category="advanced"/>
</propertyContributor>
</extension>
<extension
point="org.eclipse.ui.views.properties.tabbed.propertyTabs">
<propertyTabs contributorId="org.eclipse.ui.navigator.ProjectExplorer">
<propertyTab
label="%Resource"
category="resource"
id="CommonNavigator.tab.Resource"/>
</propertyTabs>
</extension>
I want to hide this tab, so there will be visible only tab contributed by my plugin.
Update.
I have tried activities like this, but is doesnt helps:
<activityPatternBinding
activityId="com.company.activities.hide"
isEqualityPattern="true"
pattern="org.eclipse.ui.navigator.resources/CommonNavigator.tab.Resource">
</activityPatternBinding>
On possibility is to remove unwanted contribution:
final ActionSetRegistry reg = WorkbenchPlugin.getDefault().getActionSetRegistry();
final IActionSetDescriptor[] actionSets = reg.getActionSets();
final String[] removeActionSets =
new String[] { "org.eclipse.search.searchActionSet", "org.eclipse.ui.cheatsheets.actionSet",
"org.eclipse.ui.actionSet.keyBindings", "org.eclipse.ui.edit.text.actionSet.navigation",
"org.eclipse.ui.edit.text.actionSet.annotationNavigation",
"org.eclipse.ui.edit.text.actionSet.convertLineDelimitersTo",
"org.eclipse.ui.edit.text.actionSet.openExternalFile",
"org.eclipse.ui.externaltools.ExternalToolsSet", "org.eclipse.ui.WorkingSetActionSet",
"org.eclipse.update.ui.softwareUpdates", "org.eclipse.ui.actionSet.openFiles",
"org.eclipse.mylyn.tasks.ui.navigation", };
for (IActionSetDescriptor actionSet : actionSets) {
boolean found = false;
for (String removeActionSet : removeActionSets) {
if (removeActionSet.equals(actionSet.getId())) {
found = true;
}
}
if (!found) {
continue;
}
final IExtension ext = actionSet.getConfigurationElement().getDeclaringExtension();
reg.removeExtension(ext, new Object[] { actionSet });
}