Move setting of ioready 'wait' earlier in call chain, to
[python/dscho.git] / Mac / OSX / PythonLauncher / MyDocument.m
blob09a0024d5e779ba2e8dd4075c56197ef35c3dbda
1 //
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 //
9 #import "MyDocument.h"
10 #import "MyAppDelegate.h"
11 #import "doscript.h"
13 @implementation MyDocument
15 - (id)init
17     self = [super init];
18     if (self) {
19     
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];
24         settings = NULL;
25     }
26     return self;
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.
33     return @"MyDocument";
36 - (void)close
38     NSApplication *app = [NSApplication sharedApplication];
39     [super close];
40     if ([[app delegate] shouldTerminate])
41         [app terminate: self];
44 - (void)load_defaults
46 //    if (settings) [settings release];
47     settings = [FileSettings newSettingsForFileType: filetype];
50 - (void)update_display
52 //    [[self window] setTitle: script];
53     
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     [with_terminal setState: [settings with_terminal]];
64     
65     [commandline setStringValue: [settings commandLineForScript: script]];
68 - (void)update_settings
70     [settings updateFromSource: self];
73 - (BOOL)run
75     const char *cmdline;
76     int sts;
77     
78      cmdline = [[settings commandLineForScript: script] cString];
79    if ([settings with_terminal]) {
80         sts = doscript(cmdline);
81     } else {
82         sts = system(cmdline);
83     }
84     if (sts) {
85         NSLog(@"Exit status: %d\n", sts);
86         return NO;
87     }
88     return YES;
91 - (void)windowControllerDidLoadNib:(NSWindowController *) aController
93     [super windowControllerDidLoadNib:aController];
94     // Add any code here that need to be executed once the windowController has loaded the document's window.
95     [self load_defaults];
96     [self update_display];
99 - (NSData *)dataRepresentationOfType:(NSString *)aType
101     // Insert code here to write your document from the given data.  You can also choose to override -fileWrapperRepresentationOfType: or -writeToFile:ofType: instead.
102     return nil;
105 - (BOOL)readFromFile:(NSString *)fileName ofType:(NSString *)type;
107     // Insert code here to read your document from the given data.  You can also choose to override -loadFileWrapperRepresentation:ofType: or -readFromFile:ofType: instead.
108     BOOL show_ui;
109     
110     // ask the app delegate whether we should show the UI or not. 
111     show_ui = [[[NSApplication sharedApplication] delegate] shouldShowUI];
112     [script release];
113     script = [fileName retain];
114     [filetype release];
115     filetype = [type retain];
116 //    if (settings) [settings release];
117     settings = [FileSettings newSettingsForFileType: filetype];
118     if (show_ui) {
119         [self update_display];
120         return YES;
121     } else {
122         [self run];
123         [self close];
124         return NO;
125     }
128 - (IBAction)do_run:(id)sender
130     [self update_settings];
131     [self update_display];
132     if ([self run])
133         [self close];
136 - (IBAction)do_cancel:(id)sender
138     [self close];
142 - (IBAction)do_reset:(id)sender
144     [settings reset];
145     [self update_display];
148 - (IBAction)do_apply:(id)sender
150     [self update_settings];
151     [self update_display];
154 // FileSettingsSource protocol 
155 - (NSString *) interpreter { return [interpreter stringValue];};
156 - (BOOL) honourhashbang { return [honourhashbang state];};
157 - (BOOL) debug { return [debug state];};
158 - (BOOL) verbose { return [verbose state];};
159 - (BOOL) inspect { return [inspect state];};
160 - (BOOL) optimize { return [optimize state];};
161 - (BOOL) nosite { return [nosite state];};
162 - (BOOL) tabs { return [tabs state];};
163 - (NSString *) others { return [others stringValue];};
164 - (BOOL) with_terminal { return [with_terminal state];};
166 // Delegates
167 - (void)controlTextDidChange:(NSNotification *)aNotification
169     [self update_settings];
170     [self update_display];
173 @end