一千萬個為什麽

搜索

如何禁用助記符?

我正在使用Eclipse插件基礎結構擴展Eclipse,我遇到了一個問題:

我創建了一個Eclipse編輯器,我想禁用助記符菜單Eclipse,例如:ALT + a等同於菜單Search。因為我需要在編輯器中使用這些組合(Alt + ...)。該怎麽辦?

最佳答案

按照此主題的建議:

創建您自己的方案並添加您需要的鍵綁定。在自定義ini文件中添加以下行:

org.eclipse.ui/KEY_CONFIGURATION_ID = 

請參閱 鍵綁定

alt text http://www.vogella.de/articles/EclipseCommands/images/ keybinding30.gif

Paul Webster所說:

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.

另一個解決方案,對於僅針對一個SWT組件的特定鍵事件處理,同時保持其余的默認方案,是添加一個監聽器(參見這個帖子):

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

轉載註明原文: 如何禁用助記符?