-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathQSDeveloperPlugIn_Source.m
More file actions
238 lines (169 loc) · 8.2 KB
/
QSDeveloperPlugIn_Source.m
File metadata and controls
238 lines (169 loc) · 8.2 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
//
// QSDeveloperPlugIn_Source.m
// QSDeveloperPlugIn
//
// Created by Nicholas Jitkoff on 14/04/05
// Modified by Patrick Robertson on 14/06/11
//
#import "QSDeveloperPlugIn_Source.h"
@interface DSADocSet : NSObject
- (id)initWithDocRootDirectory:(id)fp8;
@end
#define REFROOT @"/Developer/ADC Reference Library/"
@implementation QSDeveloperPlugIn_Source
- (BOOL)indexIsValidFromDate:(NSDate *)indexDate forEntry:(NSDictionary *)theEntry {
return NO;
}
- (NSImage *)iconForEntry:(NSDictionary *)dict {
return [QSResourceManager imageNamed:@"ADCReferenceLibraryIcon"];
}
- (NSString *)identifierForObject:(id <QSObject>)object {
return nil;
}
- (NSArray *)objectsForEntry:(NSDictionary *)theEntry {
NSMutableArray *objects = [NSMutableArray arrayWithCapacity:1];
QSObject *newObject;
[[NSBundle bundleWithPath:@"/Developer/Library/PrivateFrameworks/DocSetAccess.framework"] load];
NSString *rootDir = @"/Developer/Documentation/DocSets/com.apple.ADC_Reference_Library.CoreReference.docset";
NSString *rootDirDocuments = [rootDir stringByAppendingPathComponent:@"Contents/Resources/Documents"];
NSURL *docsURL = [NSURL fileURLWithPath:rootDir];
id docSet = [[[NSClassFromString(@"DSADocSet") alloc] performSelector:@selector(initWithDocRootDirectory:) withObject:docsURL] autorelease];
NSFileManager *fm = [NSFileManager defaultManager];
NSArray *nodes = [docSet valueForKeyPath: @"rootNode.searchableNodesInHierarchy"];
nodes = [nodes filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"domain == %ld", (long)1]];
for (id node in nodes) {
//NSLog(@"set %@ %@ %@", [node valueForKey:@"name"] , [node valueForKey:@"path"] , [node valueForKey:@"URL"]);
NSString *name = [node valueForKey:@"name"];
NSString *path = [node valueForKey:@"path"];
if (!path) continue;
path = [rootDirDocuments stringByAppendingPathComponent:path];
if (![fm fileExistsAtPath:path]) continue;
newObject = [QSObject fileObjectWithPath:path];
[newObject setName:name];
[newObject setObject:@"com.apple.Xcode" forMeta:@"QSPreferredApplication"];
//[newObject setIdentifier:[NSString stringWithFormat:@"devdoc:%@", (int) [node nodeID]];
if (newObject) [objects addObject:newObject];
}
return objects;
// NSXMLElement *root = [xml rootElement];
// NSXMLElement *documentRoot = [[root elementsForName:@"Documents"] lastObject];
// NSArray *documents = [documentRoot elementsForName:@"Document"];
//
// foreach(document, documents) {
//
//
// }
if (YES) {
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *baseDir = @"/Developer/Documentation/DocSets/com.apple.ADC_Reference_Library.CoreReference.docset/Contents/Resources/Documents/documentation/";
NSDirectoryEnumerator *dirEnum = [fileManager enumeratorAtPath:baseDir];
BOOL isDir;
NSString *file;
while ((file = [dirEnum nextObject])) {
NSString *path = [baseDir stringByAppendingPathComponent:file];
NSString *lcPath = [path lowercaseString];
if (([lcPath hasSuffix:@"_class"] || [lcPath hasSuffix:@"_functions"] || [lcPath hasSuffix:@"_protocol"] || [lcPath hasSuffix:@"_ref"] || [lcPath hasSuffix:@"_reference"]) && [fileManager fileExistsAtPath:path isDirectory:&isDir] && isDir) {
NSString *indexPath = [path stringByAppendingPathComponent:@"index.html"];
newObject = [QSObject fileObjectWithPath:indexPath];
[newObject setName:[[file lastPathComponent] stringByReplacing:@"_" with:@" "]];
if (newObject) {
[objects addObject:newObject];
}
}
}
return objects;
}
if (YES) {
NSFileManager *fileManager = [NSFileManager defaultManager];
NSArray *dirs = [NSArray arrayWithObjects:@"/Developer/Documentation/DocSets/com.apple.ADC_Reference_Library.CoreReference.docset/Contents/Resources/Documents/documentation/Cocoa/Reference/ApplicationKit/Classes",
@"/Developer/Documentation/DocSets/com.apple.ADC_Reference_Library.CoreReference.docset/Contents/Resources/Documents/documentation/Cocoa/Reference/Foundation/Classes",
nil];
NSEnumerator *e = [dirs objectEnumerator];
NSString *dir;
while ((dir = [e nextObject]) ) {
NSEnumerator *de = [[fileManager contentsOfDirectoryAtPath:dir error:nil] objectEnumerator];
NSString *junk;
while ((junk = [de nextObject]) ) {
NSRange junkRange = [junk rangeOfString:@"_"];
if (junkRange.location != NSNotFound) {
NSString *name = [junk substringToIndex:junkRange.location];
NSString *path = [[dir stringByAppendingPathComponent:junk] stringByAppendingPathComponent:@"index.html"];
if (![fileManager fileExistsAtPath:path]) {
continue;
}
newObject = [QSObject fileObjectWithPath:path];
[newObject setName:name];
//[newObject setIdentifier:[NSString stringWithFormat:@"devdoc:%@", [[document attributeForName:@"id"] stringValue]]];
if (newObject) {
[objects addObject:newObject];
}
}
}
}
return objects;
}
NSURL *url = [NSURL fileURLWithPath:[REFROOT stringByAppendingPathComponent:@"docSet.xml"]];
NSXMLDocument *xml = [[NSXMLDocument alloc] initWithContentsOfURL:url
options:NSUncachedRead
error:nil];
NSXMLElement *root = [xml rootElement];
NSXMLElement *documentRoot = [[root elementsForName:@"Documents"] lastObject];
NSArray *documents = [documentRoot elementsForName:@"Document"];
// NSFileManager *fm = [NSFileManager defaultManager];
for(NSXMLElement * document in documents) {
NSString *name = [[[document elementsForName:@"Name"] lastObject] stringValue];
NSString *path = [[[document elementsForName:@"Path"] lastObject] stringValue];
if (!path) continue;
path = [REFROOT stringByAppendingPathComponent:path];
if (![fm fileExistsAtPath:path]) continue;
newObject = [QSObject fileObjectWithPath:path];
[newObject setName:name];
[newObject setIdentifier:[NSString stringWithFormat:@"devdoc:%@", [[document attributeForName:@"id"] stringValue]]];
// [newObject setObject:@"" forType:QSDeveloperPlugInType];
// [newObject setPrimaryType:QSDeveloperPlugInType];
if (newObject) [objects addObject:newObject];
}
// NSArray *categoryObjects = [self categoriesForRoot:[[root elementsForName:@"Category"] lastObject]];
//
// [objects addObjectsFromArray:categoryObjects];
//NSLog(@"xml %@", documents);
[xml release];
return objects;
}
- (NSArray *)documentsForRoot:(NSXMLElement *)root {
return nil;
}
- (NSArray *)categoriesForRoot:(NSXMLElement *)root {
NSMutableArray *objects = [NSMutableArray arrayWithCapacity:1];
NSXMLElement *categoryRoot = [[root elementsForName:@"Categories"] lastObject];
NSArray *categories = [categoryRoot elementsForName:@"Category"];
for(NSXMLElement * category in categories) {
NSString *name = [[[category elementsForName:@"Name"] lastObject] stringValue];
NSString *path = [[[category elementsForName:@"Path"] lastObject] stringValue];
NSFileManager *fm = [NSFileManager defaultManager];
if (!path) continue;
path = [REFROOT stringByAppendingPathComponent:path];
if (![fm fileExistsAtPath:path]) continue;
QSObject *newObject = [QSObject fileObjectWithPath:path];
[newObject setName:name];
//NSLog(@"categ %@", path);
[newObject setIdentifier:[NSString stringWithFormat:@"devdoc:%@", [[category attributeForName:@"id"] stringValue]]];
// [newObject setObject:@"" forType:QSDeveloperPlugInType];
// [newObject setPrimaryType:QSDeveloperPlugInType];
if (newObject) [objects addObject:newObject];
}
return nil;
}
// Object Handler Methods
/*
- (void)setQuickIconForObject:(QSObject *)object {
[object setIcon:nil]; // An icon that is either already in memory or easy to load
}
- (BOOL)loadIconForObject:(QSObject *)object {
return NO;
id data = [object objectForType:QSDeveloperPlugInType];
[object setIcon:nil];
return YES;
}
*/
@end