COTrack documentationCOTrack <ETCollection>
A track represents usually a revision or commit sequence, but it is up to the class adopting the protocol to decide about the sequence content (the track nodes). What constitutes a change from the track standpoint is thus under the track class responsability. COTrack requires the presented changes to be objects that conform to COTrackNode. All nodes on a track must also be of the same kind.
A track content can be persistent (e.g. a normal undo track or a branch) or lazily constructed (e.g. a pattern undo track, see +[COUndoTrack trackForPattern:withEditingContext:] ).
Track Node Collection
You should implement these methods first, and then the other methods.
A track must also implement ETCollection support based on the core method listed above.
Basic Undo and Redo
Another part in the protocol is the basic Undo and Redo support that makes possible to move the current node accross the node collection, and interprets this move as an undo/redo action.
A selective undo means undoing a single action in the past, while keeping the more recent actions that depend on the undone one. A normal undo can be seen as a selective undo subcase where the undone action is the most recent one. The main difference lies in the fact, a selective undo usually requires to make a new commit that discards the undone changes while keeping the other changes that follow on the track. To compute this new commit, -undoNode: and -redoNode: can leverage the Diff API or some API built on top of it (e.g. -[COCommand inverse] ).
Accessing Track Nodes
- - (NSArray *) nodes
Returns all the nodes on the track.
Calling this methods mean all the nodes will be loaded in memory. For tracks that can contain 10000 nodes or even more, there is a cost involved, so the track implementation should rely on -nextNodeOnTrackFrom:backwards: as much as possible.
Changing Track Nodes
- - (id <COTrackNode>) currentNode
- - (void) undoNode: (id <COTrackNode>)aNode
- - (void) redoNode: (id <COTrackNode>)aNode
Undo and Redo
- - (void) undo