Undo, redo
From Buzztard
The editor app. needs undo/redo. As a side effect handling undo/redo makes it easy to detect when the song has been changed. If there is nothing to undo since last save (load), it has not been changed ;).
Contents |
Existing implementations
GUndo
GUndo manages a sequence of actions. Echo action has callbacks for undo/redo and free. One can link toolbar/menu items to the sequence and the allow to go back and forth.
Everytime we add an action, we would need to pack the data + some context into a struct. When an action is added, it refs all related objects.
The GUndoSequence is a default implementation of the GUndoHistory Iface. We could have our own (GUndoSequence subclass?) that also write the history to a log file. This can be used for crash recovery. We can use the BtPersistence Iface to serialize the data objects. Maybe we just need two more callback for a new action (serialize/deserialize). It could store/restore the context and use BtPersistence for the objects.
Examples
add a machine
bt_setup_add_machine(setup, machine)
- object: machine
- parent: setup
- undo: bt_setup_remove_machine(setup, machine)
- redo: bt_setup_add_machine(setup, machine)
- free: g_object_unref(machine)
remove a machine
bt_setup_remove_machine(setup, machine)
- object: machine
- parent: setup
- undo: bt_setup_add_machine(setup, machine)
- redo: bt_setup_remove_machine(setup, machine)
- free: g_object_unref(machine)
entering something in a pattern
bt_pattern_set_global_event(pattern, tick, param, value)
- object: value, old_value, tick, param
- parent: pattern
- undo: bt_pattern_set_global_event(patter, tick, param, old_value)
- redo: bt_pattern_set_global_event(patter, tick, param, value)
- free: ...
Links
Undo/Redo Links
- http://www.codeproject.com/cpp/undoredo_cpp.asp
- if we cut a selection from a pattern, that is not a full object, like the examples in the article
- http://www.javaworld.com/javaworld/jw-06-1998/jw-06-undoredo.html
- http://www-dse.doc.ic.ac.uk/~np2/software/undo.html



