sialcasa / mvvmFX

an Application Framework for implementing the MVVM Pattern with JavaFX
Apache License 2.0
489 stars 104 forks source link

Command Wrapper for Undo Commands #212

Open muxmax opened 9 years ago

muxmax commented 9 years ago

For an easier imaplementation of do-undo-commands some syntactic sugar would be nice that allows me to define for each command a corresponding undo command - just like this:

// class field
private Stack commandStack = new Stack<>()

public void doASpecificOperationThatAllowsUndoing() {
   Command doCommand = new DelegateCommand(() -> executeAnOperation);
   Command undoCommand = new DelegateCommand(() -> executeAnInverseOperation);

   CommandPair undoCommandPair = new CommandPair(doCommand, undoCommand);
   undoCommandPair.do();
   commandStack.push(undoCommandPair);
}

public void undoLastOperation() {
   commandStack.pop().undo();
}

This would be really cool. Maybe I have missed an information from the wiki, but I did not spot any stuff like this.

sialcasa commented 9 years ago

Good Idea, can you provide an implementation and create a PR?