Commit dde8b265 authored by Jack Jansen's avatar Jack Jansen

Lots of restructuring, mostly suggested by Bill Bumgarner. Main

externally visible difference is that the factory defaults are
now in a plist file in the bundle, in stead of being hard-coded in
the application.
parent 35405d4d
...@@ -37,17 +37,22 @@ ...@@ -37,17 +37,22 @@
} }
+ (id)getDefaultsForFileType: (NSString *)filetype; + (id)getDefaultsForFileType: (NSString *)filetype;
+ (id)getFactorySettingsForFileType: (NSString *)filetype;
+ (id)newSettingsForFileType: (NSString *)filetype; + (id)newSettingsForFileType: (NSString *)filetype;
- (id)init; //- (id)init;
- (id)initWithFileSettings: (FileSettings *)source; - (id)initForFileType: (NSString *)filetype;
- (id)initForFSDefaultFileType: (NSString *)filetype;
- (id)initForDefaultFileType: (NSString *)filetype;
//- (id)initWithFileSettings: (FileSettings *)source;
- (void)updateFromSource: (id <FileSettingsSource>)source; - (void)updateFromSource: (id <FileSettingsSource>)source;
- (NSString *)commandLineForScript: (NSString *)script; - (NSString *)commandLineForScript: (NSString *)script;
- (id)factorySettingsForFileType: (NSString *)filetype; //- (void)applyFactorySettingsForFileType: (NSString *)filetype;
- (void)saveDefaults; //- (void)saveDefaults;
- (void)updateFromUserDefaults: (NSString *)filetype; //- (void)applyUserDefaults: (NSString *)filetype;
- (void)applyValuesFromDict: (NSDictionary *)dict;
- (void)reset;
@end @end
...@@ -9,6 +9,29 @@ ...@@ -9,6 +9,29 @@
#import "FileSettings.h" #import "FileSettings.h"
@implementation FileSettings @implementation FileSettings
+ (id)getFactorySettingsForFileType: (NSString *)filetype
{
static FileSettings *fsdefault_py, *fsdefault_pyw, *fsdefault_pyc;
FileSettings **curdefault;
if ([filetype isEqualToString: @"Python Script"]) {
curdefault = &fsdefault_py;
} else if ([filetype isEqualToString: @"Python GUI Script"]) {
curdefault = &fsdefault_pyw;
} else if ([filetype isEqualToString: @"Python Bytecode Document"]) {
curdefault = &fsdefault_pyc;
} else {
NSLog(@"Funny File Type: %@\n", filetype);
curdefault = &fsdefault_py;
filetype = @"Python Script";
}
if (!*curdefault) {
*curdefault = [[FileSettings new] initForFSDefaultFileType: filetype];
}
return *curdefault;
}
+ (id)getDefaultsForFileType: (NSString *)filetype + (id)getDefaultsForFileType: (NSString *)filetype
{ {
static FileSettings *default_py, *default_pyw, *default_pyc; static FileSettings *default_py, *default_pyw, *default_pyc;
...@@ -26,9 +49,7 @@ ...@@ -26,9 +49,7 @@
filetype = @"Python Script"; filetype = @"Python Script";
} }
if (!*curdefault) { if (!*curdefault) {
*curdefault = [[FileSettings new] init]; *curdefault = [[FileSettings new] initForDefaultFileType: filetype];
[*curdefault factorySettingsForFileType: filetype];
[*curdefault updateFromUserDefaults: filetype];
} }
return *curdefault; return *curdefault;
} }
...@@ -37,42 +58,16 @@ ...@@ -37,42 +58,16 @@
{ {
FileSettings *cur; FileSettings *cur;
cur = [[FileSettings new] init]; cur = [FileSettings new];
[cur initWithFileSettings: [FileSettings getDefaultsForFileType: filetype]]; [cur initForFileType: filetype];
return cur; return [cur retain];
} }
- (id)init - (id)initWithFileSettings: (FileSettings *)source
{ {
self = [super init]; self = [super init];
return [self factorySettingsForFileType: @"Python Script"]; if (!self) return self;
}
- (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 = @"/Library/Frameworks/Python.framework/Versions/Current/bin/python";
with_terminal = YES;
} else if ([filetype isEqualToString: @"Python GUI Script"]) {
interpreter = @"/Library/Frameworks/Python.framework/Versions/Current/Resources/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]; interpreter = [source->interpreter retain];
debug = source->debug; debug = source->debug;
verbose = source->verbose; verbose = source->verbose;
...@@ -82,14 +77,106 @@ ...@@ -82,14 +77,106 @@
tabs = source->tabs; tabs = source->tabs;
others = [source->others retain]; others = [source->others retain];
with_terminal = source->with_terminal; with_terminal = source->with_terminal;
prefskey = source->prefskey;
if (prefskey) [prefskey retain];
return self;
}
- (id)initForFileType: (NSString *)filetype
{
FileSettings *defaults;
defaults = [FileSettings getDefaultsForFileType: filetype];
self = [self initWithFileSettings: defaults];
origsource = [defaults retain];
return self;
}
origsource = [source retain]; //- (id)init
//{
// self = [self initForFileType: @"Python Script"];
// return self;
//}
- (id)initForFSDefaultFileType: (NSString *)filetype
{
int i;
NSString *filename;
NSDictionary *dict;
NSArray *interpreters;
static NSDictionary *factorySettings;
self = [super init];
if (!self) return self;
if (factorySettings == NULL) {
NSBundle *bdl = [NSBundle mainBundle];
NSString *path = [ bdl pathForResource: @"factorySettings"
ofType: @"plist"];
factorySettings = [[NSDictionary dictionaryWithContentsOfFile:
path] retain];
if (factorySettings == NULL) {
NSLog(@"Missing %@", path);
return NULL;
}
}
dict = [factorySettings objectForKey: filetype];
if (dict == NULL) {
NSLog(@"factorySettings.plist misses file type \"%@\"", filetype);
interpreter = [@"no default found" retain];
return NULL;
}
[self applyValuesFromDict: dict];
interpreters = [dict objectForKey: @"interpreter_list"];
interpreter = NULL;
for (i=0; i < [interpreters count]; i++) {
filename = [interpreters objectAtIndex: i];
filename = [filename stringByExpandingTildeInPath];
if ([[NSFileManager defaultManager] fileExistsAtPath: filename]) {
interpreter = [filename retain];
break;
}
}
if (interpreter == NULL)
interpreter = [@"no default found" retain];
origsource = NULL;
return self; return self;
} }
- (void)saveDefaults - (void)applyUserDefaults: (NSString *)filetype
{ {
[origsource updateFromSource: self]; NSUserDefaults *defaults;
NSDictionary *dict;
defaults = [NSUserDefaults standardUserDefaults];
dict = [defaults dictionaryForKey: filetype];
if (!dict)
return;
[self applyValuesFromDict: dict];
}
- (id)initForDefaultFileType: (NSString *)filetype
{
FileSettings *fsdefaults;
fsdefaults = [FileSettings getFactorySettingsForFileType: filetype];
self = [self initWithFileSettings: fsdefaults];
if (!self) return self;
[self applyUserDefaults: filetype];
prefskey = [filetype retain];
return self;
}
- (void)reset
{
if (origsource) {
[self updateFromSource: origsource];
} else {
FileSettings *fsdefaults;
fsdefaults = [FileSettings getFactorySettingsForFileType: prefskey];
[self updateFromSource: fsdefaults];
}
} }
- (void)updateFromSource: (id <FileSettingsSource>)source - (void)updateFromSource: (id <FileSettingsSource>)source
...@@ -103,6 +190,8 @@ ...@@ -103,6 +190,8 @@
tabs = [source tabs]; tabs = [source tabs];
others = [[source others] retain]; others = [[source others] retain];
with_terminal = [source with_terminal]; with_terminal = [source with_terminal];
// And if this is a user defaults object we also save the
// values
if (!origsource) { if (!origsource) {
NSUserDefaults *defaults; NSUserDefaults *defaults;
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys: NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
...@@ -121,17 +210,10 @@ ...@@ -121,17 +210,10 @@
} }
} }
- (void)updateFromUserDefaults: (NSString *)filetype - (void)applyValuesFromDict: (NSDictionary *)dict
{ {
NSUserDefaults *defaults;
NSDictionary *dict;
id value; id value;
prefskey = [filetype retain];
defaults = [NSUserDefaults standardUserDefaults];
dict = [defaults dictionaryForKey: filetype];
if (!dict)
return;
value = [dict objectForKey: @"interpreter"]; value = [dict objectForKey: @"interpreter"];
if (value) interpreter = [value retain]; if (value) interpreter = [value retain];
value = [dict objectForKey: @"debug"]; value = [dict objectForKey: @"debug"];
......
...@@ -14,13 +14,14 @@ ...@@ -14,13 +14,14 @@
- (id)init - (id)init
{ {
[super init]; self = [super init];
if (self) { if (self) {
// Add your subclass-specific initialization here. // Add your subclass-specific initialization here.
// If an error occurs here, send a [self dealloc] message and return nil. // If an error occurs here, send a [self dealloc] message and return nil.
script = @"<no script>.py"; script = [@"<no script>.py" retain];
filetype = @"Python Script"; filetype = [@"Python Script" retain];
settings = NULL;
} }
return self; return self;
} }
...@@ -42,6 +43,7 @@ ...@@ -42,6 +43,7 @@
- (void)load_defaults - (void)load_defaults
{ {
// if (settings) [settings release];
settings = [FileSettings newSettingsForFileType: filetype]; settings = [FileSettings newSettingsForFileType: filetype];
} }
...@@ -106,8 +108,11 @@ ...@@ -106,8 +108,11 @@
// ask the app delegate whether we should show the UI or not. // ask the app delegate whether we should show the UI or not.
show_ui = [[[NSApplication sharedApplication] delegate] shouldShowUI]; show_ui = [[[NSApplication sharedApplication] delegate] shouldShowUI];
[script release];
script = [fileName retain]; script = [fileName retain];
[filetype release];
filetype = [type retain]; filetype = [type retain];
// if (settings) [settings release];
settings = [FileSettings newSettingsForFileType: filetype]; settings = [FileSettings newSettingsForFileType: filetype];
if (show_ui) { if (show_ui) {
[self update_display]; [self update_display];
...@@ -135,7 +140,7 @@ ...@@ -135,7 +140,7 @@
- (IBAction)do_reset:(id)sender - (IBAction)do_reset:(id)sender
{ {
[self load_defaults]; [settings reset];
[self update_display]; [self update_display];
} }
......
...@@ -62,7 +62,7 @@ ...@@ -62,7 +62,7 @@
- (IBAction)do_reset:(id)sender - (IBAction)do_reset:(id)sender
{ {
[self load_defaults]; [settings reset];
[self update_display]; [self update_display];
} }
......
...@@ -235,6 +235,7 @@ ...@@ -235,6 +235,7 @@
2A37F4B4FDCFA73011CA2CEA, 2A37F4B4FDCFA73011CA2CEA,
F5A4C13E02F203F601000102, F5A4C13E02F203F601000102,
089C165FFE840EACC02AAC07, 089C165FFE840EACC02AAC07,
F5A42167038BDD8E0110C447,
); );
isa = PBXGroup; isa = PBXGroup;
name = Resources; name = Resources;
...@@ -291,6 +292,7 @@ ...@@ -291,6 +292,7 @@
INSTALL_MODE_FLAG = "a+rX"; INSTALL_MODE_FLAG = "a+rX";
INSTALL_PATH = /Applications/Python; INSTALL_PATH = /Applications/Python;
LIBRARY_SEARCH_PATHS = ""; LIBRARY_SEARCH_PATHS = "";
OPTIMIZATION_CFLAGS = "-O0";
OTHER_LDFLAGS = ""; OTHER_LDFLAGS = "";
PRODUCT_NAME = PythonLauncher; PRODUCT_NAME = PythonLauncher;
SECTORDER_FLAGS = ""; SECTORDER_FLAGS = "";
...@@ -430,6 +432,7 @@ ...@@ -430,6 +432,7 @@
F58D4A3F02F1F94B01000102, F58D4A3F02F1F94B01000102,
F5A4C13F02F203F701000102, F5A4C13F02F203F701000102,
F5449B4C02FB3F7E01000102, F5449B4C02FB3F7E01000102,
F5A42168038BDD8E0110C447,
); );
isa = PBXResourcesBuildPhase; isa = PBXResourcesBuildPhase;
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
...@@ -577,6 +580,17 @@ ...@@ -577,6 +580,17 @@
settings = { settings = {
}; };
}; };
F5A42167038BDD8E0110C447 = {
isa = PBXFileReference;
path = factorySettings.plist;
refType = 4;
};
F5A42168038BDD8E0110C447 = {
fileRef = F5A42167038BDD8E0110C447;
isa = PBXBuildFile;
settings = {
};
};
F5A4C13E02F203F601000102 = { F5A4C13E02F203F601000102 = {
isa = PBXFileReference; isa = PBXFileReference;
path = PreferenceWindow.nib; path = PreferenceWindow.nib;
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Python GUI Script</key>
<dict>
<key>debug</key>
<false/>
<key>inspect</key>
<false/>
<key>interpreter_list</key>
<array>
<string>/usr/local/bin/pythonw</string>
<string>/sw/bin/pythonw</string>
<string>/Library/Frameworks/Python.framework/Versions/Current/Resources/Python.app/Contents/MacOS/python</string>
<string>/usr/bin/pythonw</string>
<string>/Applications/MacPython-OSX/python-additions/Python.app/Contents/MacOS/python</string>
</array>
<key>nosite</key>
<false/>
<key>optimize</key>
<false/>
<key>others</key>
<string></string>
<key>verbose</key>
<false/>
<key>with_terminal</key>
<false/>
</dict>
<key>Python Script</key>
<dict>
<key>debug</key>
<false/>
<key>inspect</key>
<false/>
<key>interpreter_list</key>
<array>
<string>/usr/local/bin/python</string>
<string>/sw/bin/python</string>
<string>/Library/Frameworks/Python.framework/Versions/Current/bin/python</string>
<string>/usr/bin/python</string>
</array>
<key>nosite</key>
<false/>
<key>optimize</key>
<false/>
<key>others</key>
<string></string>
<key>verbose</key>
<false/>
<key>with_terminal</key>
<true/>
</dict>
<key>Python Bytecode Document</key>
<dict>
<key>debug</key>
<false/>
<key>inspect</key>
<false/>
<key>interpreter_list</key>
<array>
<string>/usr/local/bin/python</string>
<string>/sw/bin/python</string>
<string>/Library/Frameworks/Python.framework/Versions/Current/bin/python</string>
<string>/usr/bin/python</string>
</array>
<key>nosite</key>
<false/>
<key>optimize</key>
<false/>
<key>others</key>
<string></string>
<key>verbose</key>
<false/>
<key>with_terminal</key>
<true/>
</dict>
</dict>
</plist>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment