-
Notifications
You must be signed in to change notification settings - Fork 0
/
FinderTextMatePatch.m
71 lines (53 loc) · 2.3 KB
/
FinderTextMatePatch.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
69
70
71
//
// FinderTextMatePatch.m
// FinderPatch
//
// Created by toy on 26.01.11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import "FinderTextMatePatch.h"
@implementation FinderTextMatePatch
+ (void) loadPatch {
NSWorkspace *workspace = [NSWorkspace sharedWorkspace];
NSString *textMatePath = [workspace absolutePathForAppBundleWithIdentifier:@"com.macromates.textmate"];
if (textMatePath) {
NSString *keyEquivalent = @"m";
NSUInteger modifierMask = NSCommandKeyMask | NSControlKeyMask;
[self shiftItemWithKeyEquivalent:keyEquivalent andModifierMask:modifierMask];
NSMenuItem *openInTextMateItem = [[self patchMenu] addItemWithTitle:@"Open in TextMate" action:@selector(cmdOpenInTextMate:) keyEquivalent:keyEquivalent];
[openInTextMateItem setKeyEquivalentModifierMask:modifierMask];
[openInTextMateItem setTarget:self];
NSImage *textMateIcon = [workspace iconForFile:textMatePath];
[textMateIcon setSize:NSMakeSize(16, 16)];
[openInTextMateItem setImage:textMateIcon];
}
}
+ (void) cmdOpenInTextMate:(id)sender {
[self performSelectorInBackground:@selector(cmdOpenInTextMateAsynchronyously:) withObject:sender];
}
+ (void) cmdOpenInTextMateAsynchronyously:(id)sender {
id pool = [[NSAutoreleasePool alloc] init];
FNApplication *finder = [FNApplication applicationWithName:@"Finder"];
NSArray *paths = [self refPaths:[finder selection]];
if ([paths count] > 0) {
NSMutableArray *arguments = [NSMutableArray arrayWithObjects:@"ruby", @"-e", @"load 'mate/../../bin/tm'", nil];
NSBundle *thisBundle = [NSBundle bundleForClass:[self class]];
NSString *vendorPath = [[thisBundle resourcePath] stringByAppendingPathComponent:@"vendor"];
NSArray *gemNames = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:vendorPath error:nil];
if (gemNames) {
for (NSString *gemName in gemNames) {
NSString *gemLibPath = [[vendorPath stringByAppendingPathComponent:gemName] stringByAppendingPathComponent:@"lib"];
[arguments addObjectsFromArray:[NSArray arrayWithObjects:@"-I", gemLibPath, nil]];
}
}
[arguments addObjectsFromArray:paths];
NSTask *task = [[[NSTask alloc] init] autorelease];
[task setLaunchPath:@"/usr/bin/env"];
[task setArguments:arguments];
[task setEnvironment:[self environment]];
[task launch];
[task waitUntilExit];
}
[pool release];
}
@end