-
Notifications
You must be signed in to change notification settings - Fork 0
/
QuickSnippetsSource.m
103 lines (82 loc) · 3.88 KB
/
QuickSnippetsSource.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
//
// QuickSnippetsSource.m
// QuickSnippets
//
// Created by Taichiro Yoshida on 09/11/05.
// Copyright Taichiro Yoshida 2009. All rights reserved.
//
#import <Vermilion/Vermilion.h>
#import <GTM/GTMNSString+URLArguments.h>
static NSString *const kQuickSnippetsBundleIdentifier = @"com.dataich.QuickSnippets";
static NSString *const kQuickSnippetsUrlSchemePaste = @"quicksnippets://Snippet/Paste";
static NSString *const kQuickSnippetsUrlSchemeRegist = @"quicksnippets://Snippet/Regist";
static NSString *const kQuickSnippetsPasteAction = @"com.dataich.action.QuickSnippets.Paste";
static NSString *const kQuickSnippetsRegistAction = @"com.dataich.action.QuickSnippets.Regist";
@interface QuickSnippetsSource : HGSMemorySearchSource {
}
- (void)initResultsFromPlist;
@end
@implementation QuickSnippetsSource
- (id)initWithConfiguration:(NSDictionary *)configuration {
if ((self = [super initWithConfiguration:configuration])) {
[self initResultsFromPlist];
}
return self;
}
- (void)initResultsFromPlist {
id<HGSDelegate> delegate = [[HGSPluginLoader sharedPluginLoader] delegate];
NSString *path = [[delegate userApplicationSupportFolderForApp]
stringByAppendingPathComponent:kQuickSnippetsPlist];
HGSLogDebug(@"%@", path);
NSBundle *bundle = HGSGetPluginBundle();
NSString *iconPath = [bundle pathForResource:@"QuickSnippets" ofType:@"png"];
NSImage *icon = [[NSImage alloc] initByReferencingFile:iconPath];
if(path) {
NSArray *snippets = [NSArray arrayWithContentsOfFile:path];
for(NSArray *snippet in snippets) {
NSString *key = (NSString*)[snippet objectAtIndex:0];
NSString *name = (NSString*)[snippet objectAtIndex:1];
HGSLogDebug(@"%@", name);
NSMutableDictionary *dictionary = [NSMutableDictionary dictionaryWithObjectsAndKeys:
name,
kHGSObjectAttributeNameKey,
HGS_SUBTYPE(kHGSTypeText, @"quicksnippets"), kHGSObjectAttributeTypeKey,
[NSString stringWithFormat:@"%@?%@", kQuickSnippetsUrlSchemePaste, name],
kHGSObjectAttributeURIKey,
icon,
kHGSObjectAttributeIconKey,
nil];
HGSAction *action = [[HGSExtensionPoint actionsPoint]
extensionWithIdentifier:kQuickSnippetsPasteAction];
if (action) {
[dictionary setObject:action forKey:kHGSObjectAttributeDefaultActionKey];
}
HGSResult *result = [HGSResult resultWithDictionary:dictionary source:self];
[self indexResult:result
name:key
otherTerms:nil];
}
}
NSMutableDictionary *dictionary = [NSMutableDictionary dictionaryWithObjectsAndKeys:
@"QuickSnippets Regist", kHGSObjectAttributeNameKey,
HGS_SUBTYPE(kHGSTypeAction, @"quicksnippets"), kHGSObjectAttributeTypeKey,
kQuickSnippetsUrlSchemeRegist, kHGSObjectAttributeURIKey,
icon, kHGSObjectAttributeIconKey,
nil];
HGSAction *action = [[HGSExtensionPoint actionsPoint]
extensionWithIdentifier:kQuickSnippetsRegistAction];
if (action) {
[dictionary setObject:action forKey:kHGSObjectAttributeDefaultActionKey];
}
HGSResult *result = [HGSResult resultWithDictionary:dictionary source:self];
[self indexResult:result
name:@"QuickSnippets"
otherTerms:nil];
}
- (NSMutableDictionary *)archiveRepresentationForResult:(HGSResult*)result {
return nil;
}
- (HGSResult *)resultWithArchivedRepresentation:(NSDictionary *)representation {
return nil;
}
@end