Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Undo/Redo key bindings
Undo/Redo key bindings [message #777040] Mon, 09 January 2012 17:54 Go to next message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
Hi guys,

I have implemented a GEF based editor. My problem is with Undo and Redo actions keybindings.

The code in my editor
protected void createActions() {
	ActionRegistry registry = getActionRegistry();
	IAction action;
	
	action = new UndoAction(this);
	registry.registerAction(action);
	getStackActions().add(action.getId());
	
	action = new RedoAction(this);
	registry.registerAction(action);
	getStackActions().add(action.getId());
	
	...
}

and in my ActionBarContributor
@Override
protected void buildActions() {
	addRetargetAction(new UndoRetargetAction();
	addRetargetAction(new RedoRetargetAction());	
}

@Override
public void contributeToMenu(IMenuManager menubar) {
	super.contributeToMenu(menubar);
	IMenuManager editMenu = menubar.findMenuUsingPath("edit");
	if (editMenu != null) {
		editMenu.insertBefore(IWorkbenchActionConstants.MB_ADDITIONS, getAction(ActionFactory.UNDO.getId()));
		editMenu.insertBefore(IWorkbenchActionConstants.MB_ADDITIONS, getAction(ActionFactory.REDO.getId()));
	}	
}

Undo/Redo works fine except there is no key bindings for them. My code is same as in Logic example and when I run it, keybindigs work there.
Any ideas?

[Updated on: Mon, 09 January 2012 18:01]

Report message to a moderator

Re: Undo/Redo key bindings [message #777043 is a reply to message #777040] Mon, 09 January 2012 18:00 Go to previous messageGo to next message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
When I put this code to my ActionBarAdvisor
@Override
protected void makeActions(final IWorkbenchWindow window) {
	register(ActionFactory.UNDO.create(window));
	register(ActionFactory.REDO.create(window));
}

and edit editor's ActionBarContributor
@Override
protected void buildActions() {
	addRetargetAction(new UndoRetargetAction() {
			
		@Override
		public String getActionDefinitionId() {
			return ActionFactory.UNDO.getCommandId();
		}
	});
	addRetargetAction(new RedoRetargetAction() {
			
		@Override
		public String getActionDefinitionId() {
			return ActionFactory.REDO.getCommandId();
		}
	});
}

it works fine, but I don't think that it's the right solution.
It should work just with addRetargetAction(new UndoRetargetAction());
Re: Undo/Redo key bindings [message #777136 is a reply to message #777043] Mon, 09 January 2012 23:13 Go to previous messageGo to next message
Arieh Bibliowicz is currently offline Arieh BibliowiczFriend
Messages: 4
Registered: July 2009
Junior Member
Does your editor extend
GraphicalEditor
? if so, why not call
super.createActions()
to enable the undo, instead of repeating the same code that already exists in
GraphicalEditor
? I say this because this is what I do in my editor and things are working just fine. Its worth a try Smile
Re: Undo/Redo key bindings [message #777352 is a reply to message #777136] Tue, 10 January 2012 10:16 Go to previous message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
Hi Arieh,

yes, my editor extends GraphicalEditor and I don't override makeActions().
I just copied content of the GraphicalEditor's makeActions() method here to mention that Undo/Redo are properly registered.

Well as I said, Undo/Redo works, but theirs keybindings doesn't Sad
Previous Topic:Visual Designer - GEF + EMF + JEM - opensourced at eclipse labs
Next Topic:GEF functionality within other editor window
Goto Forum:
  


Current Time: Tue Apr 16 08:44:54 GMT 2024

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

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

Back to the top