Performing Undo and Redo

Performing undo and redo is usually as simple as sending undo and redo messages to an NSUndoManager object. The undo message closes the last open undo group and then applies all the undo operations in that group (recording any undo operations as redo operations instead). The redo message likewise applies all the redo operations on the top redo group.

The undo method is intended for undoing top-level groups, and should not be used for nested undo groups. If any unclosed, nested undo groups are on the stack when undo is invoked, it raises an exception. To undo nested groups, you must explicitly close the group with an endUndoGrouping message, then use undoNestedGroup to undo it. Note also that if you turn off automatic grouping by event with setGroupsByEvent:, you must explicitly close the current undo group with endUndoGrouping before invoking either undo method.