Permalink
Browse files

Added a service for getting the results of a JSTalk script. Think: si…

…mple addition in interface builder or anywhere else.
  • Loading branch information...
ccgus committed Nov 19, 2010
1 parent 1da357c commit 37c98b1927d34348be1bb23cef5db254940981aa
Showing with 98 additions and 3 deletions.
  1. +1 −1 jstalk.xcodeproj/project.pbxproj
  2. +34 −0 res/Info.plist
  3. +1 −1 src/JSTAppDelegate.h
  4. +61 −0 src/JSTAppDelegate.m
  5. +1 −1 src/JSTalk.m
@@ -427,7 +427,7 @@
CC975BC70F47E5BD00097108 /* JSTPreprocessor.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = JSTPreprocessor.m; path = src/JSTPreprocessor.m; sourceTree = "<group>"; };
CCA69D561203BE0300C23AE7 /* jslint-jscocoa.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; name = "jslint-jscocoa.js"; path = "jscocoa/JSCocoa/jslint-jscocoa.js"; sourceTree = "<group>"; };
CCC5B8A40F1EFA6D00126722 /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = /System/Library/Frameworks/JavaScriptCore.framework; sourceTree = "<absolute>"; };
- CCC5B8B00F1EFA9700126722 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = res/Info.plist; sourceTree = "<group>"; };
+ CCC5B8B00F1EFA9700126722 /* Info.plist */ = {isa = PBXFileReference; explicitFileType = text.xml; fileEncoding = 4; name = Info.plist; path = res/Info.plist; sourceTree = "<group>"; };
CCC5B8BB0F1EFA9700126722 /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = res/English.lproj/JSTDocument.xib; sourceTree = "<group>"; };
CCC5B8BF0F1EFA9700126722 /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = res/English.lproj/MainMenu.xib; sourceTree = "<group>"; };
CCC5B8C10F1EFA9700126722 /* English */ = {isa = PBXFileReference; lastKnownFileType = text.rtf; name = English; path = res/English.lproj/Credits.rtf; sourceTree = "<group>"; };
View
@@ -115,5 +115,39 @@
</dict>
</dict>
</array>
+
+
+
+ <key>NSServices</key>
+ <array>
+
+ <dict>
+ <key>NSKeyEquivalent</key>
+ <dict>
+ <key>default</key>
+ <string>5</string>
+ </dict>
+ <key>NSMenuItem</key>
+ <dict>
+ <key>default</key>
+ <string>Get Result of JSTalk Script</string>
+ </dict>
+ <key>NSMessage</key>
+ <string>runAsJSTalkScript</string>
+ <key>NSPortName</key>
+ <string>JSTalk Editor</string>
+ <key>NSReturnTypes</key>
+ <array>
+ <string>NSRTFDPboardType</string>
+ <string>NSRTFPboardType</string>
+ <string>NSStringPboardType</string>
+ </array>
+ <key>NSSendTypes</key>
+ <array>
+ <string>NSStringPboardType</string>
+ </array>
+ </dict>
+ </array>
+
</dict>
</plist>
View
@@ -17,7 +17,7 @@
IBOutlet NSMenu *statusMenu;
NSStatusItem *statusItem;
-
+ NSString *_serviceError;
}
- (void)chooseExternalEditor:(id)sender;
View
@@ -47,6 +47,13 @@ - (void)awakeFromNib {
[JSTalk listen];
NSSetUncaughtExceptionHandler(JSTUncaughtExceptionHandler);
+
+
+ // register this object to handle the services stuff.
+ [NSApp setServicesProvider:self];
+
+ // have all the services menus get updated.
+ //NSUpdateDynamicServices();
}
- (IBAction)showPrefs:(id)sender {
@@ -210,4 +217,58 @@ - (NSFont*)defaultEditorFont {
return defaultFont;
}
+- (void)JSCocoa:(JSCocoaController*)controller hadError:(NSString*)error onLineNumber:(NSInteger)lineNumber atSourceURL:(id)url {
+ _serviceError = [error retain];
+}
+
+
+- (void)runAsJSTalkScript:(NSPasteboard *)pb userData:(NSDictionary *)userData error:(NSString **)error {
+
+ _serviceError = 0x00;
+
+ // Test for strings on the pasteboard.
+ NSArray *classes = [NSArray arrayWithObject:[NSString class]];
+ NSDictionary *options = [NSDictionary dictionary];
+ if (![pb canReadObjectForClasses:classes options:options]) {
+ *error = NSLocalizedString(@"Error: couldn't read the text.", @"pboard couldn't give string.");
+ return;
+ }
+
+ NSString *result = 0x00;
+ NSString *script = [pb stringForType:NSPasteboardTypeString];
+
+ @try {
+
+ JSTalk *jstalk = [[JSTalk alloc] init];
+
+ JSCocoaController *jsController = [jstalk jsController];
+ jsController.delegate = self;
+
+ [[[NSThread currentThread] threadDictionary] setObject:jstalk forKey:@"org.jstalk.currentJSTalkContext"];
+
+ result = [[jstalk executeString:script] description];
+
+ [[[NSThread currentThread] threadDictionary] removeObjectForKey:@"org.jstalk.currentJSTalkContext"];
+
+ [jstalk release];
+
+ }
+ @catch (NSException *e) {
+ *error = [e reason];
+ return;
+ }
+
+ if (_serviceError) {
+ result = _serviceError;
+ }
+
+ [pb clearContents];
+
+ if (result) {
+ [pb writeObjects:[NSArray arrayWithObject:result]];
+ }
+
+ [_serviceError autorelease];
+}
+
@end
View
@@ -191,7 +191,7 @@ - (void)deleteObjectWithName:(NSString*)name {
}
-- (id)executeString:(NSString*) str {
+- (id)executeString:(NSString*)str {
if (!JSTalkPluginList && JSTalkShouldLoadJSTPlugins) {
[self loadPlugins];

0 comments on commit 37c98b1

Please sign in to comment.