UndoManager question


Hi Jules, is there a reason why there is no simple addUndoableAction in UndoManager (which does not call perform) ? Me thinks this way, see:

  1. Perform some action(s)
  2. Create UndoableAction(s) in the process
  3. When done, give the UndoableAction(s) to the UndoManager to handle (but not call perform)
  4. When undoing/redoing, call UndoManager::undo()/redo()



But why? Your action class needs to have a working perform() method, so why not just use that to do the action in the first place? The way you describe it would involve writing the action method twice, wouldn’t it?


Conceptually yes, but implementationwise not really. It’s a little complicated… I’ll have to think about it some, if I can redesign it to fit the UndoManager “pattern”…


no, i think is very simple. actually your “actions” are defined elsewere in the code (ie. called from a method), you just need to create a wrapper UndoableAction around that code, keep it out from your real calling implementation and use perform() instead of calling your “action” directly.

it’s no point in have to perform actions in code, and still create undoable actions afterwards… undoable actions already performs actions !