Command Handler not responding for EditorSelectionDialog - eclipse

i am building my custom Editor. But when i right click on my desired file and try to open it with custom editor via "Open With" option, my command handler does not work. Do i have to use locationURI under menuContribution tag with commandId in plugin.xml for this? If it is then how? Please have a look at my current plugin.xml for better understanding.
Plugin.xml
<extension point="org.eclipse.ui.editors">
<editor
class="launcher.ChartEditor"
default="false"
id="launcher.ChartEditor"
name="ChartEditor">
</editor>
</extension>
<extension
point="org.eclipse.ui.commands">
<command
id="launcher.openChartEditor"
name="OpenChartEditor">
</command>
</extension>
<extension
point="org.eclipse.ui.handlers">
<handler
class="launcher.ChartEditorHandler"
commandId="launcher.openChartEditor">
</handler>
</extension>

The 'Open With...' menu just opens the editor directly. It does not use any command or handler. There is no other way to contribute to the 'Open With' menu. The EditorSelectionDialog is the same.
To use your command and handler you do need to using a menuContribution (or a tool bar contribution) but this will have to somewhere other than Open With.
The standard 'Open With' action opens the selected editor passing it the IEditorInput for the current selection. This will usually be an IFileEditorInput from which you can get the file.

Related

Is it possible to find out whether the code written in Eclipse editor is valid and disable/enable context menu button accordingly?

I'm creating Eclipse plugin for my DSL, using Xtext and need to add context menu item for my editor (what I did already), but need to find out whether the code in editor is valid, if yes -> this menu item should be enabled, otherwise disabled. Is it somethow possible to check whether the whole code is valid and update the state of this context menu item accordingly ?
I added this context menu item by adding this fragment to the plugin.xml file in .ui project in Xtext.
<extension point="org.eclipse.ui.menus">
<menuContribution locationURI="popup:#TextEditorContext?after=additions">
<command commandId="org.first.langu.ui.handler.InterpreterCommand" style="push">
<enabledWhen checkEnabled="true">
<reference definitionId="org.first.langu.Program.XtextEditor.opened"/>
</enabledWhen>
</command>
</menuContribution>
</extension>
<extension point="org.eclipse.ui.commands">
<command id="org.first.langu.ui.handler.InterpreterCommand" name="Interpret Code"/>
</extension>
<extension point="org.eclipse.ui.handlers">
<handler
class="org.first.langu.ui.ProgramExecutableExtensionFactory:org.first.langu.ui.handler.InterpretCodeHandler"
commandId="org.first.langu.ui.handler.InterpreterCommand"/>
</extension>
Basically I need to check whether code in editor is valid, instead of if editor is just opened.
you can use the editors annotation model to find out if there are any errors.
see org.eclipse.xtext.ui.editor.XtextEditorErrorTickUpdater.getSeverity(XtextEditor)
for an example on how to retrieve and filter the annotations. that class is used to display the red x in the editor icon if there are errors

Open another editor from the eclipse search view

I have a file which can be edited using two different editors.
In eclipses' project explorer you can open a file in a different editor from the context menu.
How can I open a search result (shown in the Search view) in a different editor?
As I am developing an own plug-in, a way to extend the Search view's context menu would be a valid solution as well.
I don' think there is a way to get the search view to use a different editor.
You can contribute to the search view using the org.eclipse.ui.menus extension point. The view id is org.eclipse.search.ui.views.SearchView so something like:
<extension
point="org.eclipse.ui.menus">
<menuContribution
allPopups="false"
locationURI="popup:org.eclipse.search.ui.views.SearchView">
<command
commandId="my.command.id"
label="Test Search View Contrib"
style="push">
</command>
</menuContribution>

Eclipse context menu corrupts when i am adding icon images

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

Eclipse plug-in: why doesn't my menu contribution show up after using a shortcut?

I wanted to add a menu item to the Source popup, and I got it working with the following plugin.xml fragment:
<menuContribution allPopups="true" locationURI="popup:org.eclipse.jdt.ui.source.menu">
<command
commandId="pl.axit.eclipse.bundle.commands.convertToBundle"
id="pl.axit.eclipse.bundle.menus.convertToBundle"
label="Extract bundle" >
</command>
</menuContribution>
And it works after I click the right mouse button and then select Source I can see my Extract bundle item. Great.
But... when I open the Source menu with a shortcut (alt+shift+s) then my Extract Bundle isn't there! Any idea why and how to make it appear after using the shortcut?

Adding to Eclipse's console view pop-up menu

In Eclipse plugin development, I have been able to add an item to the right-click context menu on the project explorer by doing this:
<extension point="org.eclipse.ui.menus">
<menuContribution locationURI="popup:org.eclipse.jdt.ui.PackageExplorer">
<command ... >
...
</command>
</menuContribution>
</extension>
But when I try to add to the pop-up menu for the ConsoleView, I'm not getting results.
<extension point="org.eclipse.ui.menus">
<menuContribution locationURI="popup:org.eclipse.ui.console.ConsoleView">
<command ... >
...
</command>
</menuContribution>
</extension>
I've been looking at the output from alt-shift-F1 and alt-shift-F2 (Plug-in Spy), which is where I got org.eclipse.ui.console.ConsoleView. But I can't seem to get to the pop-up menu itself. I can get information about the individual pop-up menu items (Select All, Clear, etc), but I guess I just don't quite know how to "dig" with Plug-in Spy to get the right information.
EDIT: Showing the results of my work using the answer from below
Plug-in Selection Spy had the following:
Active Part (Console)
The active view identifier:
org.eclipse.ui.console.ConsoleView
Active Selection
The selection class:
TextSelection
Active Help
The active help context identifiers:
org.eclipse.debug.ui.process_console_context
It was that last entry which pointed me toward the process console as opposed to the message console. The link in the answer had IDebugUIConstants.ID_PROCESS_CONSOLE_TYPE defined as org.eclipse.debug.ui.ProcessConsoleType. So I ended up with this, and it worked:
<menuContribution
locationURI="popup:org.eclipse.debug.ui.ProcessConsoleType.#ContextMenu">
<command
commandId="com.grch.cmgtsdk.merge"
label="Yowza!"
style="push">
</command>
</menuContribution>
The Console view itself is just a container for different kinds of consoles and it doesn't have a context menu. You need to figure out the menu ID of the specific console that you want to add your contribution to.
For text consoles the menu ID looks something like <console type>.#ContextMenu. This is not really documented and finding out the console type is not straightforward (you should look into the code). For example, console type of process console is defined in IDebugUIConstants.ID_PROCESS_CONSOLE_TYPE whereas for message console it's IConsoleConstants.MESSAGE_CONSOLE_TYPE.
Above answer helped me in creating the popup. Below is the example code:-
<menuContribution
locationURI="popup:org.eclipse.ui.MessageConsole.#ContextMenu">
<menu
label="My Popup" id="com.abhi.test.popup.menu2">
<command
commandId="com.abhi.test.command1"
id="com.abhi.test.popup.command3"
style="push">
</command>
</menu>
</menuContribution>