Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c30d7c3

Browse files
committed
At startup, test that PythonLauncher is the default application for files
of type .py, .pyw and .pyc. If not, post a warning.
1 parent 94d09f8 commit c30d7c3

3 files changed

Lines changed: 44 additions & 18 deletions

File tree

Mac/OSX/PythonLauncher/MyAppDelegate.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@
1111
- (IBAction)showPreferences:(id)sender;
1212
- (BOOL)shouldShowUI;
1313
- (BOOL)shouldTerminate;
14+
- (void)testFileTypeBinding;
1415
@end

Mac/OSX/PythonLauncher/MyAppDelegate.m

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#import "MyAppDelegate.h"
22
#import "PreferencesWindowController.h"
33
#import <Carbon/Carbon.h>
4+
#import <ApplicationServices/ApplicationServices.h>
45

56
@implementation MyAppDelegate
67

@@ -19,6 +20,8 @@ - (IBAction)showPreferences:(id)sender
1920

2021
- (void)applicationDidFinishLaunching:(NSNotification *)notification
2122
{
23+
// Test that the file mappings are correct
24+
[self testFileTypeBinding];
2225
// If we were opened because of a file drag or doubleclick
2326
// we've set initial_action_done in shouldShowUI
2427
// Otherwise we open a preferences dialog.
@@ -50,4 +53,44 @@ - (BOOL)applicationShouldOpenUntitledFile:(NSApplication *)sender
5053
return NO;
5154
}
5255

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;
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+
}
94+
}
95+
5396
@end

Mac/OSX/PythonLauncher/PythonLauncher.pbproj/project.pbxproj

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -317,24 +317,6 @@
317317
<string>English</string>
318318
<key>CFBundleDocumentTypes</key>
319319
<array>
320-
<dict>
321-
<key>CFBundleTypeExtensions</key>
322-
<array>
323-
<string>????</string>
324-
</array>
325-
<key>CFBundleTypeIconFile</key>
326-
<string></string>
327-
<key>CFBundleTypeName</key>
328-
<string>DocumentType</string>
329-
<key>CFBundleTypeOSTypes</key>
330-
<array>
331-
<string>????</string>
332-
</array>
333-
<key>CFBundleTypeRole</key>
334-
<string>Editor</string>
335-
<key>NSDocumentClass</key>
336-
<string>MyDocument</string>
337-
</dict>
338320
<dict>
339321
<key>CFBundleTypeExtensions</key>
340322
<array>

0 commit comments

Comments
 (0)