Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions GCUndoManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Cocoa/Cocoa.h>

// internal undo manager state is one of these constants

typedef enum
Expand All @@ -31,6 +29,9 @@ typedef enum
}
GCUndoTaskCoalescingKind;

extern NSString * const GCUndoManagerWillDropUndoActionNotification;
extern NSString * const GCUndoManagerWillDropRedoActionNotification;
extern NSString * const GCUndoManagerActionKey;

@class GCUndoGroup, GCUndoManagerProxy, GCConcreteUndoTask;

Expand Down
27 changes: 24 additions & 3 deletions GCUndoManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -145,7 +148,7 @@ - (void) endUndoGrouping
mIsRemovingTargets = YES;

while([self numberOfUndoActions] > [self levelsOfUndo])
[mUndoStack removeObjectAtIndex:0];
[self dropOldestUndoAction];

mIsRemovingTargets = NO;
}
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down