Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

New JSTalk filter stuff.

  • Loading branch information...
commit 02df5db535f84e4d3a38f316d0c62160f823f2bc 1 parent c00dc51
August "Gus" Mueller authored August 20, 2012
14  plugins/acornplugin/ACPlugin.h
@@ -30,6 +30,7 @@ enum {
30 30
 @protocol ACBitmapTool;
31 31
 @protocol ACImageIOProvider;
32 32
 @protocol ACImageFilter;
  33
+@protocol ACLayer;
33 34
 
34 35
 @protocol ACPluginManager
35 36
 
@@ -90,6 +91,19 @@ enum {
90 91
  */
91 92
 - (NSNumber*)worksOnShapeLayers:(id)userObject;
92 93
 
  94
+
  95
+/*
  96
+ How about a more general type of "do you work on this type of layer" question:
  97
+ 
  98
+ return [NSNumber numberWithBool:YES];
  99
+ 
  100
+ NSNumber is used to be friendly with scripting languages.
  101
+ 
  102
+ Added in version 3.5
  103
+ 
  104
+ */
  105
+- (NSNumber*)validateForLayer:(id<ACLayer>)layer;
  106
+
93 107
 @end
94 108
 
95 109
 
62  plugins/acornplugin/JSEnablerPlugIn.m
@@ -6,11 +6,14 @@
6 6
 #import "JSEnablerPlugIn.h"
7 7
 #import "ACPlugin.h"
8 8
 #import "JSTalk.h"
  9
+#import "JSCocoa.h"
  10
+#import <JavaScriptCore/JavaScriptCore.h>
9 11
 
10 12
 #define ACScriptMenuTitleKey @"ACScriptMenuTitle"
11 13
 #define ACScriptSuperMenuTitleKey @"ACScriptSuperMenuTitle"
12 14
 #define ACShortcutKeyKey @"ACShortcutKey"
13 15
 #define ACShortcutMaskKey @"ACShortcutMask"
  16
+#define ACIsActionKey @"ACIsAction"
14 17
 
15 18
 @interface JSEnablerPlugIn (SuperSecret)
16 19
 - (void)findJSCocoaScriptsForPluginManager:(id<ACPluginManager>)pluginManager;
@@ -48,12 +51,13 @@ - (NSDictionary*)propertiesFromScriptAtPath:(NSString*)path {
48 51
     [s replaceOccurrencesOfString:@"\r" withString:@"\n" options:0 range:NSMakeRange(0, [s length])];
49 52
     
50 53
     NSMutableDictionary *d              = [NSMutableDictionary dictionary];
51  
-    NSString *menuTitle                 = 0x00;
  54
+    NSString *menuTitle                 = nil;
52 55
     NSString *shortcutKey               = @"";
53 56
     NSString *superMenuTitle            = nil;
54  
-    int shortcutMask                    = 0x00;
  57
+    int shortcutMask                    = 0;
55 58
     NSEnumerator *enumerator            = [[s componentsSeparatedByString:@"\n"] objectEnumerator];
56 59
     NSString *line;
  60
+    BOOL isAction                       = NO;
57 61
     
58 62
     while ((line = [enumerator nextObject])) {
59 63
     	
@@ -81,6 +85,14 @@ - (NSDictionary*)propertiesFromScriptAtPath:(NSString*)path {
81 85
                                stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
82 86
             }
83 87
         }
  88
+        else if ([line hasPrefix:ACIsActionKey]) {
  89
+            int eqIdx = [line rangeOfString:@"="].location;
  90
+            if (eqIdx != NSNotFound && [line length] > eqIdx + 1) {
  91
+                NSString *val = [[line substringFromIndex:eqIdx+1]
  92
+                               stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
  93
+                isAction = [val boolValue];
  94
+            }
  95
+        }
84 96
         else if ([line hasPrefix:ACShortcutMaskKey]) {
85 97
             int eqIdx = [line rangeOfString:@"="].location;
86 98
             if (eqIdx != NSNotFound && [line length] > eqIdx + 1) {
@@ -119,6 +131,7 @@ - (NSDictionary*)propertiesFromScriptAtPath:(NSString*)path {
119 131
     }
120 132
     
121 133
     [d setObject:[NSNumber numberWithInt:shortcutMask] forKey:ACShortcutMaskKey];
  134
+    [d setObject:[NSNumber numberWithBool:isAction] forKey:ACIsActionKey];
122 135
     
123 136
     return d;
124 137
 }
@@ -153,13 +166,25 @@ - (void)findJSCocoaScriptsForPluginManager:(id<ACPluginManager>)pluginManager {
153 166
         NSUInteger shortcutMask             = [[scriptProperties objectForKey:ACShortcutMaskKey] unsignedIntegerValue];
154 167
         
155 168
         
156  
-        [pluginManager addFilterMenuTitle:menuTitle
157  
-                       withSuperMenuTitle:superMenuTitle
158  
-                                   target:self
159  
-                                   action:@selector(executeScriptForImage:scriptPath:)
160  
-                            keyEquivalent:shortcutKey
161  
-                keyEquivalentModifierMask:shortcutMask
162  
-                               userObject:[pluginDir stringByAppendingPathComponent:fileName]];
  169
+        if ([[scriptProperties objectForKey:ACIsActionKey] boolValue]) {
  170
+            [pluginManager addActionMenuTitle:menuTitle
  171
+                           withSuperMenuTitle:superMenuTitle
  172
+                                       target:self
  173
+                                       action:@selector(executeScriptForImage:scriptPath:)
  174
+                                keyEquivalent:shortcutKey
  175
+                    keyEquivalentModifierMask:shortcutMask
  176
+                                   userObject:[pluginDir stringByAppendingPathComponent:fileName]];
  177
+        }
  178
+        else {
  179
+            
  180
+            [pluginManager addFilterMenuTitle:menuTitle
  181
+                           withSuperMenuTitle:superMenuTitle
  182
+                                       target:self
  183
+                                       action:@selector(executeScriptForImage:scriptPath:)
  184
+                                keyEquivalent:shortcutKey
  185
+                    keyEquivalentModifierMask:shortcutMask
  186
+                                   userObject:[pluginDir stringByAppendingPathComponent:fileName]];
  187
+        }
163 188
     }
164 189
 }
165 190
 
@@ -192,13 +217,30 @@ function main(image, doc, layer) {
192 217
     
193 218
     id document = [(id)currentLayer valueForKey:@"document"]; // shh!
194 219
     
195  
-    return [jstalk callFunctionNamed:@"main" withArguments:[NSArray arrayWithObjects:image, document, currentLayer, nil]];
  220
+    JSValueRef returnValue = [[jstalk jsController] callJSFunctionNamed:@"main" withArguments:image, document, currentLayer, nil];
  221
+    
  222
+    // Hurray?
  223
+    // The main() method should be returning a value at this point, so we're going to 
  224
+    // put it back into a cocoa object.  If it's not there, then it'll be nil and that's 
  225
+    // ok for our purposes.
  226
+    CIImage *acornReturnValue = 0x00;
  227
+    
  228
+    if (![JSCocoaFFIArgument unboxJSValueRef:returnValue toObject:&acornReturnValue inContext:[[jstalk jsController] ctx]]) {
  229
+        return nil;
  230
+    }
  231
+    
  232
+    // fin.
  233
+    return acornReturnValue;
196 234
 }
197 235
 
198 236
 - (NSNumber*)worksOnShapeLayers:(id)userObject {
199 237
     return [NSNumber numberWithBool:YES];
200 238
 }
201 239
 
  240
+- (NSNumber*)validateForLayer:(id)userObject {
  241
+    return [NSNumber numberWithBool:YES];
  242
+}
  243
+
202 244
 @end
203 245
 
204 246
 

0 notes on commit 02df5db

Please sign in to comment.
Something went wrong with that request. Please try again.