Permalink
Browse files

Completed conversion of 09_Undo.

  • Loading branch information...
1 parent 8abeb11 commit 6c225a8c1cbed4a1e37b0ebb1491bcce5a756e83 @jsyedidia jsyedidia committed Jun 2, 2008
View
@@ -3,4 +3,5 @@
*.app
*.pbxuser
*.perspectivev3
+*.mode1v3
TemplateIcon.icns
@@ -1,24 +0,0 @@
-//
-// MyDocument.h
-// RaiseMan
-//
-// Created by Aaron Hillegass on 9/24/07.
-// Copyright __MyCompanyName__ 2007 . All rights reserved.
-//
-
-
-#import <Cocoa/Cocoa.h>
-@class Person;
-
-@interface MyDocument : NSDocument
-{
- NSMutableArray *employees;
-}
-#pragma mark Accessors - 'employee'
-
-- (void)setEmployees:(NSMutableArray *)array;
-- (void)insertObject:(Person *)p
- inEmployeesAtIndex:(int)r;
-- (void)removeObjectFromEmployeesAtIndex:(int)r;
-
-@end
@@ -1,173 +0,0 @@
-//
-// MyDocument.m
-// RaiseMan
-//
-// Created by Aaron Hillegass on 9/24/07.
-// Copyright __MyCompanyName__ 2007 . All rights reserved.
-//
-
-#import "MyDocument.h"
-#import "Person.h"
-
-@interface MyDocument ()
-
-- (void)startObservingPerson:(Person *)p;
-- (void)stopObservingPerson:(Person *)p;
-
-@end
-
-@implementation MyDocument
-
-- (id)init
-{
- if (![super init])
- return nil;
-
- [self setEmployees:[NSMutableArray array]];
-
- return self;
-}
-
-- (void)dealloc
-{
- [self setEmployees:nil];
- [super dealloc];
-}
-
-#pragma mark Accessors - 'employees'
-- (void)startObservingPerson:(Person *)person
-{
- [person addObserver:self
- forKeyPath:@"personName"
- options:NSKeyValueObservingOptionOld
- context:NULL];
-
- [person addObserver:self
- forKeyPath:@"expectedRaise"
- options:NSKeyValueObservingOptionOld
- context:NULL];
-}
-
-- (void)stopObservingPerson:(Person *)person
-{
- [person removeObserver:self
- forKeyPath:@"personName"];
-
- [person removeObserver:self
- forKeyPath:@"expectedRaise"];
-}
-
-
-- (void)insertObject:(Person *)p
- inEmployeesAtIndex:(int)r
-{
- // Register the undo
- NSUndoManager *undo = [self undoManager];
- [[undo prepareWithInvocationTarget:self]
- removeObjectFromEmployeesAtIndex:r];
- if (![undo isUndoing]) {
- [undo setActionName:@"Insert Person"];
- }
- // Add the person to the array
- [self startObservingPerson:p];
- [employees insertObject:p atIndex:r];
-}
-- (void)removeObjectFromEmployeesAtIndex:(int)r
-{
- Person *p = [employees objectAtIndex:r];
-
- NSUndoManager *undo = [self undoManager];
- [[undo prepareWithInvocationTarget:self]
- insertObject:p inEmployeesAtIndex:r];
- if (![undo isUndoing]) {
- [undo setActionName:@"Delete Person"];
- }
- [self stopObservingPerson:p];
- [employees removeObjectAtIndex:r];
-}
-
-- (void)setEmployees:(NSMutableArray *)array
-{
- if (array == employees) {
- return;
- }
- for (Person *p in employees) {
- [self stopObservingPerson:p];
- }
- [employees release];
- [array retain];
- employees = array;
- for (Person *p in employees) {
- [self startObservingPerson:p];
- }
-}
-
-- (void)changeKeyPath:(NSString *)keyPath
- ofObject:(id)obj
- toValue:(id)newValue
-{
- [obj setValue:newValue forKeyPath:keyPath];
-}
-
-- (void)observeValueForKeyPath:(NSString *)keyPath
- ofObject:(id)obj
- change:(NSDictionary *)change
- context:(void *)context
-{
- NSUndoManager *undo = [self undoManager];
- id oldValue = [change objectForKey:NSKeyValueChangeOldKey];
- if (oldValue == [NSNull null]) {
- oldValue = nil;
- }
- NSLog(@"oldValue = %@", oldValue);
- [[undo prepareWithInvocationTarget:self]
- changeKeyPath:keyPath
- ofObject:obj
- toValue:oldValue];
- [undo setActionName:@"Edit"];
-}
-
-#pragma mark NSDocument methods
-
-- (NSString *)windowNibName
-{
- // Override returning the nib file name of the document
- // If you need to use a subclass of NSWindowController or if your document supports multiple NSWindowControllers, you should remove this method and override -makeWindowControllers instead.
- return @"MyDocument";
-}
-
-- (void)windowControllerDidLoadNib:(NSWindowController *) aController
-{
- [super windowControllerDidLoadNib:aController];
- // Add any code here that needs to be executed once the windowController has loaded the document's window.
-}
-
-- (NSData *)dataOfType:(NSString *)typeName error:(NSError **)outError
-{
- // Insert code here to write your document to data of the specified type. If the given outError != NULL, ensure that you set *outError when returning nil.
-
- // You can also choose to override -fileWrapperOfType:error:, -writeToURL:ofType:error:, or -writeToURL:ofType:forSaveOperation:originalContentsURL:error: instead.
-
- // For applications targeted for Panther or earlier systems, you should use the deprecated API -dataRepresentationOfType:. In this case you can also choose to override -fileWrapperRepresentationOfType: or -writeToFile:ofType: instead.
-
- if ( outError != NULL ) {
- *outError = [NSError errorWithDomain:NSOSStatusErrorDomain code:unimpErr userInfo:NULL];
- }
- return nil;
-}
-
-- (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName error:(NSError **)outError
-{
- // Insert code here to read your document from the given data of the specified type. If the given outError != NULL, ensure that you set *outError when returning NO.
-
- // You can also choose to override -readFromFileWrapper:ofType:error: or -readFromURL:ofType:error: instead.
-
- // For applications targeted for Panther or earlier systems, you should use the deprecated API -loadDataRepresentation:ofType. In this case you can also choose to override -readFromFile:ofType: or -loadFileWrapperRepresentation:ofType: instead.
-
- if ( outError != NULL ) {
- *outError = [NSError errorWithDomain:NSOSStatusErrorDomain code:unimpErr userInfo:NULL];
- }
- return YES;
-}
-
-@end
@@ -1,19 +0,0 @@
-//
-// Person.h
-// RaiseMan
-//
-// Created by Aaron Hillegass on 9/24/07.
-// Copyright 2007 __MyCompanyName__. All rights reserved.
-//
-
-#import <Foundation/Foundation.h>
-
-
-@interface Person : NSObject {
- NSString *personName;
- float expectedRaise;
-}
-@property (readwrite, copy) NSString *personName;
-@property (readwrite) float expectedRaise;
-
-@end
@@ -1,32 +0,0 @@
-//
-// Person.m
-// RaiseMan
-//
-// Created by Aaron Hillegass on 9/24/07.
-// Copyright 2007 __MyCompanyName__. All rights reserved.
-//
-
-#import "Person.h"
-
-
-@implementation Person
-
-@synthesize expectedRaise;
-@synthesize personName;
-
-- (id)init
-{
- [super init];
- expectedRaise = 5.0;
- personName = @"New Person";
- return self;
-}
-
-- (void)dealloc
-{
- [personName release];
- [super dealloc];
-}
-
-@end
-
@@ -11,10 +11,8 @@
8D15AC2D0486D014006FF6A4 /* MainMenu.nib in Resources */ = {isa = PBXBuildFile; fileRef = 2A37F4B6FDCFA73011CA2CEA /* MainMenu.nib */; };
8D15AC2E0486D014006FF6A4 /* MyDocument.nib in Resources */ = {isa = PBXBuildFile; fileRef = 2A37F4B4FDCFA73011CA2CEA /* MyDocument.nib */; };
8D15AC2F0486D014006FF6A4 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C165FFE840EACC02AAC07 /* InfoPlist.strings */; };
- 8D15AC310486D014006FF6A4 /* MyDocument.m in Sources */ = {isa = PBXBuildFile; fileRef = 2A37F4ACFDCFA73011CA2CEA /* MyDocument.m */; settings = {ATTRIBUTES = (); }; };
8D15AC320486D014006FF6A4 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 2A37F4B0FDCFA73011CA2CEA /* main.m */; settings = {ATTRIBUTES = (); }; };
8D15AC340486D014006FF6A4 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A7FEA54F5311CA2CBB /* Cocoa.framework */; };
- 9379BB510CA8616B006830B4 /* Person.m in Sources */ = {isa = PBXBuildFile; fileRef = 9379BB500CA8616B006830B4 /* Person.m */; };
AB0670A50DED05BE00E0ABDA /* Nu.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AB0670A40DED05BE00E0ABDA /* Nu.framework */; };
AB0670A70DED05E400E0ABDA /* main.nu in Resources */ = {isa = PBXBuildFile; fileRef = AB0670A60DED05E400E0ABDA /* main.nu */; };
/* End PBXBuildFile section */
@@ -23,8 +21,6 @@
089C1660FE840EACC02AAC07 /* English */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = English; path = English.lproj/InfoPlist.strings; sourceTree = "<group>"; };
1058C7A7FEA54F5311CA2CBB /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; sourceTree = "<absolute>"; };
13E42FBA07B3F13500E4EEF1 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = /System/Library/Frameworks/CoreData.framework; sourceTree = "<absolute>"; };
- 2A37F4ACFDCFA73011CA2CEA /* MyDocument.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MyDocument.m; sourceTree = "<group>"; };
- 2A37F4AEFDCFA73011CA2CEA /* MyDocument.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MyDocument.h; sourceTree = "<group>"; };
2A37F4B0FDCFA73011CA2CEA /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
2A37F4B5FDCFA73011CA2CEA /* English */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = English; path = English.lproj/MyDocument.nib; sourceTree = "<group>"; };
2A37F4B7FDCFA73011CA2CEA /* English */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = English; path = English.lproj/MainMenu.nib; sourceTree = "<group>"; };
@@ -34,8 +30,6 @@
32DBCF750370BD2300C91783 /* RaiseMan_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RaiseMan_Prefix.pch; sourceTree = "<group>"; };
8D15AC360486D014006FF6A4 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
8D15AC370486D014006FF6A4 /* RaiseMan.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = RaiseMan.app; sourceTree = BUILT_PRODUCTS_DIR; };
- 9379BB4F0CA8616B006830B4 /* Person.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Person.h; sourceTree = "<group>"; };
- 9379BB500CA8616B006830B4 /* Person.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Person.m; sourceTree = "<group>"; };
AB0670A40DED05BE00E0ABDA /* Nu.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Nu.framework; path = /Library/Frameworks/Nu.framework; sourceTree = "<absolute>"; };
AB0670A60DED05E400E0ABDA /* main.nu */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = main.nu; path = nu/main.nu; sourceTree = "<group>"; };
/* End PBXFileReference section */
@@ -83,7 +77,6 @@
isa = PBXGroup;
children = (
AB0670A30DED05A900E0ABDA /* Nu */,
- 2A37F4ABFDCFA73011CA2CEA /* Classes */,
2A37F4AFFDCFA73011CA2CEA /* Other Sources */,
2A37F4B8FDCFA73011CA2CEA /* Resources */,
2A37F4C3FDCFA73011CA2CEA /* Frameworks */,
@@ -92,17 +85,6 @@
name = RaiseMan;
sourceTree = "<group>";
};
- 2A37F4ABFDCFA73011CA2CEA /* Classes */ = {
- isa = PBXGroup;
- children = (
- 9379BB4F0CA8616B006830B4 /* Person.h */,
- 9379BB500CA8616B006830B4 /* Person.m */,
- 2A37F4AEFDCFA73011CA2CEA /* MyDocument.h */,
- 2A37F4ACFDCFA73011CA2CEA /* MyDocument.m */,
- );
- name = Classes;
- sourceTree = "<group>";
- };
2A37F4AFFDCFA73011CA2CEA /* Other Sources */ = {
isa = PBXGroup;
children = (
@@ -200,9 +182,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
- 8D15AC310486D014006FF6A4 /* MyDocument.m in Sources */,
8D15AC320486D014006FF6A4 /* main.m in Sources */,
- 9379BB510CA8616B006830B4 /* Person.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Oops, something went wrong.

0 comments on commit 6c225a8

Please sign in to comment.