blob: a4c20d1042db9d5c371e02c8f391e552e689f887 [file] [log] [blame]
Jack Jansen3bbb6172002-07-29 21:36:35 +00001//
2// MyDocument.m
3// PythonLauncher
4//
5// Created by Jack Jansen on Fri Jul 19 2002.
6// Copyright (c) 2002 __MyCompanyName__. All rights reserved.
7//
8
9#import "MyDocument.h"
10#import "MyAppDelegate.h"
11
12@implementation MyDocument
13
14- (id)init
15{
16 [super init];
17 if (self) {
18
19 // Add your subclass-specific initialization here.
20 // If an error occurs here, send a [self dealloc] message and return nil.
21 script = @"<no script>.py";
22 filetype = @"Python Script";
23 }
24 return self;
25}
26
27- (NSString *)windowNibName
28{
29 // Override returning the nib file name of the document
30 // If you need to use a subclass of NSWindowController or if your document supports multiple NSWindowControllers, you should remove this method and override -makeWindowControllers instead.
31 return @"MyDocument";
32}
33
34- (void)close
35{
36 NSApplication *app = [NSApplication sharedApplication];
37 [super close];
38 if ([[app delegate] shouldTerminate])
39 [app terminate: self];
40}
41
42- (void)load_defaults
43{
44 settings = [FileSettings newSettingsForFileType: filetype];
45}
46
47- (void)update_display
48{
49// [[self window] setTitle: script];
50
51 [interpreter setStringValue: [settings interpreter]];
52 [debug setState: [settings debug]];
53 [verbose setState: [settings verbose]];
54 [inspect setState: [settings inspect]];
55 [optimize setState: [settings optimize]];
56 [nosite setState: [settings nosite]];
57 [tabs setState: [settings tabs]];
58 [others setStringValue: [settings others]];
59 [with_terminal setState: [settings with_terminal]];
60
61 [commandline setStringValue: [settings commandLineForScript: script]];
62}
63
64- (void)update_settings
65{
66 [settings updateFromSource: self];
67}
68
69- (BOOL)run
70{
71 const char *cmdline;
72 int sts;
73
74 if ([settings with_terminal]) {
75 NSLog(@"Terminal not implemented yet\n");
76 return NO;
77 }
78 cmdline = [[settings commandLineForScript: script] cString];
79 sts = system(cmdline);
80 if (sts) {
81 NSLog(@"Exit status: %d\n", sts);
82 return NO;
83 }
84 return YES;
85}
86
87- (void)windowControllerDidLoadNib:(NSWindowController *) aController
88{
89 [super windowControllerDidLoadNib:aController];
90 // Add any code here that need to be executed once the windowController has loaded the document's window.
91 [self load_defaults];
92 [self update_display];
93}
94
95- (NSData *)dataRepresentationOfType:(NSString *)aType
96{
97 // Insert code here to write your document from the given data. You can also choose to override -fileWrapperRepresentationOfType: or -writeToFile:ofType: instead.
98 return nil;
99}
100
101- (BOOL)readFromFile:(NSString *)fileName ofType:(NSString *)type;
102{
103 // Insert code here to read your document from the given data. You can also choose to override -loadFileWrapperRepresentation:ofType: or -readFromFile:ofType: instead.
104 BOOL show_ui;
105
106 // ask the app delegate whether we should show the UI or not.
107 show_ui = [[[NSApplication sharedApplication] delegate] shouldShowUI];
108 script = [fileName retain];
109 filetype = [type retain];
110 settings = [FileSettings newSettingsForFileType: filetype];
111 if (show_ui) {
112 [self update_display];
113 return YES;
114 } else {
115 [self run];
116 [self close];
117 return NO;
118 }
119}
120
121- (IBAction)do_run:(id)sender
122{
123 [self update_settings];
124 [self update_display];
125 if ([self run])
126 [self close];
127}
128
129- (IBAction)do_cancel:(id)sender
130{
131 [self close];
132}
133
134
135- (IBAction)do_reset:(id)sender
136{
137 [self load_defaults];
138 [self update_display];
139}
140
141- (IBAction)do_apply:(id)sender
142{
143 [self update_settings];
144 [self update_display];
145}
146
147// FileSettingsSource protocol
148- (NSString *) interpreter { return [interpreter stringValue];};
149- (BOOL) debug { return [debug state];};
150- (BOOL) verbose { return [verbose state];};
151- (BOOL) inspect { return [inspect state];};
152- (BOOL) optimize { return [optimize state];};
153- (BOOL) nosite { return [nosite state];};
154- (BOOL) tabs { return [tabs state];};
155- (NSString *) others { return [others stringValue];};
156- (BOOL) with_terminal { return [with_terminal state];};
157
158// Delegates
159- (void)controlTextDidChange:(NSNotification *)aNotification
160{
161 [self update_settings];
162 [self update_display];
163};
164
165@end