Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Undo/Redo Buttons stay disabled(Can't undo Commands on the CommandStack in the menu)
Undo/Redo Buttons stay disabled [message #882604] Wed, 06 June 2012 20:42 Go to next message
Christoph Bach is currently offline Christoph BachFriend
Messages: 5
Registered: June 2012
Junior Member
Hey,

so I got the issue on my previous post fixed and managed to put Commands via EditPolicies on the CommandStack and execute them. It all works fine and I'm even to determine the dirty state of the stack to be able to save the model to a file.

My problem now is that I can't click on undo/redo, because it stays disabled after model changes. I already made an ActionBarContributor like this and set it in the plugin.xml:

public class GameModelerActionBarContributor extends ActionBarContributor {

	@Override
	protected void buildActions() {
		addRetargetAction(new UndoRetargetAction());
		addRetargetAction(new RedoRetargetAction());

	}

	@Override
	protected void declareGlobalActionKeys() {
		// TODO Auto-generated method stub

	}
	
	@Override
	public void contributeToToolBar(IToolBarManager toolBarManager){
		toolBarManager.add(getAction(ActionFactory.UNDO.getId()));
		toolBarManager.add(getAction(ActionFactory.REDO.getId()));
	}

}


Did I miss something? Where do I have to tell Eclipse that there's something to undo?

Regards,
Christoph

Re: Undo/Redo Buttons stay disabled [message #882615 is a reply to message #882604] Wed, 06 June 2012 21:09 Go to previous messageGo to next message
Alexander Nyssen is currently offline Alexander NyssenFriend
Messages: 244
Registered: July 2009
Location: Lünen
Senior Member
Hi,

from what you describe a cannot precisely determine the underlying cause, so let me clarify some things and point you to some pitfalls you should check:

1) The EditPolicies are not responsible for executing command on the command stack. They only have the responsibility to return commands in oder to respond to request (see getCommand(Request)). The commands returned by the edit policies are chained together by their host edit part and returned in its getCommand(Request) method respectively. This method gets called by either the currently active tool, or by a selected action, which is responsible of finally executing the returned compound command on the stack. In order to get undo/redo working, the compound command returned by your edit part has to be undoable (isUndoable() has to return true), which is the case if all chained commands returned by its edit policies are undoable.

2) The undo and redo actions are not updated upon model changes, but upon changes of the command stack (they are referred to as stack actions). Besides the action bar contributor with the retarget actions, the mechanism for undo/redo requires that undo and redo actions are registered in the action registry of your editor and that these actions are updated by means of a CommandStackChangeListener whenever the stack changes. If your editor inherits from GraphicalEditor this should be the case. It registeres the action in the action registry in its initializeActionRegistry() method, maintains them in the list of stack actions, and updates them from within commandStackChanged(EventObject); the editor registered itself as CommandStackListener in its init(IEditorSite, IEditorInput).

Hope that clears things up a bit....

Cheers,
Alexander
Re: Undo/Redo Buttons stay disabled [message #882623 is a reply to message #882615] Wed, 06 June 2012 21:34 Go to previous messageGo to next message
Christoph Bach is currently offline Christoph BachFriend
Messages: 5
Registered: June 2012
Junior Member
Hi,

thanks for your reply. The Command is put on the CommandStack in a ButtonListener where I call getCommand width my request and this is passed to my policy which returns the Command.

When I call canUndo() on the Command, I get false, but I don't know why since I implemented undo(). When I override canUndo to make it return true, the buttons still say disabled in the toolbar.

I guess, there's something wrong with my Commands...
Btw: The Commands extend CompoundCommand.

Regards,
Christoph
Re: Undo/Redo Buttons stay disabled [message #883098 is a reply to message #882623] Thu, 07 June 2012 21:05 Go to previous messageGo to next message
Christoph Bach is currently offline Christoph BachFriend
Messages: 5
Registered: June 2012
Junior Member
Got it!. Had some bad code in my Editor class...
Didn't call super methods and stuff. Nevertheless thank you very much!
Re: Undo/Redo Buttons stay disabled [message #1080609 is a reply to message #883098] Tue, 06 August 2013 06:52 Go to previous message
NakKyu Sung is currently offline NakKyu SungFriend
Messages: 1
Registered: August 2013
Junior Member
Dear Christoph,

I have same problem now. Would you please kindly let me know how did you solve it?

Thanks in advance and regards.
NakKyu Sung.
Previous Topic:Connection bend points and snap to grid
Next Topic:Create two outline views
Goto Forum:
  


Current Time: Tue Mar 19 05:14:34 GMT 2024

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

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

Back to the top