<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>09_Undo/RaiseMan_B/English.lproj/Credits.rtf</filename>
    </added>
    <added>
      <filename>09_Undo/RaiseMan_B/English.lproj/InfoPlist.strings</filename>
    </added>
    <added>
      <filename>09_Undo/RaiseMan_B/English.lproj/MainMenu.nib/designable.nib</filename>
    </added>
    <added>
      <filename>09_Undo/RaiseMan_B/English.lproj/MainMenu.nib/keyedobjects.nib</filename>
    </added>
    <added>
      <filename>09_Undo/RaiseMan_B/English.lproj/MyDocument.nib/designable.nib</filename>
    </added>
    <added>
      <filename>09_Undo/RaiseMan_B/English.lproj/MyDocument.nib/keyedobjects.nib</filename>
    </added>
    <added>
      <filename>09_Undo/RaiseMan_B/Info.plist</filename>
    </added>
    <added>
      <filename>09_Undo/RaiseMan_B/RaiseMan.xcodeproj/project.pbxproj</filename>
    </added>
    <added>
      <filename>09_Undo/RaiseMan_B/RaiseMan_Prefix.pch</filename>
    </added>
    <added>
      <filename>09_Undo/RaiseMan_B/main.m</filename>
    </added>
    <added>
      <filename>09_Undo/RaiseMan_B/nu/main.nu</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -3,4 +3,5 @@
 *.app
 *.pbxuser
 *.perspectivev3
+*.mode1v3
 TemplateIcon.icns</diff>
      <filename>.gitignore</filename>
    </modified>
    <modified>
      <diff>@@ -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 = &quot;&lt;group&gt;&quot;; };
 		1058C7A7FEA54F5311CA2CBB /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; sourceTree = &quot;&lt;absolute&gt;&quot;; };
 		13E42FBA07B3F13500E4EEF1 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = /System/Library/Frameworks/CoreData.framework; sourceTree = &quot;&lt;absolute&gt;&quot;; };
-		2A37F4ACFDCFA73011CA2CEA /* MyDocument.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MyDocument.m; sourceTree = &quot;&lt;group&gt;&quot;; };
-		2A37F4AEFDCFA73011CA2CEA /* MyDocument.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MyDocument.h; sourceTree = &quot;&lt;group&gt;&quot;; };
 		2A37F4B0FDCFA73011CA2CEA /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = &quot;&lt;group&gt;&quot;; };
 		2A37F4B5FDCFA73011CA2CEA /* English */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = English; path = English.lproj/MyDocument.nib; sourceTree = &quot;&lt;group&gt;&quot;; };
 		2A37F4B7FDCFA73011CA2CEA /* English */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = English; path = English.lproj/MainMenu.nib; sourceTree = &quot;&lt;group&gt;&quot;; };
@@ -34,8 +30,6 @@
 		32DBCF750370BD2300C91783 /* RaiseMan_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RaiseMan_Prefix.pch; sourceTree = &quot;&lt;group&gt;&quot;; };
 		8D15AC360486D014006FF6A4 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = &quot;&lt;group&gt;&quot;; };
 		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 = &quot;&lt;group&gt;&quot;; };
-		9379BB500CA8616B006830B4 /* Person.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Person.m; sourceTree = &quot;&lt;group&gt;&quot;; };
 		AB0670A40DED05BE00E0ABDA /* Nu.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Nu.framework; path = /Library/Frameworks/Nu.framework; sourceTree = &quot;&lt;absolute&gt;&quot;; };
 		AB0670A60DED05E400E0ABDA /* main.nu */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = main.nu; path = nu/main.nu; sourceTree = &quot;&lt;group&gt;&quot;; };
 /* 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 = &quot;&lt;group&gt;&quot;;
 		};
-		2A37F4ABFDCFA73011CA2CEA /* Classes */ = {
-			isa = PBXGroup;
-			children = (
-				9379BB4F0CA8616B006830B4 /* Person.h */,
-				9379BB500CA8616B006830B4 /* Person.m */,
-				2A37F4AEFDCFA73011CA2CEA /* MyDocument.h */,
-				2A37F4ACFDCFA73011CA2CEA /* MyDocument.m */,
-			);
-			name = Classes;
-			sourceTree = &quot;&lt;group&gt;&quot;;
-		};
 		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;
 		};</diff>
      <filename>09_Undo/RaiseMan_A/RaiseMan.xcodeproj/project.pbxproj</filename>
    </modified>
    <modified>
      <diff>@@ -1,17 +1,57 @@
 (import Cocoa)		;; bridgesupport
 (load &quot;console&quot;)	;; interactive console
 
-(class MyDocument
-    (ivar (id) employees)
+(class Person is NSObject
+     (ivar (id) personName (float) expectedRaise)
+     (ivar-accessors)
+     
+     (- (id) init is
+        (super init)
+        (set @expectedRaise 5.0)
+        (set @personName &quot;New Person&quot;)
+        self)
+        
+    (- (void) setNilValueForKey: (id) key is
+        (if (key isEqual:&quot;expectedRaise&quot;)
+            (self setExpectedRaise:0.0)
+            (else (super setNilValueForKey:key)))))
+
+(class MyDocument is NSDocument
+    (ivar (id) employees (id) employeeController (id) tableView)
     
     (- (id) init is
-        (NSLog &quot;init&quot;)
         (super init)
         (self setEmployees:(array))
         self)
+
+    (- (BOOL) endEditing is
+        (set w (@tableView window))
+        (set editingEnded (w makeFirstResponder:w))
+        (unless (editingEnded) NO)
+        (set undo (self undoManager))
+        (if (undo groupingLevel)
+            (undo endUndoGrouping)
+            (undo beginUndoGrouping))
+        YES)
+
+    (- (void) createEmployee: (id) sender is
+        ; If a field is being edited, end editing
+        (unless (eq NO (self endEditing))
+            
+            (set p (@employeeController newObject))
+            (@employeeController addObject:p)
+            
+            ; In case the user has sorted the content array
+            (@employeeController rearrangeObjects)
+            
+            ; Find the row of the new object
+            (set a (@employeeController arrangedObjects))
+            (set row (a indexOfObjectIdenticalTo:p))
+            
+            ; Start editing in the first column
+            (@tableView editColumn:0 row:row withEvent:nil select:YES)))
         
     (- (void) startObservingPerson: (id) person is
-        (NSLog &quot;startObservingPerson: #{person}&quot;)
         (person addObserver:self
                  forKeyPath:&quot;personName&quot;
                     options:NSKeyValueObservingOptionOld
@@ -22,12 +62,10 @@
                     context:nil))
                     
     (- (void) stopObservingPerson: (id) person is
-        (NSLog &quot;stopObservingPerson: #{person}&quot;)
         (person removeObserver:self forKeyPath:&quot;personName&quot;)
         (person removeObserver:self forKeyPath:&quot;expectedRaise&quot;))
 
     (- (void) insertObject: (id) p inEmployeesAtIndex: (int) r is
-        (NSLog &quot;InsertObject: #{p} inEmployeesAtIndex: #{r}&quot;)
         ;; Register the undo
         (set undo (self undoManager))
         ((undo prepareWithInvocationTarget:self) 
@@ -39,7 +77,6 @@
         (@employees insertObject:p atIndex:r))
 
     (- (void) removeObjectFromEmployeesAtIndex: (int) r is
-        (NSLog &quot;removeObjectFromEmployeesAtIndex: #{r}&quot;)
         (set p (@employees r))
         (set undo (self undoManager))
         ((undo prepareWithInvocationTarget:self)
@@ -50,17 +87,30 @@
         (@employees removeObjectAtIndex:r))
 
     (- (void) setEmployees: (id) arr is
-        (NSLog &quot;setEmployees: #{arr}&quot;)
         (@employees each:(do (p) (self stopObservingPerson:p)))
         (set @employees arr)
         (@employees each:(do (p) (self startObservingPerson:p))))
 
     (- (void) changeKeyPath: (id) keyPath ofObject: (id) obj toValue:(id) newValue is
         (obj setValue:newValue forKeyPath:keyPath))
-            
-        )
-
+      
+    (- (void) observeValueForKeyPath: (id) keyPath ofObject: (id) obj
+                              change: (id) change context: (id) context is
+        (set undo (self undoManager))
+        (set oldValue (change objectForKey:NSKeyValueChangeOldKey))
+        (if (eq oldValue (NSNull null))
+            (set oldValue nil))
+        (NSLog &quot;oldValue = #{oldValue}&quot;)
+        ((undo prepareWithInvocationTarget:self)
+            changeKeyPath:keyPath ofObject:obj toValue:oldValue)
+        (undo setActionName:&quot;Edit&quot;))
 
+     (- (id) windowNibName is &quot;MyDocument&quot;)
+     
+     (- (void) windowControllerDidLoadNib: (id) aController is
+        (super windowControllerDidLoadNib:aController)
+        ;; Add any code here that needs to be executed once the windowController has loaded the document's window.
+        ))
 
 (set SHOW_CONSOLE_AT_STARTUP nil)
 </diff>
      <filename>09_Undo/RaiseMan_A/nu/main.nu</filename>
    </modified>
  </modified>
  <removed type="array">
    <removed>
      <filename>09_Undo/RaiseMan_A/MyDocument.h</filename>
    </removed>
    <removed>
      <filename>09_Undo/RaiseMan_A/MyDocument.m</filename>
    </removed>
    <removed>
      <filename>09_Undo/RaiseMan_A/Person.h</filename>
    </removed>
    <removed>
      <filename>09_Undo/RaiseMan_A/Person.m</filename>
    </removed>
  </removed>
  <parents type="array">
    <parent>
      <id>8abeb11a0e6919b7c1f2b1d1d044e16a8b10ba07</id>
    </parent>
  </parents>
  <author>
    <name>Jonathan Yedidia</name>
    <email>yedidia@merl.com</email>
  </author>
  <url>http://github.com/timburks/cocoa-programming-with-nu/commit/6c225a8c1cbed4a1e37b0ebb1491bcce5a756e83</url>
  <id>6c225a8c1cbed4a1e37b0ebb1491bcce5a756e83</id>
  <committed-date>2008-06-01T17:52:29-07:00</committed-date>
  <authored-date>2008-06-01T17:52:29-07:00</authored-date>
  <message>Completed conversion of 09_Undo.</message>
  <tree>c834717bcdf770f9cbadeb2b07ffd889eae578aa</tree>
  <committer>
    <name>Jonathan Yedidia</name>
    <email>yedidia@merl.com</email>
  </committer>
</commit>
