]> granicus.if.org Git - python/commitdiff
Lots of restructuring, mostly suggested by Bill Bumgarner. Main
authorJack Jansen <jack.jansen@cwi.nl>
Mon, 25 Nov 2002 13:11:06 +0000 (13:11 +0000)
committerJack Jansen <jack.jansen@cwi.nl>
Mon, 25 Nov 2002 13:11:06 +0000 (13:11 +0000)
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.

Mac/OSX/PythonLauncher/FileSettings.h
Mac/OSX/PythonLauncher/FileSettings.m
Mac/OSX/PythonLauncher/MyDocument.m
Mac/OSX/PythonLauncher/PreferencesWindowController.m
Mac/OSX/PythonLauncher/PythonLauncher.pbproj/project.pbxproj
Mac/OSX/PythonLauncher/factorySettings.plist [new file with mode: 0644]

index f487469c73305ffa4674c2f88776827ca001ce36..ea69b58bb19201d41f5d0ab986d0172170e53b19 100755 (executable)
 }
 
 + (id)getDefaultsForFileType: (NSString *)filetype;
++ (id)getFactorySettingsForFileType: (NSString *)filetype;
 + (id)newSettingsForFileType: (NSString *)filetype;
 
-- (id)init;
-- (id)initWithFileSettings: (FileSettings *)source;
+//- (id)init;
+- (id)initForFileType: (NSString *)filetype;
+- (id)initForFSDefaultFileType: (NSString *)filetype;
+- (id)initForDefaultFileType: (NSString *)filetype;
+//- (id)initWithFileSettings: (FileSettings *)source;
 
 - (void)updateFromSource: (id <FileSettingsSource>)source;
 - (NSString *)commandLineForScript: (NSString *)script;
 
-- (id)factorySettingsForFileType: (NSString *)filetype;
-- (void)saveDefaults;
-- (void)updateFromUserDefaults: (NSString *)filetype;
-
+//- (void)applyFactorySettingsForFileType: (NSString *)filetype;
+//- (void)saveDefaults;
+//- (void)applyUserDefaults: (NSString *)filetype;
+- (void)applyValuesFromDict: (NSDictionary *)dict;
+- (void)reset;
 
 @end
index 2147004c61aa3a8a407a920c8f24e676f527f730..89772f66b9929b59257d8e7a29f17519ebf941c8 100755 (executable)
@@ -9,6 +9,29 @@
 #import "FileSettings.h"
 
 @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
 {
     static FileSettings *default_py, *default_pyw, *default_pyc;
@@ -26,9 +49,7 @@
         filetype = @"Python Script";
     }
     if (!*curdefault) {
-        *curdefault = [[FileSettings new] init];
-        [*curdefault factorySettingsForFileType: filetype];
-        [*curdefault updateFromUserDefaults: filetype];
+        *curdefault = [[FileSettings new] initForDefaultFileType: filetype];
     }
     return *curdefault;
 }
 {
     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 = @"/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;
+    cur = [FileSettings new];
+    [cur initForFileType: filetype];
+    return [cur retain];
 }
 
 - (id)initWithFileSettings: (FileSettings *)source
 {
+    self = [super init];
+    if (!self) return self;
+    
     interpreter = [source->interpreter retain];
     debug = source->debug;
     verbose = source->verbose;
     tabs = source->tabs;
     others = [source->others retain];
     with_terminal = source->with_terminal;
+    prefskey = source->prefskey;
+    if (prefskey) [prefskey retain];
     
-    origsource = [source retain];
     return self;
 }
 
-- (void)saveDefaults
+- (id)initForFileType: (NSString *)filetype
 {
-    [origsource updateFromSource: self];
+    FileSettings *defaults;
+    
+    defaults = [FileSettings getDefaultsForFileType: filetype];
+    self = [self initWithFileSettings: defaults];
+    origsource = [defaults retain];
+    return self;
+}
+
+//- (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;
+}
+
+- (void)applyUserDefaults: (NSString *)filetype
+{
+    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
     tabs = [source tabs];
     others = [[source others] retain];
     with_terminal = [source with_terminal];
+    // And if this is a user defaults object we also save the
+    // values
     if (!origsource) {
         NSUserDefaults *defaults;
         NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
     }
 }
 
-- (void)updateFromUserDefaults: (NSString *)filetype
+- (void)applyValuesFromDict: (NSDictionary *)dict
 {
-    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"];
index 25718570b9e39f9b5ed6fc1391d58b7ea3c9dafa..fdcf86a6d5a7003c0b23d550a28331443d1dbe94 100755 (executable)
 
 - (id)init
 {
-    [super init];
+    self = [super init];
     if (self) {
     
         // Add your subclass-specific initialization here.
         // If an error occurs here, send a [self dealloc] message and return nil.
-        script = @"<no script>.py";
-        filetype = @"Python Script";    
+        script = [@"<no script>.py" retain];
+        filetype = [@"Python Script" retain];
+        settings = NULL;
     }
     return self;
 }
@@ -42,6 +43,7 @@
 
 - (void)load_defaults
 {
+//    if (settings) [settings release];
     settings = [FileSettings newSettingsForFileType: filetype];
 }
 
     
     // ask the app delegate whether we should show the UI or not. 
     show_ui = [[[NSApplication sharedApplication] delegate] shouldShowUI];
+    [script release];
     script = [fileName retain];
+    [filetype release];
     filetype = [type retain];
+//    if (settings) [settings release];
     settings = [FileSettings newSettingsForFileType: filetype];
     if (show_ui) {
         [self update_display];
 
 - (IBAction)do_reset:(id)sender
 {
-    [self load_defaults];
+    [settings reset];
     [self update_display];
 }
 
index 88421627bba01aa44e0e2035a19c6c007e3db958..79344f6a4d04eafc955528f7638e8d4f91223072 100644 (file)
@@ -62,7 +62,7 @@
 
 - (IBAction)do_reset:(id)sender
 {
-    [self load_defaults];
+    [settings reset];
     [self update_display];
 }
 
index 063339c2db679d9fabd39394a0550529ff947909..93bd1ead6b0ba29b641bdacd19d0cdfba06511de 100755 (executable)
                                2A37F4B4FDCFA73011CA2CEA,
                                F5A4C13E02F203F601000102,
                                089C165FFE840EACC02AAC07,
+                               F5A42167038BDD8E0110C447,
                        );
                        isa = PBXGroup;
                        name = Resources;
                                INSTALL_MODE_FLAG = "a+rX";
                                INSTALL_PATH = /Applications/Python;
                                LIBRARY_SEARCH_PATHS = "";
+                               OPTIMIZATION_CFLAGS = "-O0";
                                OTHER_LDFLAGS = "";
                                PRODUCT_NAME = PythonLauncher;
                                SECTORDER_FLAGS = "";
                                F58D4A3F02F1F94B01000102,
                                F5A4C13F02F203F701000102,
                                F5449B4C02FB3F7E01000102,
+                               F5A42168038BDD8E0110C447,
                        );
                        isa = PBXResourcesBuildPhase;
                        runOnlyForDeploymentPostprocessing = 0;
                        settings = {
                        };
                };
+               F5A42167038BDD8E0110C447 = {
+                       isa = PBXFileReference;
+                       path = factorySettings.plist;
+                       refType = 4;
+               };
+               F5A42168038BDD8E0110C447 = {
+                       fileRef = F5A42167038BDD8E0110C447;
+                       isa = PBXBuildFile;
+                       settings = {
+                       };
+               };
                F5A4C13E02F203F601000102 = {
                        isa = PBXFileReference;
                        path = PreferenceWindow.nib;
diff --git a/Mac/OSX/PythonLauncher/factorySettings.plist b/Mac/OSX/PythonLauncher/factorySettings.plist
new file mode 100644 (file)
index 0000000..5b81d7d
--- /dev/null
@@ -0,0 +1,79 @@
+<?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>