Undo supported by snapshotting

From EOFWiki
Jump to: navigation, search

Code

#import <Foundation/Foundation.h>
#import <EOControl/EOControl.h>
 
 
@interface NSMutableDictionary ( EOEnterpriseObjectAdditions)
@end
 
 
@implementation NSMutableDictionary ( EOEnterpriseObjectAdditions)
 
- (void) updateFromSnapshot:(NSDictionary *) snapshot
{
   [self setDictionary:snapshot];
}
 
 
- (NSDictionary *) snapshot
{
   return [[self copy] autorelease];
}
 
@end
 
 
int main (int argc, const char * argv[])
{
   NSAutoreleasePool     *pool;
   EOEditingContext      *context;
   NSMutableDictionary   *obj;
 
 
   pool = [NSAutoreleasePool new];
 
   context = [[EOEditingContext new] autorelease];
 
   obj = [NSMutableDictionary dictionary];
 
   [context insertObject:obj];
 
   [obj willChange]; 
   [obj setObject:@"VfL Bochum 1848"
           forKey:@"club"];
   NSLog( @"A) %@", [obj snapshot]);
   [context undo:nil];
   NSLog( @"B) %@", [obj snapshot]);
 
   [context redo:nil];
   NSLog( @"C) %@", [obj snapshot]);
 
   [pool release];
   return 0;
}

Comment

...work in progress...

Output







				
				
Personal tools