public
Description: Examples from the new 3rd edition of Cocoa Programming for Mac OS X, ported to Nu
Homepage: http://programming.nu/posts/2008/05/23/cocoa-programming-with-nu
Clone URL: git://github.com/timburks/cocoa-programming-with-nu.git
Fixed mix-up between 09_Undo/RaiseMan_A and 09_Undo/RaiseMan_B.
jsyedidia (author)
Sun Jun 01 18:37:54 -0700 2008
commit  bdbfd5bcadb09b65615037693fd1ef34cf3adbfe
tree    a4c84c13069ed41f8762b15de9650b163289ec89
parent  6c225a8c1cbed4a1e37b0ebb1491bcce5a756e83
...
14
15
16
17
 
18
19
20
...
31
32
33
34
 
35
36
37
...
119
120
121
122
 
123
124
125
...
171
172
173
174
 
175
176
177
...
14
15
16
 
17
18
19
20
...
31
32
33
 
34
35
36
37
...
119
120
121
 
122
123
124
125
...
171
172
173
 
174
175
176
177
0
@@ -14,7 +14,7 @@
0
     8D15AC320486D014006FF6A4 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 2A37F4B0FDCFA73011CA2CEA /* main.m */; settings = {ATTRIBUTES = (); }; };
0
     8D15AC340486D014006FF6A4 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A7FEA54F5311CA2CBB /* Cocoa.framework */; };
0
     AB0670A50DED05BE00E0ABDA /* Nu.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AB0670A40DED05BE00E0ABDA /* Nu.framework */; };
0
- AB0670A70DED05E400E0ABDA /* main.nu in Resources */ = {isa = PBXBuildFile; fileRef = AB0670A60DED05E400E0ABDA /* main.nu */; };
0
+ AB9402F70DF385F400D31812 /* main.nu in Resources */ = {isa = PBXBuildFile; fileRef = AB9402F60DF385F400D31812 /* main.nu */; };
0
 /* End PBXBuildFile section */
0
 
0
 /* Begin PBXFileReference section */
0
@@ -31,7 +31,7 @@
0
     8D15AC360486D014006FF6A4 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
0
     8D15AC370486D014006FF6A4 /* RaiseMan.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = RaiseMan.app; sourceTree = BUILT_PRODUCTS_DIR; };
0
     AB0670A40DED05BE00E0ABDA /* Nu.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Nu.framework; path = /Library/Frameworks/Nu.framework; sourceTree = "<absolute>"; };
0
- AB0670A60DED05E400E0ABDA /* main.nu */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = main.nu; path = nu/main.nu; sourceTree = "<group>"; };
0
+ AB9402F60DF385F400D31812 /* main.nu */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = main.nu; path = nu/main.nu; sourceTree = "<group>"; };
0
 /* End PBXFileReference section */
0
 
0
 /* Begin PBXFrameworksBuildPhase section */
0
@@ -119,7 +119,7 @@
0
     AB0670A30DED05A900E0ABDA /* Nu */ = {
0
       isa = PBXGroup;
0
       children = (
0
- AB0670A60DED05E400E0ABDA /* main.nu */,
0
+ AB9402F60DF385F400D31812 /* main.nu */,
0
       );
0
       name = Nu;
0
       sourceTree = "<group>";
0
@@ -171,7 +171,7 @@
0
         8D15AC2D0486D014006FF6A4 /* MainMenu.nib in Resources */,
0
         8D15AC2E0486D014006FF6A4 /* MyDocument.nib in Resources */,
0
         8D15AC2F0486D014006FF6A4 /* InfoPlist.strings in Resources */,
0
- AB0670A70DED05E400E0ABDA /* main.nu in Resources */,
0
+ AB9402F70DF385F400D31812 /* main.nu in Resources */,
0
       );
0
       runOnlyForDeploymentPostprocessing = 0;
0
     };
...
17
18
19
20
 
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
...
17
18
19
 
20
21
22
23
24
25
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
27
28
0
@@ -17,39 +17,12 @@
0
             (else (super setNilValueForKey:key)))))
0
 
0
 (class MyDocument is NSDocument
0
- (ivar (id) employees (id) employeeController (id) tableView)
0
+ (ivar (id) employees)
0
     
0
     (- (id) init is
0
         (super init)
0
         (self setEmployees:(array))
0
         self)
0
-
0
- (- (BOOL) endEditing is
0
- (set w (@tableView window))
0
- (set editingEnded (w makeFirstResponder:w))
0
- (unless (editingEnded) NO)
0
- (set undo (self undoManager))
0
- (if (undo groupingLevel)
0
- (undo endUndoGrouping)
0
- (undo beginUndoGrouping))
0
- YES)
0
-
0
- (- (void) createEmployee: (id) sender is
0
- ; If a field is being edited, end editing
0
- (unless (eq NO (self endEditing))
0
-
0
- (set p (@employeeController newObject))
0
- (@employeeController addObject:p)
0
-
0
- ; In case the user has sorted the content array
0
- (@employeeController rearrangeObjects)
0
-
0
- ; Find the row of the new object
0
- (set a (@employeeController arrangedObjects))
0
- (set row (a indexOfObjectIdenticalTo:p))
0
-
0
- ; Start editing in the first column
0
- (@tableView editColumn:0 row:row withEvent:nil select:YES)))
0
         
0
     (- (void) startObservingPerson: (id) person is
0
         (person addObserver:self
...
14
15
16
17
 
18
19
20
...
31
32
33
34
 
35
36
37
...
119
120
121
122
 
123
124
125
...
171
172
173
174
 
175
176
177
...
14
15
16
 
17
18
19
20
...
31
32
33
 
34
35
36
37
...
119
120
121
 
122
123
124
125
...
171
172
173
 
174
175
176
177
0
@@ -14,7 +14,7 @@
0
     8D15AC320486D014006FF6A4 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 2A37F4B0FDCFA73011CA2CEA /* main.m */; settings = {ATTRIBUTES = (); }; };
0
     8D15AC340486D014006FF6A4 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A7FEA54F5311CA2CBB /* Cocoa.framework */; };
0
     AB1DE74D0DF37472008275EC /* Nu.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AB1DE74C0DF37472008275EC /* Nu.framework */; };
0
- AB1DE7510DF37490008275EC /* main.nu in Resources */ = {isa = PBXBuildFile; fileRef = AB1DE7500DF37490008275EC /* main.nu */; };
0
+ AB9403130DF3861600D31812 /* main.nu in Resources */ = {isa = PBXBuildFile; fileRef = AB9403120DF3861600D31812 /* main.nu */; };
0
 /* End PBXBuildFile section */
0
 
0
 /* Begin PBXFileReference section */
0
@@ -31,7 +31,7 @@
0
     8D15AC360486D014006FF6A4 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
0
     8D15AC370486D014006FF6A4 /* RaiseMan.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = RaiseMan.app; sourceTree = BUILT_PRODUCTS_DIR; };
0
     AB1DE74C0DF37472008275EC /* Nu.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Nu.framework; path = /Library/Frameworks/Nu.framework; sourceTree = "<absolute>"; };
0
- AB1DE7500DF37490008275EC /* main.nu */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = main.nu; path = ../RaiseMan_A/nu/main.nu; sourceTree = SOURCE_ROOT; };
0
+ AB9403120DF3861600D31812 /* main.nu */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = main.nu; path = nu/main.nu; sourceTree = "<group>"; };
0
 /* End PBXFileReference section */
0
 
0
 /* Begin PBXFrameworksBuildPhase section */
0
@@ -119,7 +119,7 @@
0
     AB1DE7480DF37461008275EC /* Nu */ = {
0
       isa = PBXGroup;
0
       children = (
0
- AB1DE7500DF37490008275EC /* main.nu */,
0
+ AB9403120DF3861600D31812 /* main.nu */,
0
       );
0
       name = Nu;
0
       sourceTree = "<group>";
0
@@ -171,7 +171,7 @@
0
         8D15AC2D0486D014006FF6A4 /* MainMenu.nib in Resources */,
0
         8D15AC2E0486D014006FF6A4 /* MyDocument.nib in Resources */,
0
         8D15AC2F0486D014006FF6A4 /* InfoPlist.strings in Resources */,
0
- AB1DE7510DF37490008275EC /* main.nu in Resources */,
0
+ AB9403130DF3861600D31812 /* main.nu in Resources */,
0
       );
0
       runOnlyForDeploymentPostprocessing = 0;
0
     };
...
17
18
19
20
 
21
22
23
24
25
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
27
28
...
17
18
19
 
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
0
@@ -17,12 +17,39 @@
0
             (else (super setNilValueForKey:key)))))
0
 
0
 (class MyDocument is NSDocument
0
- (ivar (id) employees)
0
+ (ivar (id) employees (id) employeeController (id) tableView)
0
     
0
     (- (id) init is
0
         (super init)
0
         (self setEmployees:(array))
0
         self)
0
+
0
+ (- (BOOL) endEditing is
0
+ (set w (@tableView window))
0
+ (set editingEnded (w makeFirstResponder:w))
0
+ (unless (editingEnded) NO)
0
+ (set undo (self undoManager))
0
+ (if (undo groupingLevel)
0
+ (undo endUndoGrouping)
0
+ (undo beginUndoGrouping))
0
+ YES)
0
+
0
+ (- (void) createEmployee: (id) sender is
0
+ ; If a field is being edited, end editing
0
+ (unless (eq NO (self endEditing))
0
+
0
+ (set p (@employeeController newObject))
0
+ (@employeeController addObject:p)
0
+
0
+ ; In case the user has sorted the content array
0
+ (@employeeController rearrangeObjects)
0
+
0
+ ; Find the row of the new object
0
+ (set a (@employeeController arrangedObjects))
0
+ (set row (a indexOfObjectIdenticalTo:p))
0
+
0
+ ; Start editing in the first column
0
+ (@tableView editColumn:0 row:row withEvent:nil select:YES)))
0
         
0
     (- (void) startObservingPerson: (id) person is
0
         (person addObserver:self

Comments

    No one has commented yet.