Jack Jansen | 3bbb617 | 2002-07-29 21:36:35 +0000 | [diff] [blame] | 1 | #import "MyAppDelegate.h" |
| 2 | #import "PreferencesWindowController.h" |
Jack Jansen | 0a3d606 | 2002-08-01 15:07:00 +0000 | [diff] [blame] | 3 | #import <Carbon/Carbon.h> |
Jack Jansen | c30d7c3 | 2003-06-20 14:36:58 +0000 | [diff] [blame] | 4 | #import <ApplicationServices/ApplicationServices.h> |
Jack Jansen | 3bbb617 | 2002-07-29 21:36:35 +0000 | [diff] [blame] | 5 | |
| 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 Jansen | c30d7c3 | 2003-06-20 14:36:58 +0000 | [diff] [blame] | 23 | // Test that the file mappings are correct |
| 24 | [self testFileTypeBinding]; |
Jack Jansen | 3bbb617 | 2002-07-29 21:36:35 +0000 | [diff] [blame] | 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]; |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | - (BOOL)shouldShowUI |
| 35 | { |
Ronald Oussoren | 4e327c9 | 2013-07-07 09:53:08 +0200 | [diff] [blame] | 36 | // if this call comes before applicationDidFinishLaunching: we |
Jack Jansen | 0a3d606 | 2002-08-01 15:07:00 +0000 | [diff] [blame] | 37 | // should terminate immedeately after starting the script. |
| 38 | if (!initial_action_done) |
| 39 | should_terminate = YES; |
Jack Jansen | 3bbb617 | 2002-07-29 21:36:35 +0000 | [diff] [blame] | 40 | initial_action_done = YES; |
Jack Jansen | 0a3d606 | 2002-08-01 15:07:00 +0000 | [diff] [blame] | 41 | if( GetCurrentKeyModifiers() & optionKey ) |
| 42 | return YES; |
Jack Jansen | 3bbb617 | 2002-07-29 21:36:35 +0000 | [diff] [blame] | 43 | 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 Jansen | c30d7c3 | 2003-06-20 14:36:58 +0000 | [diff] [blame] | 56 | - (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 Oussoren | 4e327c9 | 2013-07-07 09:53:08 +0200 | [diff] [blame] | 65 | |
Jack Jansen | c30d7c3 | 2003-06-20 14:36:58 +0000 | [diff] [blame] | 66 | 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 Oussoren | 4e327c9 | 2013-07-07 09:53:08 +0200 | [diff] [blame] | 95 | |
Jack Jansen | 3bbb617 | 2002-07-29 21:36:35 +0000 | [diff] [blame] | 96 | @end |