Adding the Eclipse Console to the Context Menu

In developing the Eclipse plugin, I was able to add an item to the right-click context menu in the project explorer by doing the following:

<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 popup menu for ConsoleView, I get no results.

 <extension point="org.eclipse.ui.menus"> <menuContribution locationURI="popup:org.eclipse.ui.console.ConsoleView"> <command ... > ... </command> </menuContribution> </extension> 

I watched the output from alt-shift-F1 and alt-shift-F2 (Plug-in Spy), in which I got org.eclipse.ui.console.ConsoleView . But I can’t get into the popup menu. I can get information about individual elements of the pop-up menu ("Select All", "Clear", etc.), but I think that I just don’t quite understand how to "dig" using Plug-in Spy to get the right one information.

EDIT: Show the results of my work using the answer below

Spy's connectivity choices 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 

This was the last entry that pointed to the process console. , not the message console. The link in the response 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> 
+4
source share
2 answers

The console view is just a container for different consoles, and it does not have a context menu. You need to find out the menu identifier of the specific console to which you want to add your contribution.

For text consoles, the menu identifier looks something like <console type>.#ContextMenu . This is not documented, and figuring out the type of console is not easy (you should study the code). For example, the console type of the process console is defined in IDebugUIConstants.ID_PROCESS_CONSOLE_TYPE , whereas for the message console it is IConsoleConstants.MESSAGE_CONSOLE_TYPE .

+4
source

The above answer helped me create a popup. The following is an 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> 
+1
source

Source: https://habr.com/ru/post/1397505/


All Articles