PSPDFUndoSupport

Objective-C

@protocol PSPDFUndoSupport <NSObject>

Swift

protocol UndoSupport : NSObjectProtocol

Implement on model objects that should allow undo/redo.

  • Keys that should be KVO observed. Observed collections will be deeply introspected.

    Warning

    Only observe collections of type NSSet, NSOrderedSet and NSArray.

    Warning

    Do not change the result of this method dynamically.

    Declaration

    Objective-C

    + (nonnull NSSet<NSString *> *)keysForValuesToObserveForUndo;

    Swift

    static func keysForValuesToObserveForUndo() -> Set<String>
  • Returns the localized undo action name for a given key.

    Note

    If this method is not implemented or returns nil, the name of the key is used.

    Declaration

    Objective-C

    + (nullable NSString *)localizedUndoActionNameForKey:(nonnull NSString *)key;

    Swift

    optional static func localizedUndoActionName(forKey key: String) -> String?
  • Returns the coalescing for a given key.

    Note

    If this method is not implemented, PSPDFUndoCoalescingNone will be used for all keys.

    Warning

    Do not change the result of this method dynamically.

    Declaration

    Objective-C

    + (PSPDFUndoCoalescing)undoCoalescingForKey:(nonnull NSString *)key;

    Swift

    optional static func undoCoalescing(forKey key: String) -> UndoCoalescingg
  • Required when observing collections. It is your responsibility to update the affected collection.

    Note

    The index of an element is not preserved, so the order of elements in a collection might change during an undo operation.

    Warning

    It is your responsibility to trigger appropriate KVO events when you insert or remove an object. The easiest way to do this is to call mutable<CollectionType>ValueForKey: on self and to modify that collection object.

    Declaration

    Objective-C

    - (void)insertUndoObjects:(nonnull NSSet *)objects
                       forKey:(nonnull NSString *)key;

    Swift

    optional func insertUndoObjects(_ objects: Set<AnyHashable>, forKey key: String)
  • Undocumented

    Declaration

    Objective-C

    - (void)removeUndoObjects:(NSSet *)objects forKey:(NSString *)key;

    Swift

    optional func removeUndoObjects(_ objects: Set<AnyHashable>, forKey key: String)
  • Called when changes caused by an undo or redo were applied to an object.

    Declaration

    Objective-C

    - (void)didUndoOrRedoChange:(nonnull NSString *)key;

    Swift

    optional func didUndoOrRedoChange(_ key: String)
  • Required for conditional undo removal support. Implementing this method makes sure the internal undo manager records the correct target object, so we’re able to use removeAllActionsWithTarget: for undo removal, by passing in self as the method parameter. Your implementation should pass the action parameter through to-[PSPDFUndoController performUndoAction:]`.

    Declaration

    Objective-C

    - (void)performUndoAction:(nonnull PSPDFUndoAction *)action;

    Swift

    optional func perform(_ action: PSPDFUndoAction)