2002-07-29 23:36:35 +02:00
|
|
|
#import "MyAppDelegate.h"
|
|
|
|
#import "PreferencesWindowController.h"
|
2002-08-01 17:07:00 +02:00
|
|
|
#import <Carbon/Carbon.h>
|
2003-06-20 16:36:58 +02:00
|
|
|
#import <ApplicationServices/ApplicationServices.h>
|
2002-07-29 23:36:35 +02:00
|
|
|
|
|
|
|
@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
|
|
|
|
{
|
2003-06-20 16:36:58 +02:00
|
|
|
// Test that the file mappings are correct
|
|
|
|
[self testFileTypeBinding];
|
2002-07-29 23:36:35 +02:00
|
|
|
// 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
|
|
|
|
{
|
2013-07-07 09:53:08 +02:00
|
|
|
// if this call comes before applicationDidFinishLaunching: we
|
2016-08-30 19:47:49 +02:00
|
|
|
// should terminate immediately after starting the script.
|
2002-08-01 17:07:00 +02:00
|
|
|
if (!initial_action_done)
|
|
|
|
should_terminate = YES;
|
2002-07-29 23:36:35 +02:00
|
|
|
initial_action_done = YES;
|
2002-08-01 17:07:00 +02:00
|
|
|
if( GetCurrentKeyModifiers() & optionKey )
|
|
|
|
return YES;
|
2002-07-29 23:36:35 +02:00
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)shouldTerminate
|
|
|
|
{
|
|
|
|
return should_terminate;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)applicationShouldOpenUntitledFile:(NSApplication *)sender
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
2003-06-20 16:36:58 +02:00
|
|
|
- (void)testFileTypeBinding
|
|
|
|
{
|
|
|
|
NSURL *ourUrl;
|
|
|
|
OSStatus err;
|
|
|
|
FSRef appRef;
|
|
|
|
NSURL *appUrl;
|
|
|
|
static NSString *extensions[] = { @"py", @"pyw", @"pyc", NULL};
|
|
|
|
NSString **ext_p;
|
|
|
|
int i;
|
2013-07-07 09:53:08 +02:00
|
|
|
|
2003-06-20 16:36:58 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-07-07 09:53:08 +02:00
|
|
|
|
2002-07-29 23:36:35 +02:00
|
|
|
@end
|