Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 512 lines (361 sloc) 18.417 kb
cbdc2a9 @ccgus [UPDATES] General code cleanup for the Acorn and VoodooPad sample plu…
authored
1 /*
2 Not only does this plugin load up the JSTalk Listener, so we can talk to VoodooPad via JSTalk, it also adds support for JavaScript Plugins, via VP's plugin API.
3 */
ee99867 @ccgus oh geeze
authored
4
5 #import "JavaScriptPluginEnabler.h"
6
7 #import <JSTalk/JSTalk.h>
6eaabbd @ccgus Fixed a compile error
authored
8 #import <JSTalk/JSCocoa.h>
9 #import <JavaScriptCore/JavaScriptCore.h>
ee99867 @ccgus oh geeze
authored
10
11 #define VPLanguageKey @"VPLanguage"
12 #define VPScriptMenuTitleKey @"VPScriptMenuTitle"
13 #define VPScriptSuperMenuTitleKey @"VPScriptSuperMenuTitle"
14 #define VPShortcutKeyKey @"VPShortcutKey"
15 #define VPShortcutMaskKey @"VPShortcutMask"
16 #define VPBackgroundThreadKey @"VPBackgroundThread"
17
c62d72f @ccgus Added an editor for jstalk
authored
18 JavaScriptPluginEnabler *JavaScriptPluginEnablerGlobalHACKHACKHACK;
19
ee99867 @ccgus oh geeze
authored
20 @interface NSObject (VPAppDelegateExtrase)
21 - (void) console:(NSString*)s;
22 @end
23
24
25 @interface JavaScriptPluginEnabler (Private)
698bb6e @ccgus Little formatting updates, and a bit of experimentation.
authored
26 - (NSDictionary*)propertiesFromScriptAtPath:(NSString*)path;
ee99867 @ccgus oh geeze
authored
27 @end
28
29 @implementation JavaScriptPluginEnabler
30
31
698bb6e @ccgus Little formatting updates, and a bit of experimentation.
authored
32 - (void)didRegister {
c62d72f @ccgus Added an editor for jstalk
authored
33
34 JavaScriptPluginEnablerGlobalHACKHACKHACK = self;
ee99867 @ccgus oh geeze
authored
35
36 NSString *scriptsDir = [self scriptsDir];
37 if (!scriptsDir) {
38 NSLog(@"Could not find Script PlugIns directory");
39 return;
40 }
41
42 NSArray *scriptsFolder = [[NSFileManager defaultManager] directoryContentsAtPath:scriptsDir];
43 NSEnumerator *enumerator = [scriptsFolder objectEnumerator];
44 NSString *fileName;
45 NSString *filePath;
46 while ((fileName = [enumerator nextObject])) {
47 filePath = [scriptsDir stringByAppendingPathComponent:fileName];
48 [self registerScript:filePath];
49 }
50
bb20314 @ccgus Changed up the VoodooPad plugin a bit, it does more.
authored
51 [[self pluginManager] addPluginsMenuTitle:@"Run Page as JSTalk"
52 withSuperMenuTitle:@"JSTalk"
ee99867 @ccgus oh geeze
authored
53 target:self
54 action:@selector(handleRunAsJavaScript:)
55 keyEquivalent:@";"
56 keyEquivalentModifierMask:NSCommandKeyMask | NSControlKeyMask];
57
bb20314 @ccgus Changed up the VoodooPad plugin a bit, it does more.
authored
58 [[self pluginManager] addPluginsMenuTitle:[NSString stringWithFormat:@"Save Page as JSTalk Plugin%C", 0x2026]
59 withSuperMenuTitle:@"JSTalk"
ee99867 @ccgus oh geeze
authored
60 target:self
61 action:@selector(handleSaveAsJavaScript:)
62 keyEquivalent:@""
63 keyEquivalentModifierMask:0];
64
f67ddf4 More VP fun.
August Mueller authored
65 [[self pluginManager] addPluginsMenuTitle:[NSString stringWithFormat:@"Copy as JSTalk Bookmarklet"]
66 withSuperMenuTitle:@"JSTalk"
67 target:self
68 action:@selector(copyBookmarkletToPasteboard:)
69 keyEquivalent:@""
70 keyEquivalentModifierMask:0];
71
bb20314 @ccgus Changed up the VoodooPad plugin a bit, it does more.
authored
72 [[self pluginManager] registerPluginAppleScriptName:@"JSTalk Script"
ee99867 @ccgus oh geeze
authored
73 target:self
74 action:@selector(runScriptAction:)];
75
bb20314 @ccgus Changed up the VoodooPad plugin a bit, it does more.
authored
76 [[self pluginManager] registerEventRunner:self forLanguage:@"JSTalk"];
ee99867 @ccgus oh geeze
authored
77
99e3e23 added the ability to call jstalk: javascript: urls, which will then e…
August Mueller authored
78 [[self pluginManager] registerURLHandler:self];
ee99867 @ccgus oh geeze
authored
79
80 // this guy openes up a port to listen for outside JSTalk commands commands
81 [JSTalk listen];
82 }
83
698bb6e @ccgus Little formatting updates, and a bit of experimentation.
authored
84 - (BOOL)runScript:(NSString *)script forEvent:(NSString*)eventName withEventDictionary:(NSMutableDictionary*)eventDictionary {
ee99867 @ccgus oh geeze
authored
85 // todo
86 return NO;
87 }
88
698bb6e @ccgus Little formatting updates, and a bit of experimentation.
authored
89 - (BOOL)canHandleURL:(NSString*)theUrl {
99e3e23 added the ability to call jstalk: javascript: urls, which will then e…
August Mueller authored
90 return [theUrl hasPrefix:@"jstalk:"] || [theUrl hasPrefix:@"javascript:"];
91 }
92
93
698bb6e @ccgus Little formatting updates, and a bit of experimentation.
authored
94 - (BOOL)handleURL:(NSString*)theURL {
99e3e23 added the ability to call jstalk: javascript: urls, which will then e…
August Mueller authored
95
96 if ([theURL hasPrefix:@"jstalk:"]) {
97 theURL = [theURL substringWithRange:NSMakeRange(7, [theURL length] - 7)];
98 }
99 else if ([theURL hasPrefix:@"javascript:"]) {
100 theURL = [theURL substringWithRange:NSMakeRange(11, [theURL length] - 11)];
101 }
102 else {
103 // ...?
104 return NO;
105 }
106
107 NSWindowController *wc = 0x00;
108 NSDocument *currentDoc = [[NSDocumentController sharedDocumentController] currentDocument];
109
110 // let's see if we can figure out what the current window controller is.
111 if (currentDoc && [[currentDoc windowControllers] count]) {
112 NSWindowController *currentWindowController = [[currentDoc windowControllers] objectAtIndex:0];
113
114 // we're really just making an educated guess as to this being the right window controller. I'm assuming someone's clicking on
115 // a link.
116 if ([[currentWindowController window] isMainWindow]) {
117 wc = currentWindowController;
118 }
119 }
120
121 NSString *theSource = [theURL stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
122
123 [self runScript:theSource withWindowController:(id)wc];
124
125 return YES;
126 }
ee99867 @ccgus oh geeze
authored
127
f67ddf4 More VP fun.
August Mueller authored
128
698bb6e @ccgus Little formatting updates, and a bit of experimentation.
authored
129 - (void)copyBookmarkletToPasteboard:(id<VPPluginWindowController>)windowController {
f67ddf4 More VP fun.
August Mueller authored
130
131
132 NSRange r = [[windowController textView] selectedRange];
133
134 NSString *selectedText = 0x00;
135
136 if (r.length == 0) {
137 selectedText = [[[windowController textView] textStorage] string];
138 }
139 else {
140 selectedText = [[[[windowController textView] textStorage] string] substringWithRange:r];
141 }
142
143 NSString *bookmarklet = [NSString stringWithFormat:@"javascript:%@", [selectedText stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
144
145 NSDictionary *atts = [NSDictionary dictionaryWithObject:bookmarklet forKey:NSLinkAttributeName];
146
147 NSAttributedString *ats = [[[NSMutableAttributedString alloc] initWithString:@"JSTalk Bookmarklet" attributes:atts] autorelease];
148
149 NSData *atsData = [ats RTFFromRange:NSMakeRange(0, [ats length]) documentAttributes:nil];
150
151 NSPasteboard *pb = [NSPasteboard generalPasteboard];
152
153 [pb declareTypes:[NSArray arrayWithObjects:NSStringPboardType, NSRTFPboardType, nil] owner:nil];
154 [pb setString:bookmarklet forType:NSStringPboardType];
155 [pb setData:atsData forType:NSRTFPboardType];
156 }
157
158
159
160
161
162
163
ee99867 @ccgus oh geeze
authored
164 - (void)savePanelDidEndForSaveAsJavaScript:(NSSavePanel *)savePanel
165 returnCode:(int)returnCode
166 contextInfo:(id<VPPluginWindowController>)windowController
167 {
168 if (returnCode == NSOKButton) {
169 NSString *s = [[windowController textView] string];
170
171 [[s dataUsingEncoding:NSUTF8StringEncoding] writeToFile:[savePanel filename] atomically:YES];
172
173 [self registerScript:[savePanel filename]];
174
175 // privateness, please ignore.
176 [[self pluginManager] performSelector:@selector(sortMenu)];
177 }
178 }
179
180 - (void) handleSaveAsJavaScript:(id<VPPluginWindowController>)windowController {
181
182 NSString *key = [windowController key];
183
184 NSString *displayName = [[[windowController document] vpDataForKey:key] displayName];
185
186 if (!displayName) {
187 NSLog(@"I could not figure out the name of this page!");
188 NSBeep();
189 return;
190 }
191
bb20314 @ccgus Changed up the VoodooPad plugin a bit, it does more.
authored
192 NSString *name = [NSString stringWithFormat:@"%@.jstalk", displayName];
ee99867 @ccgus oh geeze
authored
193
194 NSSavePanel *savePanel = [NSSavePanel savePanel];
195
196 [savePanel setPrompt:NSLocalizedString(@"Save", @"Save")];
bb20314 @ccgus Changed up the VoodooPad plugin a bit, it does more.
authored
197 [savePanel setTitle:NSLocalizedString(@"Save as JSTalk Plugin", @"Save as JSTalk Plugin")];
ee99867 @ccgus oh geeze
authored
198
199 [savePanel beginSheetForDirectory:[self scriptsDir]
200 file:name
201 modalForWindow:[windowController window]
202 modalDelegate:self
203 didEndSelector:@selector(savePanelDidEndForSaveAsJavaScript:returnCode:contextInfo:)
204 contextInfo:windowController];
205 }
206
698bb6e @ccgus Little formatting updates, and a bit of experimentation.
authored
207 - (void)runScript:(NSString*)script withWindowController:(id<VPPluginWindowController>)windowController {
bb20314 @ccgus Changed up the VoodooPad plugin a bit, it does more.
authored
208
209 JSTalk *jstalk = [[[JSTalk alloc] init] autorelease];
210
99e3e23 added the ability to call jstalk: javascript: urls, which will then e…
August Mueller authored
211 [jstalk pushObject:windowController withName:@"windowController"];
212 [jstalk pushObject:[windowController document] withName:@"document"];
bb20314 @ccgus Changed up the VoodooPad plugin a bit, it does more.
authored
213
214 JSCocoaController *jsController = [jstalk jsController];
215
216 jsController.delegate = self;
217
218 jstalk.printController = self;
219
220 [jstalk executeString:script];
221
222 }
223
698bb6e @ccgus Little formatting updates, and a bit of experimentation.
authored
224 - (void)handleRunAsJavaScript:(id<VPPluginWindowController>)windowController {
ee99867 @ccgus oh geeze
authored
225
226 _nonRetainedCurrentTextView = [windowController textView];
227
228 NSString *buffer = [[[windowController textView] textStorage] mutableString];
229
230 NSRange r = [[windowController textView] selectedRange];
231 if (r.length > 0) {
232 buffer = [buffer substringWithRange:r];
233
234 // now put the insertion point at the end of the selection.
235 r.location += r.length;
236 r.length = 0;
237 [[windowController textView] setSelectedRange:r];
238 }
239
bb20314 @ccgus Changed up the VoodooPad plugin a bit, it does more.
authored
240 [self runScript:buffer withWindowController:windowController];
ee99867 @ccgus oh geeze
authored
241
242 _nonRetainedCurrentTextView = 0x00;
243
244 }
245
246
247
698bb6e @ccgus Little formatting updates, and a bit of experimentation.
authored
248 - (void)handleRunScript:(id<VPPluginWindowController>)windowController userObject:(id)userObject {
ee99867 @ccgus oh geeze
authored
249 // todo
bb20314 @ccgus Changed up the VoodooPad plugin a bit, it does more.
authored
250
251 NSError *err = 0x00;
252 NSString *script = [NSString stringWithContentsOfFile:userObject encoding:NSUTF8StringEncoding error:&err];
253
254 if (!script) {
255 NSLog(@"Could not read script: %@", err);
256 return;
257 }
258
259 [self runScript:script withWindowController:windowController];
ee99867 @ccgus oh geeze
authored
260 }
261
262
263
698bb6e @ccgus Little formatting updates, and a bit of experimentation.
authored
264 - (NSDictionary*)propertiesFromScriptAtPath:(NSString*)path {
ee99867 @ccgus oh geeze
authored
265
bb20314 @ccgus Changed up the VoodooPad plugin a bit, it does more.
authored
266 NSMutableString *s = [NSMutableString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
ee99867 @ccgus oh geeze
authored
267 if (!s) {
268 return nil;
269 }
270
271 // clean up some line endings.
272 [s replaceOccurrencesOfString:@"\r\n" withString:@"\n" options:0 range:NSMakeRange(0, [s length])];
273 [s replaceOccurrencesOfString:@"\r" withString:@"\n" options:0 range:NSMakeRange(0, [s length])];
274
275 NSMutableDictionary *d = [NSMutableDictionary dictionary];
276 NSString *lang = 0x00;
277 NSString *menuTitle = 0x00;
278 NSString *shortcutKey = @"";
279 NSString *superMenuTitle = nil;
280 int shortcutMask = 0x00;
281 BOOL backgroundThread = 0x00;
282 NSEnumerator *enumerator = [[s componentsSeparatedByString:@"\n"] objectEnumerator];
283 NSString *line;
284
285 while ((line = [enumerator nextObject])) {
286
287 if ([line hasPrefix:@"VPEndConfig"]) {
288 break;
289 }
290 else if ([line hasPrefix:VPLanguageKey]) {
bb20314 @ccgus Changed up the VoodooPad plugin a bit, it does more.
authored
291 NSInteger eqIdx = [line rangeOfString:@"="].location;
ee99867 @ccgus oh geeze
authored
292 if (eqIdx != NSNotFound && [line length] > eqIdx + 1) {
293 lang = [[line substringFromIndex:eqIdx+1]
294 stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
295 }
296 }
297 else if ([line hasPrefix:VPScriptMenuTitleKey]) {
bb20314 @ccgus Changed up the VoodooPad plugin a bit, it does more.
authored
298 NSInteger eqIdx = [line rangeOfString:@"="].location;
ee99867 @ccgus oh geeze
authored
299 if (eqIdx != NSNotFound && [line length] > eqIdx + 1) {
300 menuTitle = [[line substringFromIndex:eqIdx+1]
301 stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
302 }
303 }
304 else if ([line hasPrefix:VPScriptSuperMenuTitleKey]) {
bb20314 @ccgus Changed up the VoodooPad plugin a bit, it does more.
authored
305 NSInteger eqIdx = [line rangeOfString:@"="].location;
ee99867 @ccgus oh geeze
authored
306 if (eqIdx != NSNotFound && [line length] > eqIdx + 1) {
307 superMenuTitle = [[line substringFromIndex:eqIdx+1]
308 stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
309 }
310 }
311 else if ([line hasPrefix:VPBackgroundThreadKey]) {
bb20314 @ccgus Changed up the VoodooPad plugin a bit, it does more.
authored
312 NSInteger eqIdx = [line rangeOfString:@"="].location;
ee99867 @ccgus oh geeze
authored
313 if (eqIdx != NSNotFound && [line length] > eqIdx + 1) {
314
315 NSString *junk = [[line substringFromIndex:eqIdx+1] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
316 backgroundThread = [@"true" isEqualToString:junk];
317 }
318 }
319 else if ([line hasPrefix:VPShortcutKeyKey]) {
bb20314 @ccgus Changed up the VoodooPad plugin a bit, it does more.
authored
320 NSInteger eqIdx = [line rangeOfString:@"="].location;
ee99867 @ccgus oh geeze
authored
321 if (eqIdx != NSNotFound && [line length] > eqIdx + 1) {
322 shortcutKey = [[line substringFromIndex:eqIdx+1]
323 stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
324 }
325 }
326 else if ([line hasPrefix:VPShortcutMaskKey]) {
bb20314 @ccgus Changed up the VoodooPad plugin a bit, it does more.
authored
327 NSInteger eqIdx = [line rangeOfString:@"="].location;
ee99867 @ccgus oh geeze
authored
328 if (eqIdx != NSNotFound && [line length] > eqIdx + 1) {
329 NSString *junk = [[line substringFromIndex:eqIdx+1]
330 stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
331
332 junk = [junk lowercaseString];
333
334 if ([junk rangeOfString:@"command"].location != NSNotFound) {
335 shortcutMask = shortcutMask | NSCommandKeyMask;
336 }
337 if ([junk rangeOfString:@"option"].location != NSNotFound) {
338 shortcutMask = shortcutMask | NSAlternateKeyMask;
339 }
340 if ([junk rangeOfString:@"shift"].location != NSNotFound) {
341 shortcutMask = shortcutMask | NSShiftKeyMask;
342 }
343 if ([junk rangeOfString:@"control"].location != NSNotFound) {
344 shortcutMask = shortcutMask | NSControlKeyMask;
345 }
346 }
347 }
348 }
349
350 if (lang) {
351 [d setObject:lang forKey:VPLanguageKey];
352 }
bb20314 @ccgus Changed up the VoodooPad plugin a bit, it does more.
authored
353
ee99867 @ccgus oh geeze
authored
354 if (menuTitle) {
355 [d setObject:menuTitle forKey:VPScriptMenuTitleKey];
356 }
357 if (superMenuTitle) {
358 [d setObject:superMenuTitle forKey:VPScriptSuperMenuTitleKey];
359 }
360 if (shortcutKey) {
361 [d setObject:shortcutKey forKey:VPShortcutKeyKey];
362 }
363
364 [d setObject:[NSNumber numberWithBool:backgroundThread] forKey:VPBackgroundThreadKey];
365 [d setObject:[NSNumber numberWithInt:shortcutMask] forKey:VPShortcutMaskKey];
366
367 return d;
368 }
369
698bb6e @ccgus Little formatting updates, and a bit of experimentation.
authored
370 - (void)registerScript:(NSString*)scriptPath {
ee99867 @ccgus oh geeze
authored
371
bb20314 @ccgus Changed up the VoodooPad plugin a bit, it does more.
authored
372 NSMutableString *s = [NSMutableString stringWithContentsOfFile:scriptPath encoding:NSUTF8StringEncoding error:nil];
ee99867 @ccgus oh geeze
authored
373 if (!s) {
374 return;
375 }
376
377 id <VPPluginManager> pluginManager = [self pluginManager];
378 NSDictionary *scriptProperties = [self propertiesFromScriptAtPath:scriptPath];
379
bb20314 @ccgus Changed up the VoodooPad plugin a bit, it does more.
authored
380 if (!([scriptPath hasSuffix:@".jstalk"] || [scriptPath hasSuffix:@".jscocoa"] || [scriptPath hasSuffix:@".javascript"] || [scriptPath hasSuffix:@".js"])){
ee99867 @ccgus oh geeze
authored
381 return;
382 }
383
384 NSString *menuTitle = [scriptProperties objectForKey:VPScriptMenuTitleKey];
bb20314 @ccgus Changed up the VoodooPad plugin a bit, it does more.
authored
385 menuTitle = menuTitle ? menuTitle : [[scriptPath lastPathComponent] stringByDeletingPathExtension];
ee99867 @ccgus oh geeze
authored
386 NSString *shortcutKey = [scriptProperties objectForKey:VPShortcutKeyKey];
387 shortcutKey = shortcutKey ? shortcutKey : @"";
388 NSString *superMenuTitle = [scriptProperties objectForKey:VPScriptSuperMenuTitleKey];
389 int shortcutMask = [[scriptProperties objectForKey:VPShortcutMaskKey] intValue];
390
bb20314 @ccgus Changed up the VoodooPad plugin a bit, it does more.
authored
391 superMenuTitle = superMenuTitle ? superMenuTitle : @"JSTalk";
392
ee99867 @ccgus oh geeze
authored
393 [pluginManager addPluginsMenuTitle:menuTitle
394 withSuperMenuTitle:superMenuTitle
395 target:self
396 action:@selector(handleRunScript:userObject:)
397 keyEquivalent:shortcutKey
398 keyEquivalentModifierMask:shortcutMask
399 userObject:[scriptPath retain]];
400
401 }
402
698bb6e @ccgus Little formatting updates, and a bit of experimentation.
authored
403 - (NSString*)scriptsDir {
ee99867 @ccgus oh geeze
authored
404
405 NSString *scriptPluginDir = [@"~/Library/Application Support/VoodooPad/Script PlugIns" stringByExpandingTildeInPath];
406 BOOL isDir;
407 NSFileManager *fm = [NSFileManager defaultManager];
408 if ([fm fileExistsAtPath:scriptPluginDir isDirectory:&isDir] && isDir) {
409 return scriptPluginDir;
410 }
411
412 if ([fm createDirectoryAtPath:scriptPluginDir attributes:nil]) {
413 return scriptPluginDir;
414 }
415
416 return nil;
417 }
418
419
420
698bb6e @ccgus Little formatting updates, and a bit of experimentation.
authored
421 - (void)print:(NSString*)s {
ee99867 @ccgus oh geeze
authored
422 [[NSApp delegate] console:s];
423 }
424
698bb6e @ccgus Little formatting updates, and a bit of experimentation.
authored
425 - (void)JSCocoa:(JSCocoaController*)controller hadError:(NSString*)error onLineNumber:(NSInteger)lineNumber atSourceURL:(id)url {
ee99867 @ccgus oh geeze
authored
426
cbdc2a9 @ccgus [UPDATES] General code cleanup for the Acorn and VoodooPad sample plu…
authored
427 lineNumber -= 1;
ee99867 @ccgus oh geeze
authored
428
429 if (!error) {
430 return;
431 }
432
433 if (lineNumber < 0) {
434 [self print:error];
435 }
436 else {
437 [self print:[NSString stringWithFormat:@"Line %d, %@", lineNumber, error]];
438
bb20314 @ccgus Changed up the VoodooPad plugin a bit, it does more.
authored
439 if (_nonRetainedCurrentTextView) {
ee99867 @ccgus oh geeze
authored
440
bb20314 @ccgus Changed up the VoodooPad plugin a bit, it does more.
authored
441 NSUInteger lineIdx = 0;
442 NSRange lineRange = NSMakeRange(0, 0);
443
444 while (lineIdx < lineNumber) {
445
446 lineRange = [[[_nonRetainedCurrentTextView textStorage] string] lineRangeForRange:NSMakeRange(NSMaxRange(lineRange), 0)];
447 lineIdx++;
448 }
449
450 if (lineRange.length) {
451 [_nonRetainedCurrentTextView showFindIndicatorForRange:lineRange];
452 }
ee99867 @ccgus oh geeze
authored
453 }
454 }
455 }
456
698bb6e @ccgus Little formatting updates, and a bit of experimentation.
authored
457 - (BOOL)validateAction:(SEL)anAction forPageType:(NSString*)pageType userObject:(id)userObject {
c62d72f @ccgus Added an editor for jstalk
authored
458 return YES;
459 }
ee99867 @ccgus oh geeze
authored
460
698bb6e @ccgus Little formatting updates, and a bit of experimentation.
authored
461
462
463 @end
464
465 @interface NSApplication (JSTalkExtras)
466
467 @end
468
781aade @ccgus Made a change to the preprocessor to support inline functions, which …
authored
469 // These next guys are private APIs that I use in VoodooPad for testing purposes.
470 // Just ignore!
698bb6e @ccgus Little formatting updates, and a bit of experimentation.
authored
471 @implementation NSApplication (JSTalkExtras)
472
781aade @ccgus Made a change to the preprocessor to support inline functions, which …
authored
473 + (id)newErrorBlockForJSFunction:(JSValueRefAndContextRef)callbackFunction {
698bb6e @ccgus Little formatting updates, and a bit of experimentation.
authored
474
781aade @ccgus Made a change to the preprocessor to support inline functions, which …
authored
475 JSContextRef mainContext = [[JSCocoa controllerFromContext:callbackFunction.ctx] ctx];
476 JSValueProtect(mainContext, callbackFunction.value);
698bb6e @ccgus Little formatting updates, and a bit of experimentation.
authored
477 void (^theBlock)(NSError *) = ^(NSError *err) {
781aade @ccgus Made a change to the preprocessor to support inline functions, which …
authored
478 [[JSCocoa controllerFromContext:mainContext] callJSFunction:callbackFunction.value withArguments:[NSArray arrayWithObjects:err, nil]];
698bb6e @ccgus Little formatting updates, and a bit of experimentation.
authored
479 };
480
481 return [theBlock copy];
482 }
483
484 + (void)testFunction:(void (^)(NSError *))theBlock {
485
486 theBlock(nil);
487
488 }
489
781aade @ccgus Made a change to the preprocessor to support inline functions, which …
authored
490 + (void)runInBackground:(JSValueRefAndContextRef)callbackFunction {
491
492 JSContextRef mainContext = [[JSCocoa controllerFromContext:callbackFunction.ctx] ctx];
493 JSValueProtect(mainContext, callbackFunction.value);
494 dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
495 [[JSCocoa controllerFromContext:mainContext] callJSFunction:callbackFunction.value withArguments:nil];
496 });
497 }
698bb6e @ccgus Little formatting updates, and a bit of experimentation.
authored
498
499
ee99867 @ccgus oh geeze
authored
500 @end
698bb6e @ccgus Little formatting updates, and a bit of experimentation.
authored
501
502
503
504
505
506
507
508
509
510
511
Something went wrong with that request. Please try again.