开发者

How to disable mnemonics?

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?


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 http://www.vogella.de/articles/EclipseCommands/images/keybinding30.gif

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 );
    }
} );


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>


This helped me with empty.scheme: Put this on top of your IApplication.start()

public Object start(IApplicationContext context) { 
    // set the default shortcuts
PlatformUI.getPreferenceStore().setDefault(IWorkbenchPreferenceConstants.KEY_CONFIGURATION_ID, "your.scheme"); //$NON-NLS-1$ 
    // start your app 
} 

and you will have the default scheme set to your.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜