5 // Created by Jack Jansen on Fri Jul 19 2002.
6 // Copyright (c) 2002 __MyCompanyName__. All rights reserved.
10 #import "MyAppDelegate.h"
13 @implementation MyDocument
20 // Add your subclass-specific initialization here.
21 // If an error occurs here, send a [self dealloc] message and return nil.
22 script = [@"<no script>.py" retain];
23 filetype = [@"Python Script" retain];
29 - (NSString *)windowNibName
31 // Override returning the nib file name of the document
32 // 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.
38 NSApplication *app = [NSApplication sharedApplication];
40 if ([[app delegate] shouldTerminate])
41 [app terminate: self];
46 // if (settings) [settings release];
47 settings = [FileSettings newSettingsForFileType: filetype];
50 - (void)update_display
52 // [[self window] setTitle: script];
54 [interpreter setStringValue: [settings interpreter]];
55 [honourhashbang setState: [settings honourhashbang]];
56 [debug setState: [settings debug]];
57 [verbose setState: [settings verbose]];
58 [inspect setState: [settings inspect]];
59 [optimize setState: [settings optimize]];
60 [nosite setState: [settings nosite]];
61 [tabs setState: [settings tabs]];
62 [others setStringValue: [settings others]];
63 [scriptargs setStringValue: [settings scriptargs]];
64 [with_terminal setState: [settings with_terminal]];
66 [commandline setStringValue: [settings commandLineForScript: script]];
69 - (void)update_settings
71 [settings updateFromSource: self];
79 cmdline = [[settings commandLineForScript: script] cString];
80 if ([settings with_terminal]) {
81 sts = doscript(cmdline);
83 sts = system(cmdline);
86 NSLog(@"Exit status: %d\n", sts);
92 - (void)windowControllerDidLoadNib:(NSWindowController *) aController
94 [super windowControllerDidLoadNib:aController];
95 // Add any code here that need to be executed once the windowController has loaded the document's window.
97 [self update_display];
100 - (NSData *)dataRepresentationOfType:(NSString *)aType
102 // Insert code here to write your document from the given data. You can also choose to override -fileWrapperRepresentationOfType: or -writeToFile:ofType: instead.
106 - (BOOL)readFromFile:(NSString *)fileName ofType:(NSString *)type;
108 // Insert code here to read your document from the given data. You can also choose to override -loadFileWrapperRepresentation:ofType: or -readFromFile:ofType: instead.
111 // ask the app delegate whether we should show the UI or not.
112 show_ui = [[[NSApplication sharedApplication] delegate] shouldShowUI];
114 script = [fileName retain];
116 filetype = [type retain];
117 // if (settings) [settings release];
118 settings = [FileSettings newSettingsForFileType: filetype];
120 [self update_display];
124 [self performSelector:@selector(close) withObject:nil afterDelay:0.0];
129 - (IBAction)do_run:(id)sender
131 [self update_settings];
132 [self update_display];
137 - (IBAction)do_cancel:(id)sender
143 - (IBAction)do_reset:(id)sender
146 [self update_display];
149 - (IBAction)do_apply:(id)sender
151 [self update_settings];
152 [self update_display];
155 // FileSettingsSource protocol
156 - (NSString *) interpreter { return [interpreter stringValue];};
157 - (BOOL) honourhashbang { return [honourhashbang state];};
158 - (BOOL) debug { return [debug state];};
159 - (BOOL) verbose { return [verbose state];};
160 - (BOOL) inspect { return [inspect state];};
161 - (BOOL) optimize { return [optimize state];};
162 - (BOOL) nosite { return [nosite state];};
163 - (BOOL) tabs { return [tabs state];};
164 - (NSString *) others { return [others stringValue];};
165 - (NSString *) scriptargs { return [scriptargs stringValue];};
166 - (BOOL) with_terminal { return [with_terminal state];};
169 - (void)controlTextDidChange:(NSNotification *)aNotification
171 [self update_settings];
172 [self update_display];