views:

227

answers:

3

I'm extending Eclipse using the Eclipse plugin infrastructure, and I've come into a problem:

I created an Eclipse editor and I would like to disable the mnemonic menus Eclipse, for example: ALT + a is equivalent to the menu Search. Because I need these combinations (Alt +...) in my editor. what to do?

+1  A: 

As recommended in this thread:

Create you own scheme and add the keybindings you need to it. In the customization ini file add this line:

org.eclipse.ui/KEY_CONFIGURATION_ID = <your scheme id>

See Keybindings.

alt text

as Paul Webster puts it:

You can override a shortcut in one of 3 ways

  1. create a new scheme with no parent. You can then define as many keybindings as you want, as you will see none of the default bindings.
  2. create a new scheme with the default scheme parent. You will inherit all of the default keybindings, but any that you define in your scheme will take precedence (I think :)
  3. create a child context off of the context containing some of the bindings. Any keys that you define in your context will take precedence over the original context.

Another solution, for a specific key event processing just for one SWT component, while keeping the default scheme for the rest, is to add a Listener (see this thread):

final Listener keyDownFilter = new Listener()
{
    private void postKeyEvent( final int type, final char character, final int keyCode )
    {
        final Display display = PlatformUI.getWorkbench().getDisplay();
        final Event event = new Event();
        event.type = type;
        event.character = character;
        event.keyCode = keyCode;
        display.post( event );
    }

    /* (non-Javadoc)
    * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
    */
    public void handleEvent( Event ev )
    {
        if ( ev.widget == RichText.this.editorControl )
        {
            if ( ( ev.keyCode == SWT.CR || ev.keyCode == SWT.KEYPAD_CR ) && ( ev.stateMask & SWT.SHIFT ) == 0 )
            {
                ev.doit = false;
                postKeyEvent( SWT.KeyDown, ( char ) 0, SWT.SHIFT );
                postKeyEvent( SWT.KeyDown, ev.character, ev.keyCode );
                postKeyEvent( SWT.KeyUp, ( char ) 0, SWT.SHIFT );
            }
        }
    }
};

final Display display = PlatformUI.getWorkbench().getDisplay();
display.addFilter( SWT.KeyDown, keyDownFilter );
this.editorControl.addDisposeListener( new DisposeListener()
{
    /* (non-Javadoc)
    * @see org.eclipse.swt.events.DisposeListener#widgetDisposed(org.eclipse.swt.events.DisposeEvent)
    */
    public void widgetDisposed( final DisposeEvent ev )
    {
        display.removeFilter( SWT.KeyDown, keyDownFilter );
    }
} );
VonC
Thank's for reply. I tried what you recommended but it did not work.in fact, I already use my propore Scheme when my editor is active (using IBindigService in FocusListener). In this case, the eclipse shortcuts do not work but the "File" menu activates when I press "ALT + F" for example (Alt+a activate the search menu) and I need his combinations (Alt +...) in my editor when they represent mnemonics menu of Eclipse!
Imen
@Imen: sorry to read that. I do hope you will find a solution and post it here. Did you try the child context tip to check if it was capturing some of those key events?
VonC
@VonC: First, thank you for the interest you have shown in my problem. I tried to use the Filter as you recommended but the problem is that when pressing ALT my editor intercepts the key but also Elipse. therefore my editor loses focus and Eclipse menus are activated (File, Search ..). I don't understand your question?
Imen
@Imen: Well, since "Any keys that you define in your context will take precedence over the original context", it looked like a good way to override the ALT "menu focus activation" behavior and replace that by your Editor shortcut activation. Hence my question.
VonC
any other ideas?
Imen
I asked this question in the eclipse site, here is the response I received: "There's no way to disable the mnemonics from within eclipse as they are acted upon by your platform (windows) and window manager (windows). You would have to disable mnemonics from windows itself" How can i disable mnemonics from windows?
Imen
@Imen: try http://www.autohotkey.com/ for instance
VonC
A: 

Sorry, I am a beginner in Eclipse plugin Developpment.

I do this: I create - a context:

<extension
     point="org.eclipse.ui.contexts">
  <context
        id="mycontext"
        name="My Context"
        parentId="org.eclipse.ui.textEditorScope">
  </context>

  • a scheme an keys to override Alt

  • a command

  • an ActionSet

    <action
           class="MyActionClass"
           definitionId="mycommand"
           icon="icons/..."
           id="myaction"
           label="My Action"
           menubarPath="..."
           tooltip="...">
     </action>
    

but it still does not work?

Imen
A: 

a scheme an keys to override Alt

<extension
     point="org.eclipse.ui.bindings">
  <scheme
        id="myscheme"
        name="My Scheme"
        parentId="org.eclipse.ui.defaultAcceleratorConfiguration">
  </scheme>
  <key
        commandId="mycommand"
        contextId="mycontext"
        schemeId="myscheme"
        sequence="Alt+A">
  </key>
  <key
        commandId="mycommand"
        contextId="mycontext"
        schemeId="myscheme"
        sequence="Alt">
  </key>

a command

<extension
     point="org.eclipse.ui.commands">
  <command
        id="mycommand"
        name="My Command">
  </command>

Imen