forked from ccgus/flycode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJSCocoaLoaderPlugIn.m
68 lines (49 loc) · 1.96 KB
/
JSCocoaLoaderPlugIn.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#import "JSCocoaLoaderPlugIn.h"
#import "CodaPlugInsController.h"
#import "JSCocoaController.h"
/// ooooh, a hack!
static CodaPlugInsController *JSCocoaLoaderPlugInCodaPlugInsController;
@implementation JSCocoaLoaderPlugIn
- (id)initWithPlugInController:(CodaPlugInsController*)inController bundle:(NSBundle*)aBundle
{
if ( (self = [super init]) != nil ) {
controller = inController;
JSCocoaLoaderPlugInCodaPlugInsController = controller;
[self findJSCocoaScripts];
}
return self;
}
+ (CodaPlugInsController *) codaPluginsController {
return JSCocoaLoaderPlugInCodaPlugInsController;
}
- (NSString*)name {
return @"JSCocoa";
}
- (void) execute:(id)sender {
NSString *path = [sender representedObject];
NSError *err = 0x00;
NSString *pathContents = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:&err];
id c = [JSCocoaController sharedController];
[c evalJSString:pathContents];
}
- (void) findJSCocoaScripts {
NSString *pluginDir = [@"~/Library/Application Support/Coda/JSPlug-ins/" stringByExpandingTildeInPath];
NSFileManager *fm = [NSFileManager defaultManager];
BOOL isDir = NO;
if (!([fm fileExistsAtPath:pluginDir isDirectory:&isDir] && isDir)) {
return;
}
for (NSString *fileName in [fm contentsOfDirectoryAtPath:pluginDir error:nil]) {
if (![fileName hasSuffix:@".js"]) {
continue;
}
[controller registerActionWithTitle:[fileName stringByDeletingPathExtension]
underSubmenuWithTitle:nil
target:self
selector:@selector(execute:)
representedObject:[pluginDir stringByAppendingPathComponent:fileName]
keyEquivalent:@""
pluginName:[fileName stringByDeletingPathExtension]];
}
}
@end