Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » CRT+A / CTR+Z / CTR+Y are not caught by a keylistner in a wizard
CRT+A / CTR+Z / CTR+Y are not caught by a keylistner in a wizard [message #666447] Wed, 20 April 2011 13:40 Go to next message
BLANC Philippe is currently offline BLANC PhilippeFriend
Messages: 89
Registered: July 2009
Member
Hello,
I'm developping a RCP application.
My application mange undo/redo cut/copy paste in my editors/views. everything is ok.
Now, I would like to manage these actions in some of my wizards.

I have a wizard with a TreeViewer.
I've added popup menu and key listeners to manage the cut/copy/paste and the undo/redo operations.
I have a problem for the undo/redo shortcuts: they are not detected by my key listener.

Here is my code:

mComputationTreeViewer.getControl().addKeyListener(new KeyListener() {
	@Override
	public void keyReleased(KeyEvent e) {}
	@Override
	public void keyPressed(KeyEvent e) {
		if((e.keyCode == 'c') && (e.stateMask == SWT.CTRL)) {
                       mCopyAction.run();
                }else if((e.keyCode == 'v') && (e.stateMask == SWT.CTRL)) {
                       mPasteAction.run();
                }else if((e.keyCode == 'z') && (e.stateMask == SWT.CTRL)) {
                       // Never call, WHY ????
                       mUndoAction.run();
                }else if((e.keyCode == 'y') && (e.stateMask == SWT.CTRL)) {
                       // Never call, WHY ????
                       mRedoAction.run();
                }
}});


If somebody has any suggestion...

Thank you.
Regards,

Philippe B.

PS: I'm working on Eclipse 3.5
Re: CRT+A / CTR+Z / CTR+Y are not caught by a keylistner in a wizard [message #666458 is a reply to message #666447] Wed, 20 April 2011 13:56 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Eclipse RCP uses the keybinding system along with commands and handlers.
undo and redo are bound to commands in the dialogAndWindows context,
which means they're eaten by the keybinding system before they'll get to
your wizard.

You can activate and then deactivate handlers for the undo and redo
commands in your wizard.

PW


--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Platform_Expression_Framework
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/helios/index.jsp?topic=/org.eclipse. platform.doc.isv/guide/workbench.htm


icon14.gif  Re: CRT+A / CTR+Z / CTR+Y are not caught by a keylistner in a wizard [message #666474 is a reply to message #666458] Wed, 20 April 2011 14:32 Go to previous message
BLANC Philippe is currently offline BLANC PhilippeFriend
Messages: 89
Registered: July 2009
Member
Hello Paul,
Thank you for your explanation.
So i found a previous post where your explain how to activate/deactivate a handler:
http://www.eclipsezone.com/eclipse/forums/t75054.html

Here is my code in my wizard:

// Handler activation
IHandlerService service = (IHandlerService) PlatformUI.getWorkbench().getService(IHandlerService.class);
AbstractHandler handler = new AbstractHandler() {
			@Override
			public Object execute(ExecutionEvent event) throws ExecutionException {
				mUndoAction.run();
				return null;
			}
};
IHandlerActivation handlerActivation = service.activateHandler("org.eclipse.ui.edit.undo", handler, new ActiveShellExpression(getShell()));





// Handler deactivation
service.deactivateHdanler(handlerActivation);
handlerActivation.getHandler().dispose(); 


Thank you very much.
Regards,
Philippe B.
Previous Topic:Start eclipse on Windows 7
Next Topic:DND with multiple Transfer Types
Goto Forum:
  


Current Time: Sun Dec 21 04:19:07 GMT 2014

Powered by FUDForum. Page generated in 0.01643 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software