Author Topic: SlickEdit context menu ID  (Read 4002 times)

r.pakosch

  • Junior Community Member
  • Posts: 2
  • Hero Points: 0
SlickEdit context menu ID
« on: October 04, 2013, 01:56:08 pm »
Hi there,

we developed an Eclipse plug-in that registers context menu actions for Eclipse editors dynamically. Technically it creates Eclipse commands and registers them via context menu URIs, usually:
"popup:#AbstractTextEditorContext?after=additions"

We even support editors that use custom context IDs (not "AbstractTextEditorContext"). Usually we can find out the context ID by using the Eclipse Plug-In Spy which usually can be opened by pressing "Alt + Ctrl + F2" but the SlickEdit Editor seems to "swallow" the combination and prints "Key not defined" in the status bar.
Does anybody know the context menu ID of the editor?

Another thing we tried is to use the "Edit this menu" function to manually add our commands but they are not listed in the "Command" combo box of the "Menu Editor" dialog (even if successfully defined).

Is there another API to programmatically add actions to the context menu?

Thanks!
Ralf

Matthew

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 990
  • Hero Points: 44
Re: SlickEdit context menu ID
« Reply #1 on: November 01, 2013, 05:35:25 pm »
The context menu for the SlickEdit editor is controlled by our binaries. And the commands that can go on that menu have to be entries in our Slick-C macro language (and not commands that are exposed via Eclipse). We do provide a function in our Slick-C code that will invoke an Eclipse-defined command.

The first step is to create a new SlickEdit macro file, with a .e extension. You can start with the below example
Code: [Select]
#include "slick.sh"

_command void SampleMenuCommand()
{
    // Slick-C triggering a native Eclipse command
    _eclipse_execute_command("org.eclipse.ui.newWizard","","");
}

Save that as sample.e, and then use the Macro > Load Module… menu command and browse to that file. It will compile and load it into our Slick-C runtime. That SampleMenuCommand is now available to be bound to an entry in one of our menus.

That example above has two empty arguments at the end. The middle argument is for a list of comma-separated parameter names, and the last argument is for a comma-separated list of parameter values.
Here's an example from our own macro source that uses these parameters
Code: [Select]
/**
 * Activates the Outline view in Eclipse.
 */
_command void eclipse_show_outline() name_info(',')
{
   if (isEclipsePlugin()) {
      _eclipse_execute_command("org.eclipse.ui.views.showView","org.eclipse.ui.views.showView.viewId,org.eclipse.ui.views.showView.makeFast", "org.eclipse.ui.views.ContentOutline,false");
   } else {
      activate_defs();
   }
}

r.pakosch

  • Junior Community Member
  • Posts: 2
  • Hero Points: 0
Re: SlickEdit context menu ID
« Reply #2 on: November 08, 2013, 02:27:02 pm »
Hi Matthew,

thanks for the response! This interface sounds interesting, I'll give it a try.

Unfortunately this will probably not fully meet our requirements. We need to extend the context menu dynamically at runtime and without any additional steps (like creating macro files).

After some investigations I think the only thing that needs to be done by the SlickEdit editor plug-in is calling this method:

Code: [Select]
org.eclipse.ui.IEditorSite#registerContextMenu(MenuManager menuManager,
            ISelectionProvider selectionProvider, boolean includeEditorInput)

Most editors do this implicitly by extending org.eclipse.ui.texteditor.AbstractTextEditor.

After a context menu is registered by this method it can be extended by Eclipse command contributions, which is exactly what we need.

Thanks!
Ralf