1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
|
//
// FileSettings.m
// PythonLauncher
//
// Created by Jack Jansen on Sun Jul 21 2002.
// Copyright (c) 2002 __MyCompanyName__. All rights reserved.
//
#import "FileSettings.h"
@implementation FileSettings
+ (id)getDefaultsForFileType: (NSString *)filetype
{
static FileSettings *default_py, *default_pyw, *default_pyc;
FileSettings **curdefault;
if ([filetype isEqualToString: @"Python Script"]) {
curdefault = &default_py;
} else if ([filetype isEqualToString: @"Python GUI Script"]) {
curdefault = &default_pyw;
} else if ([filetype isEqualToString: @"Python Bytecode Document"]) {
curdefault = &default_pyc;
} else {
NSLog(@"Funny File Type: %@\n", filetype);
curdefault = &default_py;
filetype = @"Python Script";
}
if (!*curdefault) {
*curdefault = [[FileSettings new] init];
[*curdefault factorySettingsForFileType: filetype];
[*curdefault updateFromUserDefaults: filetype];
}
return *curdefault;
}
+ (id)newSettingsForFileType: (NSString *)filetype
{
FileSettings *cur;
cur = [[FileSettings new] init];
[cur initWithFileSettings: [FileSettings getDefaultsForFileType: filetype]];
return cur;
}
- (id)init
{
self = [super init];
return [self factorySettingsForFileType: @"Python Script"];
}
- (id)factorySettingsForFileType: (NSString *)filetype
{
debug = NO;
verbose = NO;
inspect = NO;
optimize = NO;
nosite = NO;
tabs = NO;
others = @"";
if ([filetype isEqualToString: @"Python Script"] ||
[filetype isEqualToString: @"Python Bytecode Document"]) {
interpreter = @"/usr/local/bin/python";
with_terminal = YES;
} else if ([filetype isEqualToString: @"Python GUI Script"]) {
interpreter = @"/Applications/Python.app/Contents/MacOS/python";
with_terminal = NO;
} else {
NSLog(@"Funny File Type: %@\n", filetype);
}
origsource = NULL;
return self;
}
- (id)initWithFileSettings: (FileSettings *)source
{
interpreter = [source->interpreter retain];
debug = source->debug;
verbose = source->verbose;
inspect = source->inspect;
optimize = source->optimize;
nosite = source->nosite;
tabs = source->tabs;
others = [source->others retain];
with_terminal = source->with_terminal;
origsource = [source retain];
return self;
}
- (void)saveDefaults
{
[origsource updateFromSource: self];
}
- (void)updateFromSource: (id <FileSettingsSource>)source
{
interpreter = [[source interpreter] retain];
debug = [source debug];
verbose = [source verbose];
inspect = [source inspect];
optimize = [source optimize];
nosite = [source nosite];
tabs = [source tabs];
others = [[source others] retain];
with_terminal = [source with_terminal];
if (!origsource) {
NSUserDefaults *defaults;
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
interpreter, @"interpreter",
[NSNumber numberWithBool: debug], @"debug",
[NSNumber numberWithBool: verbose], @"verbose",
[NSNumber numberWithBool: inspect], @"inspect",
[NSNumber numberWithBool: optimize], @"optimize",
[NSNumber numberWithBool: nosite], @"nosite",
[NSNumber numberWithBool: nosite], @"nosite",
others, @"others",
[NSNumber numberWithBool: with_terminal], @"with_terminal",
nil];
defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject: dict forKey: prefskey];
}
}
- (void)updateFromUserDefaults: (NSString *)filetype
{
NSUserDefaults *defaults;
NSDictionary *dict;
id value;
prefskey = [filetype retain];
defaults = [NSUserDefaults standardUserDefaults];
dict = [defaults dictionaryForKey: filetype];
if (!dict)
return;
value = [dict objectForKey: @"interpreter"];
if (value) interpreter = [value retain];
value = [dict objectForKey: @"debug"];
if (value) debug = [value boolValue];
value = [dict objectForKey: @"verbose"];
if (value) verbose = [value boolValue];
value = [dict objectForKey: @"inspect"];
if (value) inspect = [value boolValue];
value = [dict objectForKey: @"optimize"];
if (value) optimize = [value boolValue];
value = [dict objectForKey: @"nosite"];
if (value) nosite = [value boolValue];
value = [dict objectForKey: @"nosite"];
if (value) tabs = [value boolValue];
value = [dict objectForKey: @"others"];
if (value) others = [value retain];
value = [dict objectForKey: @"with_terminal"];
if (value) with_terminal = [value boolValue];
}
- (NSString *)commandLineForScript: (NSString *)script
{
return [NSString stringWithFormat:
@"\"%@\"%s%s%s%s%s%s %@ \"%@\" %s",
interpreter,
debug?" -d":"",
verbose?" -v":"",
inspect?" -i":"",
optimize?" -O":"",
nosite?" -S":"",
tabs?" -t":"",
others,
script,
with_terminal? "" : " &"];
}
// FileSettingsSource protocol
- (NSString *) interpreter { return interpreter;};
- (BOOL) debug { return debug;};
- (BOOL) verbose { return verbose;};
- (BOOL) inspect { return inspect;};
- (BOOL) optimize { return optimize;};
- (BOOL) nosite { return nosite;};
- (BOOL) tabs { return tabs;};
- (NSString *) others { return others;};
- (BOOL) with_terminal { return with_terminal;};
@end
|