]> granicus.if.org Git - python/commitdiff
At startup, test that PythonLauncher is the default application for files
authorJack Jansen <jack.jansen@cwi.nl>
Fri, 20 Jun 2003 14:36:58 +0000 (14:36 +0000)
committerJack Jansen <jack.jansen@cwi.nl>
Fri, 20 Jun 2003 14:36:58 +0000 (14:36 +0000)
of type .py, .pyw and .pyc. If not, post a warning.

Mac/OSX/PythonLauncher/MyAppDelegate.h
Mac/OSX/PythonLauncher/MyAppDelegate.m
Mac/OSX/PythonLauncher/PythonLauncher.pbproj/project.pbxproj

index c65175a7aec651e4192fc0bef625bf0bdea19993..097b54177c881d2d9d6eba7522d2b627f2037c35 100644 (file)
@@ -11,4 +11,5 @@
 - (IBAction)showPreferences:(id)sender;
 - (BOOL)shouldShowUI;
 - (BOOL)shouldTerminate;
+- (void)testFileTypeBinding;
 @end
index cb9797249db7e5875c9c710852ac7bc56266e819..a5ba7510784c97b7920298443be85eca77a7644f 100644 (file)
@@ -1,6 +1,7 @@
 #import "MyAppDelegate.h"
 #import "PreferencesWindowController.h"
 #import <Carbon/Carbon.h>
+#import <ApplicationServices/ApplicationServices.h>
 
 @implementation MyAppDelegate
 
@@ -19,6 +20,8 @@
 
 - (void)applicationDidFinishLaunching:(NSNotification *)notification
 {
+    // Test that the file mappings are correct
+    [self testFileTypeBinding];
     // If we were opened because of a file drag or doubleclick
     // we've set initial_action_done in shouldShowUI
     // Otherwise we open a preferences dialog.
     return NO;
 }
 
+- (void)testFileTypeBinding
+{
+    NSURL *ourUrl;
+    OSStatus err;
+    FSRef appRef;
+    NSURL *appUrl;
+    static NSString *extensions[] = { @"py", @"pyw", @"pyc", NULL};
+    NSString **ext_p;
+    int i;
+    
+    if ([[NSUserDefaults standardUserDefaults] boolForKey: @"SkipFileBindingTest"])
+        return;
+    ourUrl = [NSURL fileURLWithPath: [[NSBundle mainBundle] bundlePath]];
+    for( ext_p = extensions; *ext_p; ext_p++ ) {
+        err = LSGetApplicationForInfo(
+            kLSUnknownType,
+            kLSUnknownCreator,
+            (CFStringRef)*ext_p,
+            kLSRolesViewer,
+            &appRef,
+            (CFURLRef *)&appUrl);
+        if (err || ![appUrl isEqual: ourUrl] ) {
+            i = NSRunAlertPanel(@"File type binding",
+                @"PythonLauncher is not the default application for all " \
+                  @"Python script types. You should fix this with the " \
+                  @"Finder's \"Get Info\" command.\n\n" \
+                  @"See \"Changing the application that opens a file\" in " \
+                  @"Mac Help for details.",
+                @"OK",
+                @"Don't show this warning again",
+                NULL);
+            if ( i == 0 ) { // Don't show again
+                [[NSUserDefaults standardUserDefaults]
+                    setObject:@"YES" forKey:@"SkipFileBindingTest"];
+            }
+            return;
+        }
+    }
+}
+        
 @end
index 5b4a06c87c573a202215d95cc3a68f53def77ad9..107ce3dd4f27c23c23f7f866cb9d7c4818628d8d 100755 (executable)
        <string>English</string>
        <key>CFBundleDocumentTypes</key>
        <array>
-               <dict>
-                       <key>CFBundleTypeExtensions</key>
-                       <array>
-                               <string>????</string>
-                       </array>
-                       <key>CFBundleTypeIconFile</key>
-                       <string></string>
-                       <key>CFBundleTypeName</key>
-                       <string>DocumentType</string>
-                       <key>CFBundleTypeOSTypes</key>
-                       <array>
-                               <string>????</string>
-                       </array>
-                       <key>CFBundleTypeRole</key>
-                       <string>Editor</string>
-                       <key>NSDocumentClass</key>
-                       <string>MyDocument</string>
-               </dict>
                <dict>
                        <key>CFBundleTypeExtensions</key>
                        <array>