annotate lisp/oobr/tree-nx/TreeController.m @ 14:9ee227acff29 r19-15b90

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