Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 98 lines (67 sloc) 3.904 kb
1d83afe @ccgus Added support for double clicking JSTalk plugins to install them.
authored
1 //
2 // JSTPluginMover.m
3 // jstalk
4 //
5 // Created by August Mueller on 8/15/10.
6 // Copyright 2010 Flying Meat Inc. All rights reserved.
7 //
8
9 #import "JSTPluginMover.h"
10 #import <JSTalk/JSTalk.h>
11
12 @implementation JSTPluginMover
13
14 - (void) makeWindowControllers { }
15
16 - (NSData *)dataRepresentationOfType:(NSString *)type {
17 return nil;
18 }
19
20 - (BOOL)readFromFile:(NSString *)fileName ofType:(NSString *)docType {
21 NSString *thePluginName = [fileName lastPathComponent];
22 NSString *pluginsFolder = [@"~/Library/Application Support/JSTalk/Plug-ins/" stringByExpandingTildeInPath];
23 NSString *placeToPut = [pluginsFolder stringByAppendingPathComponent:thePluginName];
24
25 // is it already in the plugins folder?
26 if ([placeToPut isEqualToString:fileName]) {
27 // wait 2 seconds and close this guy.
28 [self performSelector:@selector(close) withObject:nil afterDelay:2];
29 return YES;
30 }
31
32 NSString *askQuestion = NSLocalizedString(@"Would you like to copy the plugin '%@' into your JSTalk Plug-ins folder?",
33 @"Would you like to copy the plugin '%@' into your JSTalk Plug-ins folder?");
34
35 int decision = NSRunAlertPanel(NSLocalizedString(@"Install Plug-in?", @"Install Plug-in?"),
36 [NSString stringWithFormat:askQuestion, thePluginName], @"Install Plug-in", @"Cancel", nil);
37
38
39
40 if (decision == NSOKButton) {
41 NSFileManager *fileManager = [NSFileManager defaultManager];
42
43 NSError *err = 0x00; // yes, I know the cocoa conventions on this. I'm going to nil it out anyway.
44 if (![fileManager createDirectoryAtPath:pluginsFolder withIntermediateDirectories:YES attributes:nil error:&err]) {
45 NSLog(@"Error making the plug-in directory: %@", err);
46 NSBeep();
47 return NO;
48 }
49
50 // check and see if it's already there..
51 BOOL isDir;
52
53 if ([fileManager fileExistsAtPath:placeToPut isDirectory:&isDir] && isDir) {
54
55 NSString *sorryQ = NSLocalizedString(@"There is already a plug-in installed with the name '%@'. Please quit JSTalk, remove it, and then try again.",
56 @"There is already a plug-in installed with the name '%@'. Please quit JSTalk, remove it, and then try again.");
57
58 NSString *openFolder = NSLocalizedString(@"Open Plug-ins Folder", @"Open Plug-ins Folder");
59
60 decision = NSRunAlertPanel(NSLocalizedString(@"Sorry", @"Sorry"), [NSString stringWithFormat:sorryQ, thePluginName], nil, openFolder, nil);
61
62 // open up the plugins folder for the user to remove the plugin.
63 if (decision != NSOKButton) {
64 [[NSWorkspace sharedWorkspace] openFile:pluginsFolder];
65 }
66 }
67 else {
68
69
70 if (![fileManager copyItemAtPath:fileName toPath:[pluginsFolder stringByAppendingPathComponent:thePluginName] error:&err]) {
71
72 NSLog(@"Error copying plug-in: %@", err);
73 NSRunAlertPanel(NSLocalizedString(@"Sorry", @"Sorry"),
74 NSLocalizedString(@"I could not copy in the plug-in.",
75 @"I could not copy in the plug-in."),
76 nil, nil, nil);
77 }
78 else {
79
80 [JSTalk resetPlugins];
81
82
83 NSRunAlertPanel(NSLocalizedString(@"Plug-in Installed.", @"Plug-in Installed."), @"", nil, nil, nil);
84
85
86 }
87 }
88 }
89
90
91 // wait 2 seconds and close this guy.
92 [self performSelector:@selector(close) withObject:nil afterDelay:2];
93
94 return YES;
95 }
96
97 @end
Something went wrong with that request. Please try again.