I am trying to control the visibility of context menu items for EditorView in Eclipse. Here is the plugin configuration code
<visibleWhen>
<with variable="activeEditorId">
<equals value="org.eclipse.ui.DefaultTextEditor"></equals>
</with>
</visibleWhen>
but somehow it is not working and not showing the menu item for editor at all. Any help will be greatly appreciated.
Thanks
Can you try with org.eclipse.jdt.ui.CompilationUnitEditor?
Related
I have developed a IDE for a custom language in Eclipse 3 for RCP and RAP developers. Therefore I used IDE plug-ins wherever possible and applicable. This week I was busy migrating the application to Eclipse e4 (with compatibility layer) with Eclipse for RCP and RAP developers 2021-6. Everything works nearly fine so far.
The one thing i cannot figure out is how I can place the "run" menu where I want. It is placed as first menu in the menu bar.
Another strange thing by the way is that if I use Eclipse 2020-6 instead of 2021-6 as development environment, also the search menu is at the wrong position.
The problem is that the run and search menus come from an IDE plug-in and they are implemented as actions and therefore I cannot specify any order in terms of menus. For all other menus I defined appropriate menuContibutions, commands and handlers. For the latter, I can decide where each menu should be placed with the help of plugin.xml by specifying ?before= or ?after=.
I did a search over stackoverflow issues that have to do with adding menus, reorderung menus, mixing actions with commands and handlers and so on but I could not find a solution how I could place the run menu where I want.
I hoped that there would be something like an ID that I can use to specify as ?before= or ?after= in plugin.xml but I think this will not work with actions.
Can anyone give me a hint how I could place all menus in the desired order? Or is this simply impossible when mixing actions and commands+handlers? Is there any actions-wrapping functionality in order for me to specify ?before= or ?after= in my menuContibutions in plugin.xml?
If you mean the Run menu added by the org.eclipse.debug.ui plug-in this is created using and action set:
<extension point="org.eclipse.ui.actionSets">
<actionSet
label="%BreakpointActionSet.label"
visible="false"
id="org.eclipse.debug.ui.breakpointActionSet">
<menu
label="%RunMenu.label"
path="additions"
id="org.eclipse.ui.run">
which is adding the Run menu at the position additions in the main menu.
The standard main menu created by org.eclipse.ui.internal.ide.WorkbenchActionBuilder creates the main menu like this:
#Override
protected void fillMenuBar(IMenuManager menuBar) {
menuBar.add(createFileMenu());
menuBar.add(createEditMenu());
menuBar.add(createNavigateMenu());
menuBar.add(createProjectMenu());
// This line creates the 'additions' position
menuBar.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
menuBar.add(createWindowMenu());
menuBar.add(createHelpMenu());
}
Thanks to greg-449, I finally figured it out. The following definition finally solved my problem (--> ?before=org.eclipse.ui.run):
<extension
point="org.eclipse.ui.menus">
<menuContribution
allPopups="false"
locationURI="menu:org.eclipse.ui.main.menu?before=org.eclipse.ui.run">
<menu
id="at.boi.tabex.dvl.mainmenu.file"
label="&File">
</menu>
<menu
id="at.boi.tabex.dvl.mainmenu.edit"
label="&Edit">
</menu>
<menu
id="at.boi.tabex.dvl.mainmenu.project"
label="&Project">
</menu>
<menu
id="at.boi.tabex.dvl.mainmenu.tools"
label="&Tools">
</menu>
<menu
id="at.boi.tabex.dvl.mainmenu.table"
label="&Ta&ble">
</menu>
</menuContribution>
</extension>
Everytime i am adding an extension point for context menu contribution to my eclipse plugin, the context menu is corrupted like in the screenshot:
I am using normal GIF images for the menu icons. Have you got an idea why this is happening.
This is how i define the context menu entry:
<extension point="org.eclipse.ui.menus">
<menuContribution
locationURI=
"popup:org.eclipse.ui.navigator.ProjectExplorer#PopupMenu?after=additions">
<menu
icon="icons/zf_logo_mini.gif"
label="MyProject">
<command
commandId="MyProjekt.commands.AddComponent"
icon="icons/add_obj.gif"
label="Sample Entry"
tooltip="Sample Entry">
</command>
</menu>
</menuContribution>
Thanks in advance!
Try to refresh the whole workspace and determine, wether there are some interferrences with some other plugins like cdt
I'm creating an eclipse 4 plugin project. I have a tree viewer that shows model elements.
Problem:
I need to show a popup menu based on the selection that I'm doing on the tree viewer.
I tired to use core expression as explained in the link:
http://www.vogella.com/tutorials/EclipseRCP/article.html#menuadvanced_popup
But whenever I attach the core expression with my popup menu it disappears.
The popup menu appears for all the elements if i don't attach the core expression.
Is there something else that i'm supposed to do to get things right ?
or Should i use a different approach ?
Please find the below snap of my Application.e4xmi file
My plugin.xml file definition for the core expression
<definition
id="xxx.abc.project.addchilddefinition">
<with variable="org.eclipse.ui.selection">
<iterate
ifEmpty="false"
operator="or">
<instanceof
value="xxx.abc.project.model.ObjectName">
</instanceof>
</iterate>
</with>
</definition>
I've registered my popup menu using the below code snippet:
menuService.registerContextMenu(treeviewer.getControl(),
"xxx.abc.project.popupmenu.addchild");
menuService is the EMenuService object and "xxx.abc.project.popupmenu.addchild" is my popupmenu id
You need to use a with element to specify that the selection should be used:
<definition
id="xxx.abc.project.addchilddefinition">
<with
variable="org.eclipse.ui.selection">
<iterate
ifEmpty="false"
operator="or">
<instanceof
value="xxx.abc.project.model.ObjectName">
</instanceof>
</iterate>
</with>
You must also call the ESelectionService setSelection(Object) method when the tree selection changes.
The selection variable org.eclipse.ui.selection is defined in IServiceConstants.ACTIVE_SELECTION
In eclipse there are certain toolbars which becomes visible when I open java editor. It goes invisible when I close the editor (only one editor was open.)
Here opening the java editor is not changing the perspective.
How to achieve this functionality in eclipse rcp application?
Pre-3.3 this can be accomplished through a org.eclipse.ui.IEditorActionBarContributor, defined in your editor extension with the contributorClass attribute.
Since 3.3 a core expression definition can be used in a visiblewhen expression.
For example, a re-usable core expression for an editor can be defined as follows
<extension point = "org.eclipse.core.expressions.definitions">
<definition id="org.eclipse.ui.examples.contributions.activeEditor">
<with variable="activeEditorId">
<equals value="org.eclipse.ui.examples.contributions.editor"/>
</with>
</definition>
</extension>
Then the following expression can be used to control whether a menu or toolbar is visible
<visibleWhen>
<reference definitionId=""org.eclipse.ui.examples.contributions.activeEditor"/>
</visibleWhen>
You need to look at Activities and Contexts to hide/unhide contributions
http://www.vogella.com/blog/2009/07/13/eclipse-activities/
I am trying to override the Eclipse File > Save menu action to add some functionality.
I have tried the following things
a) Create a new action and add it to the global action handler
actionBars.setGlobalActionHandler(ActionFactory.SAVE.getId(), mySaveAction);
actionRegistry.registerAction(action);
b) Create a new handler and override the save command
<extension point="org.eclipse.ui.handlers">
<handler commandId="org.eclipse.ui.file.save"
class="com.diagrams.ui.SaveFileHandler">
<enabledWhen>
<with variable="activePartId">
<equals
value="com.diagrams.editors.MultiPageEditor" />
</with>
</enabledWhen>
<activeWhen>
<with variable="activePartId">
<equals
value="com.diagrams.editors.MultiPageEditor" />
</with>
</activeWhen>
</handler>
</extension>
With both these approaches I have been able to override the Keyboard Ctrl+S functionality but the "File > Save" menu seem to work differently.
Would really appreciate any help, Thanks
In an RCP application, you can contribute the Save action in your ActionBarAdvisor. This also registers the action so it is available from the save command.
But as a plugin in the Eclipse IDE, the IDE provides the ActionBarAdvisor and hooks up the Save action in the File menu. Because that's not technically a command (Actions are a step above an SWT.Selection listener) that's why you can't override the File>Save action.
However, each part provides its own save implementation, so you can do whatever you want in your MultiPageEditor.
The other option is to use org.eclipse.ui.commands.ICommandService.addExecutionListener(IExecutionListener) and add an IExecutionListener (or IEL2). That can listen for the save command, the ID is declared in org.eclipse.ui.IWorkbenchCommandConstants.
It might have something to do with the activePartId being different when the main menu is selected versus a keystroke or using the right-click menu. Have you looked at other extension points?