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.
as Paul Webster puts it:
You can override a shortcut in one of 3 ways
- 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.
- 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 :)
- 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 );
}
} );