blob: e75fb06616b68d6a8cdf8d9f93a62ee9ec11a0a6 [file] [log] [blame]
Jack Jansen3bbb6172002-07-29 21:36:35 +00001#import "MyAppDelegate.h"
2#import "PreferencesWindowController.h"
Jack Jansen0a3d6062002-08-01 15:07:00 +00003#import <Carbon/Carbon.h>
Jack Jansenc30d7c32003-06-20 14:36:58 +00004#import <ApplicationServices/ApplicationServices.h>
Jack Jansen3bbb6172002-07-29 21:36:35 +00005
6@implementation MyAppDelegate
7
8- (id)init
9{
10 self = [super init];
11 initial_action_done = NO;
12 should_terminate = NO;
13 return self;
14}
15
16- (IBAction)showPreferences:(id)sender
17{
18 [PreferencesWindowController getPreferencesWindow];
19}
20
21- (void)applicationDidFinishLaunching:(NSNotification *)notification
22{
Jack Jansenc30d7c32003-06-20 14:36:58 +000023 // Test that the file mappings are correct
24 [self testFileTypeBinding];
Jack Jansen3bbb6172002-07-29 21:36:35 +000025 // 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];
31 }
32}
33
34- (BOOL)shouldShowUI
35{
Ronald Oussoren4e327c92013-07-07 09:53:08 +020036 // if this call comes before applicationDidFinishLaunching: we
Jack Jansen0a3d6062002-08-01 15:07:00 +000037 // should terminate immedeately after starting the script.
38 if (!initial_action_done)
39 should_terminate = YES;
Jack Jansen3bbb6172002-07-29 21:36:35 +000040 initial_action_done = YES;
Jack Jansen0a3d6062002-08-01 15:07:00 +000041 if( GetCurrentKeyModifiers() & optionKey )
42 return YES;
Jack Jansen3bbb6172002-07-29 21:36:35 +000043 return NO;
44}
45
46- (BOOL)shouldTerminate
47{
48 return should_terminate;
49}
50
51- (BOOL)applicationShouldOpenUntitledFile:(NSApplication *)sender
52{
53 return NO;
54}
55
Jack Jansenc30d7c32003-06-20 14:36:58 +000056- (void)testFileTypeBinding
57{
58 NSURL *ourUrl;
59 OSStatus err;
60 FSRef appRef;
61 NSURL *appUrl;
62 static NSString *extensions[] = { @"py", @"pyw", @"pyc", NULL};
63 NSString **ext_p;
64 int i;
Ronald Oussoren4e327c92013-07-07 09:53:08 +020065
Jack Jansenc30d7c32003-06-20 14:36:58 +000066 if ([[NSUserDefaults standardUserDefaults] boolForKey: @"SkipFileBindingTest"])
67 return;
68 ourUrl = [NSURL fileURLWithPath: [[NSBundle mainBundle] bundlePath]];
69 for( ext_p = extensions; *ext_p; ext_p++ ) {
70 err = LSGetApplicationForInfo(
71 kLSUnknownType,
72 kLSUnknownCreator,
73 (CFStringRef)*ext_p,
74 kLSRolesViewer,
75 &appRef,
76 (CFURLRef *)&appUrl);
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.",
84 @"OK",
85 @"Don't show this warning again",
86 NULL);
87 if ( i == 0 ) { // Don't show again
88 [[NSUserDefaults standardUserDefaults]
89 setObject:@"YES" forKey:@"SkipFileBindingTest"];
90 }
91 return;
92 }
93 }
94}
Ronald Oussoren4e327c92013-07-07 09:53:08 +020095
Jack Jansen3bbb6172002-07-29 21:36:35 +000096@end