|
|
1.1 root 1: /* Controller.m:
2: * You may freely copy, distribute, and reuse the code in this example.
3: * NeXT disclaims any warranty of any kind, expressed or implied, as to its
4: * fitness for any particular use.
5: *
6: * Controller is providing the high level interface to the main menu commands
7: * like open, close, evaluate, and clear.
8: *
9: */
10:
11: #import<foundation/NSString.h>
12: #import <foundation/NSException.h>
13:
14: #import "Controller.h"
15: #import "Evaluator.h"
16:
17: void MyTopLevelErrorHandler(NXHandler *errorState);
18:
19: @implementation Controller
20:
21: #define DEFAULT_LIBRARY "Library/Models"
22:
23: - appDidInit:sender
24: {
25: NXSetTopLevelErrorHandler(MyTopLevelErrorHandler);
26:
27: [self open:sender];
28: return self;
29: }
30:
31: void MyTopLevelErrorHandler(NXHandler *errorState)
32: {
33: if (errorState->code >= NSExceptionBase &&
34: errorState->code <= NSLastException) {
35: NSException *exception = (id) errorState->data1;
36:
37: NSLog(@"%@: %@\n", [exception exceptionName], [exception exceptionReason]);
38: }
39: }
40:
41:
42: - open:sender
43: {
44: char **files;
45: char *path;
46: const char *directory;
47: const char *const types[] = { "eomodel", 0 };
48: id openPanel;
49:
50: openPanel = [OpenPanel new];
51: [openPanel allowMultipleFiles:YES];
52:
53: path = malloc((MAXPATHLEN +1)*sizeof(char));
54: sprintf(path, "%s/%s", getenv("HOME"), DEFAULT_LIBRARY);
55: if ([openPanel runModalForDirectory:path file:NULL types:types])
56: if ((files = (char **) [openPanel filenames]) != NULL)
57: {
58: directory = [openPanel directory];
59: for (; *files; ++files)
60: {
61: sprintf(path, "%s/%s", directory, *files);
62: [self openFileNamed:path];
63: }
64: }
65: free(path);
66: return self;
67: }
68:
69: - openFileNamed:(const char *)filename
70: {
71: return [[Evaluator alloc] initWithModelFile:
72: [[NSString alloc]initWithCString:filename]];
73: }
74:
75: - evaluate:sender
76: {
77: [[[NXApp mainWindow] delegate] evaluate:sender];
78: return self;
79: }
80:
81: - clear:sender
82: {
83: [[[NXApp mainWindow] delegate] clear:sender];
84: return self;
85: }
86:
87:
88: - close:sender
89: {
90: [[[NXApp mainWindow] delegate] close:sender];
91: return self;
92: }
93:
94: @end
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.