Issue #5262: Fixed bug in next roll over time computation in TimedRotatingFileHandler.
[python.git] / Mac / PythonLauncher / MyAppDelegate.m
bloba5ba7510784c97b7920298443be85eca77a7644f
1 #import "MyAppDelegate.h"
2 #import "PreferencesWindowController.h"
3 #import <Carbon/Carbon.h>
4 #import <ApplicationServices/ApplicationServices.h>
6 @implementation MyAppDelegate
8 - (id)init
10     self = [super init];
11     initial_action_done = NO;
12     should_terminate = NO;
13     return self;
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];
31     }
34 - (BOOL)shouldShowUI
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 )
42         return YES;
43     return NO;
46 - (BOOL)shouldTerminate
48     return should_terminate;
51 - (BOOL)applicationShouldOpenUntitledFile:(NSApplication *)sender
53     return NO;
56 - (void)testFileTypeBinding
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;
65     
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     }
95         
96 @end