Eclipse插件开发:为Editor ToolBar添加操作/键盘快捷键

时间:2015-03-03 10:22:55

标签: eclipse eclipse-plugin eclipse-rcp nodeclipse enide

Eclipse Image Viewer plugin内我要添加左右箭头键< - 或右 - > 到下一张或上一张图片(在全尺寸模式下)

QuickImageEditor使用ToolBarToolItem

https://github.com/Nodeclipse/quickimage/blob/master/quickimage/src/nu/psnet/quickimage/editors/QuickImageEditor.java#L118-128

    ToolBar toolBar = new ToolBar(compos, SWT.FLAT);
    toolBar.setLayoutData(toolbarData);


    previous = new ToolItem(toolBar, SWT.FLAT);
    previous.setToolTipText("Previous Image");
    previous.setImage(new Image(parent.getDisplay(), iconsdir + "previous.gif"));
    previous.setSelection(true);

虽然ToolItem没有添加密钥记录的API,但我将lister添加到ToolBar

添加的代码是

    toolBar.addKeyListener(new KeyListener(){
        //@Override
        public void keyPressed(KeyEvent e) {
        }
        //@Override
        public void keyReleased(KeyEvent e) {
            if (e.keyCode == SWT.ARROW_LEFT){
                clickedPrevious();  
                return;
            }
            if (e.keyCode == SWT.ARROW_RIGHT){
                clickedNext();
                return;
            }               
        }           
    });

然而,这不起作用。

如何向Eclipse编辑器添加键盘引导操作?

0 个答案:

没有答案