Eclipse plugin dev: Add actions / keyboard shortcut for Editor ToolBar

321 Views Asked by At

Inside Eclipse Image Viewer plugin I want to add moving on arrow keys left <- or right -> to the next or previous image (in Fullsize mode)

QuickImageEditor uses ToolBar and ToolItem.

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

While ToolItem doesn't have API to add keylister, I add lister to ToolBar.

added code is

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

This however does not work.

How to add keyboard-lead actions to Eclipse Editor?

0

There are 0 best solutions below