annotate pkg-src/tree-nx/TreeController.m @ 204:a15e4b3d59c6

Added tag r20-3b28 for changeset 850242ba4a81
author cvs
date Mon, 13 Aug 2007 10:02:23 +0200
parents 0132846995bd
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2 #import <stdio.h>
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4 #import "TreeController.h"
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
5 #import "NamedTree.h"
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
6 #import "TreeView.h"
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
7
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
8 @implementation TreeController
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
9
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
10 - appDidInit:(Application *)sender
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
11 {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
12 BOOL haveOpenedDocument = NO; // whether we have opened a document
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
13
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
14 // // Gets the public port for SomeApp
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
15 // port_t thePort = NXPortFromName("Emacs", NULL);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
16 //
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
17 // if (thePort != PORT_NULL)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
18 // // Sets the Speaker to send its next message to SomeApp's port
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
19 // [[NXApp appSpeaker] setSendPort:thePort];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
20
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
21 if (NXArgc > 1)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
22 {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
23 int i;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
24
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
25 for (i = 1; i < NXArgc; i++)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
26 {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
27 haveOpenedDocument = [self openFile: NXArgv[i]] || haveOpenedDocument;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
28 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
29 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
30
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
31 return self;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
32 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
33
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
34 - init
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
35 {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
36 [super init];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
37 first = YES;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
38 nextX = 200;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
39 nextY = 600;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
40 return self;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
41 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
42
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
43 - info:sender // bring up the info panel, obviously
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
44 {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
45 if(!infoPanel)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
46 [NXApp loadNibSection:"InfoPanel.nib" owner:self withNames:NO];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
47 return [infoPanel orderFront:sender];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
48 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
49
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
50 - open:sender
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
51 { // use open panel to select a file -- only with .tree extension.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
52 // only one file may be loaded at a time.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
53 const char *const *files;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
54 char *file;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
55 const char *dir;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
56 static const char *const ft[2] = {"tree", NULL};
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
57
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
58 id openPanel = [OpenPanel new];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
59 [openPanel allowMultipleFiles:NO];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
60 if (first) {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
61 [openPanel runModalForDirectory:[[NXBundle mainBundle] directory]
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
62 file:NULL types:ft];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
63 first = NO;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
64 } else [openPanel runModalForTypes:ft];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
65 files = [openPanel filenames];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
66 dir = [openPanel directory];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
67 file = malloc(strlen(files[0]) + strlen(dir) + 8);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
68 strcpy(file, dir);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
69 strcat(file,"/");
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
70 strcat(file, files[0]);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
71 strcat(file, "\0");
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
72 [self openFile:file];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
73 return self;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
74 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
75
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
76 char nextChar; // This allows me to do single character lookahead in scan
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
77
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
78 id readToNewline(FILE *file) // used to parse a file; reads until a newline
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
79 { // returns a string object... reads until EOL to get string value.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
80 id newString = [[String alloc] init];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
81 char *buffer = (char *)malloc(1024); // should be plenty big
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
82 char *spot = buffer;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
83
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
84 while (nextChar != '\n')
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
85 {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
86 spot[0] = nextChar; spot++; nextChar = fgetc(file);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
87 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
88 spot[0] = '\0'; // terminate the string
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
89 nextChar = fgetc(file); // Get next char for next invocation of this function
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
90 [newString setString:buffer];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
91 free(buffer);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
92 return newString;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
93 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
94
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
95 char prevChar; // This allows me to do single character lookback in scan
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
96
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
97 id readToSep(FILE *file) // used to parse a file; reads until a newline or a "^^" sequence
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
98 { // returns a string object... reads until EOL to get string value.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
99 id newString = [[String alloc] init];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
100 char *buffer = (char *)malloc(1024); // should be plenty big
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
101 char *spot = buffer;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
102 int c;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
103
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
104 while (nextChar != '\n')
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
105 {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
106 if (nextChar == '^')
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
107 if ((c = fgetc(file)) == '^')
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
108 break;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
109 else
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
110 ungetc(c, file);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
111 spot[0] = nextChar; spot++; nextChar = fgetc(file);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
112 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
113 spot[0] = '\0'; // terminate the string
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
114 prevChar = nextChar;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
115 nextChar = fgetc(file); // Get next char for next invocation of this function
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
116 [newString setString:buffer];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
117 free(buffer);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
118 return newString;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
119 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
120
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
121 // This actually opens a file. WorkSpace and Open panel methods both
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
122 // eventually get to here to do the real work. This code is pretty much
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
123 // worth ignoring, unless you _really_ care about how I read in the
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
124 // files. It's mostly specific to the file format so it's not
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
125 // generally useful. The framework for this code came from the
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
126 // code in my "Viewer.app" that is in with some PD raytracers I ported
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
127 // to the NeXT--allows viewing an rgb bitmap file; I wrote it before
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
128 // GW and ImageViewer existed... (See raytracers.tar.Z on sonata/orst)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
129 - (BOOL)openFile:(const char *)name
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
130 {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
131 // id alert;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
132 id aString, treeName, rootNode, workingNode, tempNode;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
133 id newString, stack = [[List alloc] init];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
134 int indLevel, numSpaces, indent = 0;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
135 char *tempString;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
136 BOOL rStat = YES;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
137 FILE *file;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
138 // for debugging:
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
139 //NXStream *out = NXOpenFile(fileno(stdout), NX_WRITEONLY);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
140
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
141 // get a new doc window.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
142 [NXApp loadNibSection:"DocWindow.nib" owner:self withNames:NO];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
143 [[treeView window] setTitleAsFilename:name];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
144 // put up an alert panel to let user know we're busy
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
145 // alert = NXGetAlertPanel(NULL, "Reading tree and creating image.",
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
146 // NULL, NULL, NULL);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
147 // [alert makeKeyAndOrderFront:self];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
148 // Read the tree file. NOTE THAT THIS DOES NOT DO ERROR CHECKING.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
149 file = fopen(name, "r");
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
150 nextChar = fgetc(file); // prime the system
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
151 treeName = readToNewline(file); // first line is tree's name
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
152 aString = readToSep(file); // Get the name of the root node.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
153 rootNode = [[[NamedTree alloc]
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
154 initLabelString:aString] setTreeName:treeName];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
155 if (prevChar != '\n')
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
156 [rootNode setValue: readToSep(file)]; // Set the node's value.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
157 [stack insertObject:rootNode at:0];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
158 workingNode = rootNode;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
159 // figure out the indentation
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
160 while (nextChar == ' ') {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
161 indent++;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
162 nextChar = fgetc(file);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
163 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
164 aString = readToSep(file); // get name of child node
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
165 tempNode = [[[NamedTree alloc]
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
166 initLabelString:aString] setTreeName:treeName];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
167 if (prevChar != '\n')
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
168 [tempNode setValue: readToSep(file)]; // Set the node's value.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
169 [workingNode addBranch:tempNode];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
170 [stack insertObject:tempNode at:0];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
171 workingNode = tempNode;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
172 // now that we know the file's char's, we read in the other nodes
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
173 // I use a List object as if it were a stack and push parent nodes on
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
174 // it while working on children rather than doing a recursive function.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
175 // the comments are sparse, just know that it's mostly pushing and
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
176 // popping from the stack to get at the right parent to add a child to.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
177 while (!feof(file)) {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
178 aString = readToSep(file); // next node name + indentation.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
179 // find out # of indentation spaces and strip them off
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
180 // *** This gives a warning: ignore it, it's unimportant here.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
181 tempString = [aString stringValue]; numSpaces = 0;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
182 while (tempString[0] == ' ') {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
183 numSpaces++; tempString++;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
184 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
185 indLevel = numSpaces / indent;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
186 if (indLevel == ([stack count] - 1)) // same level as last object
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
187 {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
188 [stack removeObjectAt:0];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
189 workingNode = [stack objectAt:0];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
190 newString = [[String alloc] initString:tempString];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
191 [aString free];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
192 tempNode = [[[NamedTree alloc]
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
193 initLabelString:newString] setTreeName:treeName];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
194 if (prevChar != '\n')
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
195 [tempNode setValue: readToSep(file)]; // Set the node's value.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
196 [workingNode addBranch:tempNode];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
197 [stack insertObject:tempNode at:0];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
198 workingNode = tempNode;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
199 } else if (indLevel == ([stack count])) { // child of last node
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
200 newString = [[String alloc] initString:tempString];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
201 [aString free];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
202 tempNode = [[[NamedTree alloc]
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
203 initLabelString:newString] setTreeName:treeName];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
204 if (prevChar != '\n')
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
205 [tempNode setValue: readToSep(file)]; // Set the node's value.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
206 [workingNode addBranch:tempNode];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
207 [stack insertObject:tempNode at:0];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
208 workingNode = tempNode;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
209 } else if (indLevel < [stack count]) { // higher level, so pop
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
210 while (indLevel < [stack count]) { // pop until at right level
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
211 [stack removeObjectAt:0];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
212 workingNode = [stack objectAt:0];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
213 } // now add new node since we're at the level
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
214 newString = [[String alloc] initString:tempString];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
215 [aString free];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
216 tempNode = [[[NamedTree alloc]
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
217 initLabelString:newString] setTreeName:treeName];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
218 if (prevChar != '\n')
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
219 [tempNode setValue: readToSep(file)]; // Set the node's value.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
220 [workingNode addBranch:tempNode];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
221 [stack insertObject:tempNode at:0];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
222 workingNode = tempNode;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
223 } else { // typically, if user goes in two levels at once, which
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
224 // doesn't make any sense semantically
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
225 fprintf(stderr, "Error: level too deep!\n");
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
226 rStat = NO;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
227 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
228 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
229 // Debugging code to pretty print the parsed tree. If this output
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
230 // is correct, then we know that the parse was OK.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
231 //printf("\nHere's the parsed tree:\n");
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
232 //printf("Tree name: \"%s\".", [treeName stringValue]);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
233 //[rootNode dumpTree:out level:0 indent:" "];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
234 //printf("\n\n");
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
235 //NXClose(out);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
236 // end debug code
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
237 // rStat = return status of tree reader YES = success
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
238 // Now attach the Tree to the TreeView...
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
239 [treeView attachTree:rootNode];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
240 // and now bring up the window for the user
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
241 [[treeView window] moveTo:nextX :(nextY-218)];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
242 // Get rid of the alert
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
243 // [alert orderOut:self];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
244 // [alert free];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
245 nextX += 22; nextY -= 25;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
246 if (nextX > 370)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
247 {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
248 nextX = 200; nextY = 600;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
249 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
250 [[treeView window] makeKeyAndOrderFront:self];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
251 return rStat;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
252 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
253
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
254
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
255 // The next two methods allow the WorkSpace to open a .tree file when
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
256 // it is double-clicked. (Or any file that's cmd-dragged over our icon.)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
257
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
258 - (BOOL)appAcceptsAnotherFile:sender { return YES; }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
259 - (int)app:sender openFile:(const char *)file type:(const char *)type
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
260 {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
261 return [self openFile:file];
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
262 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
263
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
264
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
265 @end