CPObjectCPUndoManager
@implementation CPUndoManager : CPObject
CPUndoManager
provides a general mechanism supporting implementation of user action "undo" in applications. Essentially, it allows you to store sequences of messages and receivers that need to be invoked to undo or redo an action. The various methods in this class provide for grouping of sets of actions, execution of undo or redo actions, and tuning behavior parameters such as the size of the undo stack. Each application entity with its own editing history (e.g., a document) should have its own undo manager instance. Obtain an instance through a simple [[CPUndoManager alloc] init]
message.
Method Summary | |
---|---|
-(id) | init Initializes the undo manager. |
-(id) | initWithCoder:(CPCoder)aCoder |
-(void) | beginUndoGrouping Starts a new grouping of undo tasks, and makes it the current grouping. |
-(BOOL) | canRedo Returns YES if the user can perform a redo operation. |
-(BOOL) | canUndo Returns YES if the user can perform an undo operation. |
-(void) | disableUndoRegistration Disables undo registrations. |
-(void) | enableUndoRegistration Enables undo registrations. |
-(void) | encodeWithCoder:(CPCoder)aCoder |
-(void) | endUndoGrouping Closes the current undo grouping. |
-(void) | forwardInvocation:(CPInvocation)anInvocation Records the specified invocation as an undo operation. |
-(unsigned) | groupingLevel Returns the number of undo/redo groups. |
-(BOOL) | groupsByEvent Returns YES if the manager groups undo operations at every iteration of the run loop. |
-(BOOL) | isRedoing Returns YES if the manager is currently performing a redo. |
-(BOOL) | isUndoRegistrationEnabled Returns YES if undo registration is enabled. |
-(BOOL) | isUndoing Returns YES if the manager is currently performing an undo. |
-(id) | prepareWithInvocationTarget:(id)aTarget Prepares the specified target for the undo action. |
-(void) | redo Performs the redo operation using the last grouping on the redo stack. |
-(CPString) | redoActionName If the receiver can perform a redo, this method returns the action name previously associated with the top grouping with -setActionName: . |
-(void) | registerUndoWithTarget:(id)aTarget selector:(SEL)aSelector object:(id)anObject Registers an undo operation. |
-(void) | removeAllActions Clears all redo and undo operations and enables undo registrations. |
-(void) | removeAllActionsWithTarget:(id)aTarget Removes any redo and undo operations that use the specified target. |
-(CPArray) | runLoopModes Returns the CPRunLoopMode s in which the receiver registers
the -endUndoGrouping processing when it -groupsByEvent . |
-(void) | setActionName:(CPString)anActionName Sets the name associated with the actions of the current group. |
-(void) | setGroupsByEvent:(BOOL)aFlag Sets whether the manager should group undo operations at every iteration of the run loop. |
-(void) | setRunLoopModes:(CPArray)modes Sets the modes in which the receiver registers the calls with the current run loop to invoke -endUndoGrouping
when it -groupsByEvent . |
-(void) | undo Ends the current grouping, and performs an 'undo' operation. |
-(CPString) | undoActionName If the receiver can perform an undo, this method returns the action name previously associated with the top grouping with -setActionName: . |
-(void) | undoNestedGroup Performs an undo on the last undo group. |
Method Detail |
---|
-(id)init
-(id)initWithCoder:(CPCoder)aCoder
aCoder
-(void)beginUndoGrouping
-(BOOL)canRedo
YES
if the user can perform a redo operation.-(BOOL)canUndo
YES
if the user can perform an undo operation.-(void)disableUndoRegistration
-(void)enableUndoRegistration
disableUndoRegistration
.
So, if two disable calls were made, two enable calls are required
to actually enable undo registration again.-(void)encodeWithCoder:(CPCoder)aCoder
aCoder
-(void)endUndoGrouping
CPInternalInconsistencyException
- if no undo group is open-(void)forwardInvocation:(CPInvocation)anInvocation
anInvocation
- the message to record-(unsigned)groupingLevel
-(BOOL)groupsByEvent
YES
if the manager groups undo operations at every iteration of the run loop.-(BOOL)isRedoing
YES
if the manager is currently performing a redo.-(BOOL)isUndoRegistrationEnabled
YES
if undo registration is enabled.-(BOOL)isUndoing
YES
if the manager is currently performing an undo.-(id)prepareWithInvocationTarget:(id)aTarget
aTarget
- the target to receive the action-(void)redo
-(CPString)redoActionName
-setActionName:
. This name should identify the action to be redone.nil
if no there's no redo on the stack.
-(void)registerUndoWithTarget:(id)aTarget selector:(SEL)aSelector object:(id)anObject
-disableUndoRegistration
, this method does nothing.aTarget
- the target for the undo invocationaSelector
- the selector for the action messageanObject
- the argument for the action messageCPInternalInconsistencyException
- if no undo group is currently open-(void)removeAllActions
-(void)removeAllActionsWithTarget:(id)aTarget
aTarget
- the target for which operations should be removed.-(CPArray)runLoopModes
CPRunLoopMode
s in which the receiver registers
the -endUndoGrouping
processing when it -groupsByEvent
.-(void)setActionName:(CPString)anActionName
anActionName
- the new name for the current group-(void)setGroupsByEvent:(BOOL)aFlag
aFlag
- YES
groups undo operations-(void)setRunLoopModes:(CPArray)modes
-endUndoGrouping
when it -groupsByEvent
. This method first
cancels any pending registrations in the old modes and
registers the invocation in the new modes.modes
- the modes in which calls are registered-(void)undo
-(CPString)undoActionName
-setActionName:
. This name should identify the action to be undone.nil
if no if there's no undo on the stack.
-(void)undoNestedGroup
Created on Sat Sep 13 14:15:43 PDT 2008