[Python-checkins] python/dist/src/Mac/OSX/PythonLauncher MyAppDelegate.h,1.1,1.2 MyAppDelegate.m,1.2,1.3

jackjansen@users.sourceforge.net jackjansen@users.sourceforge.net
Fri, 20 Jun 2003 07:37:00 -0700


Update of /cvsroot/python/python/dist/src/Mac/OSX/PythonLauncher
In directory sc8-pr-cvs1:/tmp/cvs-serv31425/PythonLauncher

Modified Files:
	MyAppDelegate.h MyAppDelegate.m 
Log Message:
At startup, test that PythonLauncher is the default application for files
of type .py, .pyw and .pyc. If not, post a warning.



Index: MyAppDelegate.h
===================================================================
RCS file: /cvsroot/python/python/dist/src/Mac/OSX/PythonLauncher/MyAppDelegate.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** MyAppDelegate.h	29 Jul 2002 21:36:35 -0000	1.1
--- MyAppDelegate.h	20 Jun 2003 14:36:58 -0000	1.2
***************
*** 12,14 ****
--- 12,15 ----
  - (BOOL)shouldShowUI;
  - (BOOL)shouldTerminate;
+ - (void)testFileTypeBinding;
  @end

Index: MyAppDelegate.m
===================================================================
RCS file: /cvsroot/python/python/dist/src/Mac/OSX/PythonLauncher/MyAppDelegate.m,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** MyAppDelegate.m	1 Aug 2002 15:07:00 -0000	1.2
--- MyAppDelegate.m	20 Jun 2003 14:36:58 -0000	1.3
***************
*** 2,5 ****
--- 2,6 ----
  #import "PreferencesWindowController.h"
  #import <Carbon/Carbon.h>
+ #import <ApplicationServices/ApplicationServices.h>
  
  @implementation MyAppDelegate
***************
*** 20,23 ****
--- 21,26 ----
  - (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
***************
*** 51,53 ****
--- 54,96 ----
  }
  
+ - (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