Mercurial > cpython-lru_cache-weakref
view Mac/PythonLauncher/MyAppDelegate.m @ 51749:1408feec0084 3.0
Merged revisions 69798 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
................
r69798 | benjamin.peterson | 2009-02-19 22:02:38 -0600 (Thu, 19 Feb 2009) | 13 lines
Merged revisions 69769,69776 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r69769 | georg.brandl | 2009-02-19 02:30:06 -0600 (Thu, 19 Feb 2009) | 1 line
#5310, #3558: fix operator precedence table.
........
r69776 | georg.brandl | 2009-02-19 10:34:51 -0600 (Thu, 19 Feb 2009) | 2 lines
#5317: update IronPython URL.
........
................
| author | Benjamin Peterson <benjamin@python.org> |
|---|---|
| date | Fri, 20 Feb 2009 04:05:32 +0000 |
| parents | a19c20c5e5c7 |
| children | 738cba2bf849 |
line wrap: on
line source
#import "MyAppDelegate.h" #import "PreferencesWindowController.h" #import <Carbon/Carbon.h> #import <ApplicationServices/ApplicationServices.h> @implementation MyAppDelegate - (id)init { self = [super init]; initial_action_done = NO; should_terminate = NO; return self; } - (IBAction)showPreferences:(id)sender { [PreferencesWindowController getPreferencesWindow]; } - (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. if (!initial_action_done) { initial_action_done = YES; [self showPreferences: self]; } } - (BOOL)shouldShowUI { // if this call comes before applicationDidFinishLaunching: we // should terminate immedeately after starting the script. if (!initial_action_done) should_terminate = YES; initial_action_done = YES; if( GetCurrentKeyModifiers() & optionKey ) return YES; return NO; } - (BOOL)shouldTerminate { return should_terminate; } - (BOOL)applicationShouldOpenUntitledFile:(NSApplication *)sender { 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
