diff --git a/GCUndoManager.h b/GCUndoManager.h index aa83c12..f6cce86 100644 --- a/GCUndoManager.h +++ b/GCUndoManager.h @@ -12,8 +12,6 @@ // 2011/01/11 - fix to ensure submitting tasks in response to a checkpoint notification is correctly handled // 2011/07/08 - added NSUndoManagerDidCloseUndoGroupNotification for 10.7 (Lion) compatibility -#import - // internal undo manager state is one of these constants typedef enum @@ -31,6 +29,9 @@ typedef enum } GCUndoTaskCoalescingKind; +extern NSString * const GCUndoManagerWillDropUndoActionNotification; +extern NSString * const GCUndoManagerWillDropRedoActionNotification; +extern NSString * const GCUndoManagerActionKey; @class GCUndoGroup, GCUndoManagerProxy, GCConcreteUndoTask; diff --git a/GCUndoManager.m b/GCUndoManager.m index 373eb4e..87417b7 100644 --- a/GCUndoManager.m +++ b/GCUndoManager.m @@ -12,6 +12,9 @@ // on 10.6 so that a wider range of methods can be submitted as undo tasks. Unlike 10.6 however, it does not bypass um's -forwardInvocation: // method, so subclasses still work when -forwardInvocaton: is overridden. +NSString * const GCUndoManagerWillDropUndoActionNotification = @"GCUndoManagerWillDropUndoActionNotification"; +NSString * const GCUndoManagerWillDropRedoActionNotification = @"GCUndoManagerWillDropRedoActionNotification"; +NSString * const GCUndoManagerActionKey = @"GCUndoManagerActionKey"; @interface GCUndoManagerProxy : NSProxy { @@ -145,7 +148,7 @@ - (void) endUndoGrouping mIsRemovingTargets = YES; while([self numberOfUndoActions] > [self levelsOfUndo]) - [mUndoStack removeObjectAtIndex:0]; + [self dropOldestUndoAction]; mIsRemovingTargets = NO; } @@ -317,6 +320,24 @@ - (void) setGroupsByEvent:(BOOL) groupByEvent +- (void) dropOldestUndoAction +{ + NSDictionary * userInfo = [NSDictionary dictionaryWithObject:[mUndoStack objectAtIndex:0] forKey:GCUndoManagerActionKey]; + [[NSNotificationCenter defaultCenter] postNotificationName:GCUndoManagerWillDropUndoActionNotification object:self userInfo:userInfo]; + [mUndoStack removeObjectAtIndex:0]; +} + + + +- (void) dropOldestRedoAction +{ + NSDictionary * userInfo = [NSDictionary dictionaryWithObject:[mRedoStack objectAtIndex:0] forKey:GCUndoManagerActionKey]; + [[NSNotificationCenter defaultCenter] postNotificationName:GCUndoManagerWillDropRedoActionNotification object:self userInfo:userInfo]; + [mRedoStack removeObjectAtIndex:0]; +} + + + - (NSUInteger) levelsOfUndo { return mLevelsOfUndo; @@ -335,10 +356,10 @@ - (void) setLevelsOfUndo:(NSUInteger) levels mIsRemovingTargets = YES; while([self numberOfUndoActions] > levels) - [mUndoStack removeObjectAtIndex:0]; + [self dropOldestUndoAction]; while([self numberOfRedoActions] > levels) - [mRedoStack removeObjectAtIndex:0]; + [self dropOldestRedoAction]; mIsRemovingTargets = NO; }