-
Notifications
You must be signed in to change notification settings - Fork 5
/
OpenInSublime.m
72 lines (52 loc) · 1.55 KB
/
OpenInSublime.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
72
// Created by Ray Kola
// Based on Open in Textmate by orta therox on 06/09/2010. Copyright 2010 wgrids. All rights reserved.
#import "OpenInSublime.h"
@implementation OpenInSublime
@synthesize host;
+ (id)plugin:(id<NTPathFinderPluginHostProtocol>)pathfinder_host;
{
OpenInSublime* result = [[self alloc] init];
result.host = pathfinder_host;
return [result autorelease];
}
- (NSMenuItem*)contextualMenuItem;
{
return [self menuItem];
}
- (NSMenuItem*)menuItem;
{
NSMenuItem* menuItem;
menuItem = [[[NSMenuItem alloc] initWithTitle:@"Open in Sublime" action:@selector(pluginAction:) keyEquivalent:@""] autorelease];
[menuItem setTarget:self];
return menuItem;
}
- (void)pluginAction:(id)sender;
{
[self processItems:nil parameter:nil];
}
- (BOOL)validateMenuItem:(NSMenuItem*)menuItem;
{
return [[[self host] selection:nil browserID:nil] count] > 0;
}
- (id)processItems:(NSArray*)items parameter:(id)parameter;
{
if (!items)
items = [self.host selection:nil browserID:nil];
// Look for the files selected and turn it into one nice string
NSEnumerator* enumerator = [items objectEnumerator];
NSString *path;
id<NTFSItem> item;
while (item = [enumerator nextObject])
{
path = [item path];
if (path)
{
[[NSWorkspace sharedWorkspace] openFile:path withApplication:@"Sublime Text 2"];
}
}
//This is a round about way of doing it, and there's the limit of
// only allowing one file to be worked on at once but it's good enough for
// the minute, and for me.
return nil;
}
@end