1 #import "MyAppDelegate.h"
2 #import "PreferencesWindowController.h"
3 #import <Carbon/Carbon.h>
4 #import <ApplicationServices/ApplicationServices.h>
6 @implementation MyAppDelegate
11 initial_action_done = NO;
12 should_terminate = NO;
16 - (IBAction)showPreferences:(id)sender
18 [PreferencesWindowController getPreferencesWindow];
21 - (void)applicationDidFinishLaunching:(NSNotification *)notification
23 // Test that the file mappings are correct
24 [self testFileTypeBinding];
25 // If we were opened because of a file drag or doubleclick
26 // we've set initial_action_done in shouldShowUI
27 // Otherwise we open a preferences dialog.
28 if (!initial_action_done) {
29 initial_action_done = YES;
30 [self showPreferences: self];
36 // if this call comes before applicationDidFinishLaunching: we
37 // should terminate immedeately after starting the script.
38 if (!initial_action_done)
39 should_terminate = YES;
40 initial_action_done = YES;
41 if( GetCurrentKeyModifiers() & optionKey )
46 - (BOOL)shouldTerminate
48 return should_terminate;
51 - (BOOL)applicationShouldOpenUntitledFile:(NSApplication *)sender
56 - (void)testFileTypeBinding
62 static NSString *extensions[] = { @"py", @"pyw", @"pyc", NULL};
66 if ([[NSUserDefaults standardUserDefaults] boolForKey: @"SkipFileBindingTest"])
68 ourUrl = [NSURL fileURLWithPath: [[NSBundle mainBundle] bundlePath]];
69 for( ext_p = extensions; *ext_p; ext_p++ ) {
70 err = LSGetApplicationForInfo(
77 if (err || ![appUrl isEqual: ourUrl] ) {
78 i = NSRunAlertPanel(@"File type binding",
79 @"PythonLauncher is not the default application for all " \
80 @"Python script types. You should fix this with the " \
81 @"Finder's \"Get Info\" command.\n\n" \
82 @"See \"Changing the application that opens a file\" in " \
83 @"Mac Help for details.",
85 @"Don't show this warning again",
87 if ( i == 0 ) { // Don't show again
88 [[NSUserDefaults standardUserDefaults]
89 setObject:@"YES" forKey:@"SkipFileBindingTest"];