Class: NSUndoManager
Overview
NSUndoManager is a general-purpose recorder of operations for undo and redo.
Instance Method Summary (collapse)
-
- beginUndoGrouping
Marks the beginning of an undo group.
-
- canRedo
Returns a Boolean value that indicates whether the receiver has any actions to redo.
-
- canUndo
Returns a Boolean value that indicates whether the receiver has any actions to undo.
-
- disableUndoRegistration
Disables the recording of undo operations, whether by registerUndoWithTarget:selector:object: or by invocation-based undo.
-
- enableUndoRegistration
Enables the recording of undo operations.
-
- endUndoGrouping
Marks the end of an undo group.
-
- groupingLevel
Returns the number of nested undo groups (or redo groups, if Redo was invoked last) in the current event loop.
-
- groupsByEvent
Returns a Boolean value that indicates whether the receiver automatically creates undo groups around each pass of the run loop.
-
- isRedoing
Returns a Boolean value that indicates whether the receiver is in the process of performing its redo method.
-
- isUndoing
Returns a Boolean value that indicates whether the receiver is in the process of performing its undo or undoNestedGroup method.
-
- isUndoRegistrationEnabled
Returns a Boolean value that indicates whether the recording of undo operations is enabled.
-
- levelsOfUndo
Returns the maximum number of top-level undo groups the receiver holds.
-
- prepareWithInvocationTarget:
Prepares the receiver for invocation-based undo with the given target as the subject of the next undo operation and returns self.
-
- redo
Performs the operations in the last group on the redo stack, if there are any, recording them on the undo stack as a single group.
-
- redoActionIsDiscardable
Returns whether the next redo action is discardable.
-
- redoActionName
Returns the name identifying the redo action.
-
- redoMenuItemTitle
Returns the complete title of the Redo menu command, for example, “Redo Paste.” Returns “Redo” if no action name has been assigned or nil if there is nothing to redo.
-
- redoMenuTitleForUndoActionName:
Returns the complete, localized title of the Redo menu command for the action identified by the given name.
-
- registerUndoWithTarget:selector:object:
Records a single undo operation for a given target, so that when an undo is performed it is sent a specified selector with a given object as the sole argument.
-
- removeAllActions
Clears the undo and redo stacks and re-enables the receiver.
-
- removeAllActionsWithTarget:
Clears the undo and redo stacks of all operations involving the specified target as the recipient of the undo message.
-
- runLoopModes
Returns the modes governing the types of input handled during a cycle of the run loop.
-
- setActionIsDiscardable:
Sets whether the next undo or redo action is discardable.
-
- setActionName:
Sets the name of the action associated with the Undo or Redo command.
-
- setGroupsByEvent:
Sets a Boolean value that specifies whether the receiver automatically groups undo operations during the run loop.
-
- setLevelsOfUndo:
Sets the maximum number of top-level undo groups the receiver holds.
-
- setRunLoopModes:
Sets the modes that determine the types of input handled during a cycle of the run loop.
-
- undo
Closes the top-level undo group if necessary and invokes undoNestedGroup.
-
- undoActionIsDiscardable
Returns whether the next undo action is discardable.
-
- undoActionName
Returns the name identifying the undo action.
-
- undoMenuItemTitle
Returns the complete title of the Undo menu command, for example, “Undo Paste.” Returns “Undo” if no action name has been assigned or nil if there is nothing to undo.
-
- undoMenuTitleForUndoActionName:
Returns the complete, localized title of the Undo menu command for the action identified by the given name.
-
- undoNestedGroup
Performs the undo operations in the last undo group (whether top-level or nested), recording the operations on the redo stack as a single group.
Methods inherited from NSObject
#!, #!=, #!~, #, #==, #===, #=~, #Rational, #__callee__, #__method__, #__send__, #__type__, `, alloc, allocWithZone:, #autoContentAccessingProxy, autoload, autoload?, autorelease_pool, #awakeAfterUsingCoder:, binding, block_given?, caller, cancelPreviousPerformRequestsWithTarget:, cancelPreviousPerformRequestsWithTarget:selector:object:, catch, class, classFallbacksForKeyedArchiver, #classForCoder, #classForKeyedArchiver, classForKeyedUnarchiver, #clone, conformsToProtocol:, #copy, copyWithZone:, #dealloc, #define_singleton_method, description, display, #doesNotRecognizeSelector:, #dup, #enum_for, #eql?, #equal?, #extend, fail, #finalize, format, #forwardInvocation:, #forwardingTargetForSelector:, framework, #freeze, #frozen?, getpass, gets, global_variables, #init, initialize, #initialize_clone, #initialize_copy, #initialize_dup, #inspect, instanceMethodForSelector:, instanceMethodSignatureForSelector:, #instance_eval, #instance_exec, #instance_of?, #instance_variable_defined?, #instance_variable_get, #instance_variable_set, #instance_variables, instancesRespondToSelector:, isSubclassOfClass:, #is_a?, iterator?, #kind_of?, lambda, load, load_bridge_support_file, load_plist, local_variables, loop, #method, #methodForSelector:, #methodSignatureForSelector:, #methods, #mutableCopy, mutableCopyWithZone:, new, #nil?, open, p, #performSelector:onThread:withObject:waitUntilDone:, #performSelector:onThread:withObject:waitUntilDone:modes:, #performSelector:withObject:afterDelay:, #performSelector:withObject:afterDelay:inModes:, #performSelectorInBackground:withObject:, #performSelectorOnMainThread:withObject:waitUntilDone:, #performSelectorOnMainThread:withObject:waitUntilDone:modes:, print, printf, #private_methods, proc, #protected_methods, #public_method, #public_methods, #public_send, putc, puts, raise, rand, readline, readlines, #replacementObjectForCoder:, #replacementObjectForKeyedArchiver:, require, resolveClassMethod:, resolveInstanceMethod:, #respond_to?, #respond_to_missing?, select, #send, setVersion:, #singleton_methods, sprintf, srand, superclass, #taint, #tainted?, #tap, test, throw, #to_plist, #to_s, trace_var, trap, #trust, #untaint, untrace_var, #untrust, #untrusted?, version
Constructor Details
This class inherits a constructor from NSObject
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class NSObject
Instance Method Details
- (Object) beginUndoGrouping
Marks the beginning of an undo group. All individual undo operations before a subsequent endUndoGrouping message are grouped together and reversed by a later undo message. By default undo groups are begun automatically at the start of the event loop, but you can begin your own undo groups with this method, and nest them within other groups.This method posts an NSUndoManagerCheckpointNotification unless a top-level undo is in progress. It posts an NSUndoManagerDidOpenUndoGroupNotification if a new group was successfully created.
- (Boolean) canRedo
Returns a Boolean value that indicates whether the receiver has any actions to redo. Because any undo operation registered clears the redo stack, this method posts an NSUndoManagerCheckpointNotification to allow clients to apply their pending operations before testing the redo stack.
- (Boolean) canUndo
Returns a Boolean value that indicates whether the receiver has any actions to undo. The return value does not mean you can safely invoke undo or undoNestedGroup—you may have to close open undo groups first.
- (Object) disableUndoRegistration
Disables the recording of undo operations, whether by registerUndoWithTarget:selector:object: or by invocation-based undo. This method can be invoked multiple times by multiple clients. The enableUndoRegistration method must be invoked an equal number of times to re-enable undo registration.
- (Object) enableUndoRegistration
Enables the recording of undo operations. Because undo registration is enabled by default, it is often used to balance a prior disableUndoRegistration message. Undo registration isn’t actually re-enabled until an enable message balances the last disable message in effect. Raises an NSInternalInconsistencyException if invoked while no disableUndoRegistration message is in effect.
- (Object) endUndoGrouping
Marks the end of an undo group. All individual undo operations back to the matching beginUndoGrouping message are grouped together and reversed by a later undo or undoNestedGroup message. Undo groups can be nested, thus providing functionality similar to nested transactions. Raises an NSInternalInconsistencyException if there’s no beginUndoGrouping message in effect.This method posts an NSUndoManagerCheckpointNotification and an NSUndoManagerDidCloseUndoGroupNotification just before the group is closed.
- (Integer) groupingLevel
Returns the number of nested undo groups (or redo groups, if Redo was invoked last) in the current event loop.
- (Boolean) groupsByEvent
Returns a Boolean value that indicates whether the receiver automatically creates undo groups around each pass of the run loop.
The default is YES.
- (Boolean) isRedoing
Returns a Boolean value that indicates whether the receiver is in the process of performing its redo method.
- (Boolean) isUndoing
Returns a Boolean value that indicates whether the receiver is in the process of performing its undo or undoNestedGroup method.
- (Boolean) isUndoRegistrationEnabled
Returns a Boolean value that indicates whether the recording of undo operations is enabled. Undo registration is enabled by default.
- (Integer) levelsOfUndo
Returns the maximum number of top-level undo groups the receiver holds. When ending an undo group results in the number of groups exceeding this limit, the oldest groups are dropped from the stack. The default is 0.
- (Object) prepareWithInvocationTarget(target)
Prepares the receiver for invocation-based undo with the given target as the subject of the next undo operation and returns self. See “Registering Undo Operations” for more information.
- (Object) redo
Performs the operations in the last group on the redo stack, if there are any, recording them on the undo stack as a single group. Raises an NSInternalInconsistencyException if the method is invoked during an undo operation.This method posts an NSUndoManagerCheckpointNotification and NSUndoManagerWillRedoChangeNotification before it performs the redo operation, and it posts the NSUndoManagerDidRedoChangeNotification after it performs the redo operation.
- (Boolean) redoActionIsDiscardable
Returns whether the next redo action is discardable. Specifies that the latest redo action may be safely discarded when a document can not be saved for any reason. These are typically actions that don’t effect persistent state.An example might be an redo action that changes the viewable area of a document.
- (String) redoActionName
Returns the name identifying the redo action. For example, if the menu title is “Redo Delete,” the string returned is “Delete.”
- (String) redoMenuItemTitle
Returns the complete title of the Redo menu command, for example, “Redo Paste.” Returns “Redo” if no action name has been assigned or nil if there is nothing to redo.
- (String) redoMenuTitleForUndoActionName(actionName)
Returns the complete, localized title of the Redo menu command for the action identified by the given name. Override this method if you want to customize the localization behavior. This method is invoked by redoMenuItemTitle.
- (Object) registerUndoWithTarget(target, selector:aSelector, object:anObject)
Records a single undo operation for a given target, so that when an undo is performed it is sent a specified selector with a given object as the sole argument. Also clears the redo stack. Does not retain target, but does retain anObject. See “Registering Undo Operations” for more information.Raises an NSInternalInconsistencyException if invoked when no undo group has been established using beginUndoGrouping. Undo groups are normally set by default, so you should rarely need to begin a top-level undo group explicitly.
- (Object) removeAllActions
Clears the undo and redo stacks and re-enables the receiver.
- (Object) removeAllActionsWithTarget(target)
Clears the undo and redo stacks of all operations involving the specified target as the recipient of the undo message. Doesn’t re-enable the receiver if it’s disabled. An object that shares an NSUndoManager with other clients should invoke this message in its implementation of dealloc.
- (Array) runLoopModes
Returns the modes governing the types of input handled during a cycle of the run loop. By default, the sole run-loop mode is NSDefaultRunLoopMode (which excludes data from NSConnection objects).
- (Object) setActionIsDiscardable(discardable)
Sets whether the next undo or redo action is discardable. Specifies that the latest undo action may be safely discarded when a document can not be saved for any reason. An example might be an undo action that changes the viewable area of a document. To find out if an undo group contains only discardable actions, look for the NSUndoManagerGroupIsDiscardableKey in the userInfo dictionary of the NSUndoManagerWillCloseUndoGroupNotification.
- (Object) setActionName(actionName)
Sets the name of the action associated with the Undo or Redo command. If actionName is an empty string, the action name currently associated with the menu command is removed. There is no effect if actionName is nil.
- (Object) setGroupsByEvent(flag)
Sets a Boolean value that specifies whether the receiver automatically groups undo operations during the run loop. The default is YES. If you turn automatic grouping off, you must close groups explicitly before invoking either undo or undoNestedGroup.
- (Object) setLevelsOfUndo(anInt)
Sets the maximum number of top-level undo groups the receiver holds. When ending an undo group results in the number of groups exceeding this limit, the oldest groups are dropped from the stack. The default is 0.If invoked with a limit below the prior limit, old undo groups are immediately dropped.
- (Object) setRunLoopModes(modes)
Sets the modes that determine the types of input handled during a cycle of the run loop. By default, the sole run-loop mode is NSDefaultRunLoopMode (which excludes data from NSConnection objects). With this method, you could limit the input to data received during a mouse-tracking session by setting the mode to NSEventTrackingRunLoopMode, or you could limit it to data received from a modal panel with NSModalPanelRunLoopMode.
- (Object) undo
Closes the top-level undo group if necessary and invokes undoNestedGroup. This method also invokes endUndoGrouping if the nesting level is 1. Raises an NSInternalInconsistencyException if more than one undo group is open (that is, if the last group isn’t at the top level).This method posts an NSUndoManagerCheckpointNotification.
- (Boolean) undoActionIsDiscardable
Returns whether the next undo action is discardable. Specifies that the latest undo action may be safely discarded when a document can not be saved for any reason. These are typically actions that don’t effect persistent state.An example might be an undo action that changes the viewable area of a document.
- (String) undoActionName
Returns the name identifying the undo action. For example, if the menu title is “Undo Delete,” the string returned is “Delete.”
- (String) undoMenuItemTitle
Returns the complete title of the Undo menu command, for example, “Undo Paste.” Returns “Undo” if no action name has been assigned or nil if there is nothing to undo.
- (String) undoMenuTitleForUndoActionName(actionName)
Returns the complete, localized title of the Undo menu command for the action identified by the given name. Override this method if you want to customize the localization behavior. This method is invoked by undoMenuItemTitle.
- (Object) undoNestedGroup
Performs the undo operations in the last undo group (whether top-level or nested), recording the operations on the redo stack as a single group. Raises an NSInternalInconsistencyException if any undo operations have been registered since the last enableUndoRegistration message.This method posts an NSUndoManagerCheckpointNotification and NSUndoManagerWillUndoChangeNotification before it performs the undo operation, and it posts an NSUndoManagerDidUndoChangeNotification after it performs the undo operation.