Permalink
Browse files

Add the ability to make the indirect arg optional

return `3` in the `get argument count` handler
  • Loading branch information...
1 parent 00d0aba commit 2461394d7d495c0cb2581c1605b0838aa7919c01 @pjrobertson committed Feb 1, 2013
View
58 Quicksilver/PlugIns-Main/QSCorePlugIn/Code/QSAppleScriptActions.m
@@ -36,6 +36,9 @@ - (QSAction *)scriptActionForPath:(NSString *)path {
NSArray *validDirectTypes = [self validDirectTypesForScript:path];
NSArray *validIndirectTypes = [self validIndrectTypesForScript:path];
+ // get the argument count of the script. 1 = dObj only. 2 = dObj + iObj. 3 = indirect Optional
+ NSInteger argumentCount = [self argumentCountForScript:path];
+
if ([handlers containsObject:@"aevtodoc"] || [handlers containsObject:@"DAEDopfl"]) {
// Only set the type if the user hasn't specified any (i.e. hasn't set the 'get direct types' handler)
if (!validDirectTypes) {
@@ -62,6 +65,12 @@ - (QSAction *)scriptActionForPath:(NSString *)path {
if ([validIndirectTypes count]) {
[actionDict setObject:validIndirectTypes forKey:kActionIndirectTypes];
}
+ if (argumentCount == 3) {
+ // argumentCount == 3 means indirect optional
+ [actionDict setObject:[NSNumber numberWithBool:YES] forKey:kActionIndirectOptional];
+ argumentCount = 2;
+ }
+ [actionDict setObject:[NSNumber numberWithInteger:argumentCount] forKey:kActionArgumentCount];
NSString *actionName = [[path lastPathComponent] stringByDeletingPathExtension];
QSAction *action = [QSAction actionWithDictionary:actionDict identifier:[kAppleScriptActionIDPrefix stringByAppendingString:path]];
@@ -300,7 +309,7 @@ - (NSArray *)validIndirectObjectsForAction:(NSString *)action directObject:(QSOb
}
-(NSArray *)validIndirectObjectsForAppleScript:(NSString *)script directObject:(QSObject *)dObject {
- NSString *scriptPath = [script substringFromIndex:[kAppleScriptActionIDPrefix length]];
+ NSString *scriptPath = [self scriptPathForID:script];
id indirectTypes = [self validIndrectTypesForScript:scriptPath];
if (indirectTypes) {
@@ -312,24 +321,42 @@ -(NSArray *)validIndirectObjectsForAppleScript:(NSString *)script directObject:(
}
return nil;
}
-
-- (NSInteger)argumentCountForAction:(NSString *)actionId {
- NSInteger argumentCount = 1;
+
+-(NSString *)scriptPathForID:(NSString *)actionId {
QSAction *action = [QSAction actionWithIdentifier:actionId];
NSString *scriptPath = [action objectForKey:kActionScript];
+
+ if (!scriptPath) {
+ return nil;
+ }
- if ([actionId isEqualToString:kAppleScriptOpenTextAction] || [actionId isEqualToString:kAppleScriptOpenFilesAction])
- argumentCount = 2;
+ if ([scriptPath hasPrefix:@"/"] || [scriptPath hasPrefix:@"~"]) {
+ scriptPath = [scriptPath stringByStandardizingPath];
+ } else {
+ scriptPath = [[action bundle] pathForResource:[scriptPath stringByDeletingPathExtension] ofType:[scriptPath pathExtension]];
+ }
+ return scriptPath;
+}
+
+- (NSInteger)argumentCountForAction:(NSString *)actionId {
+
+ if ([actionId isEqualToString:kAppleScriptOpenTextAction] || [actionId isEqualToString:kAppleScriptOpenFilesAction]) {
+ return 2;
+ }
+
+ NSString *scriptPath = [self scriptPathForID:actionId];
+ if (!scriptPath) {
+ // can't find the script so just return 1 and hope for the best
+ return 1;
+ }
- // TODO: figure out why all this code is here - scriptPath always seems to be nil
+ // this should never realistically be called, since the script argument count is set in scriptActionForPath: (above)
+ return [self argumentCountForScript:scriptPath] > 1 ? 2 : 1;
+}
- if (!scriptPath)
- return argumentCount;
- if ([scriptPath hasPrefix:@"/"] || [scriptPath hasPrefix:@"~"])
- scriptPath = [scriptPath stringByStandardizingPath];
- else
- scriptPath = [[action bundle] pathForResource:[scriptPath stringByDeletingPathExtension] ofType:[scriptPath pathExtension]];
+-(NSInteger)argumentCountForScript:(NSString *)scriptPath {
+ NSInteger argumentCount = 1;
NSArray *handlers = [NSAppleScript validHandlersFromArray:[NSArray arrayWithObject:@"DAEDgarc"] inScriptFile:scriptPath];
if( handlers != nil && [handlers count] != 0 ) {
@@ -353,14 +380,9 @@ - (NSInteger)argumentCountForAction:(NSString *)actionId {
[script release];
}
-
-#ifdef DEBUG
- NSLog(@"argument count for %@ is %ld", actionId, (long)argumentCount);
-#endif
return argumentCount;
}
-
// Retrieves an array of types from either the 'get direct types' or 'get indirect types' AppleScript handlers (depending on the input parameter 'handler')
-(NSArray *)typeArrayForScript:(NSString *)scriptPath forHandler:(NSString *)handler {
View
2 Quicksilver/Scripting/Quicksilver.sdef
@@ -87,7 +87,7 @@
<parameter name="with" code="IdOb" description="indirect object" type="any" optional="yes"/>
<result description="value to return to Quicksilver" type="any"/>
</command>
- <command name="get argument count" code="DAEDgarc" description="Get the argument count for this action. Scripts with this handler can customize their argument count. Valid values are 1, 2.">
+ <command name="get argument count" code="DAEDgarc" description="Get the argument count for this action. Scripts with this handler can customize their argument count. Valid values are: 1 = 1st pane only; 2 = 1st pane and 3rd pane; 3 = 1st pane, and 3rd pane (optional).">
<cocoa class="NSScriptCommand"/>
<result description="value to return to Quicksilver" type="integer"/>
</command>
View
2 Quicksilver/Scripting/QuicksilverHandlers.scriptTerminology
@@ -7,7 +7,7 @@
<key>GetArgumentCount</key>
<dict>
<key>Description</key>
- <string>Get the argument count for this action. Scripts with this handler can customize their argument count. Valid values are 1, 2.</string>
+ <string>Get the argument count for this action. Scripts with this handler can customize their argument count. Valid values are: 1 = 1st pane only; 2 = 1st pane and 3rd pane; 3 = 1st pane, and 3rd pane (optional).</string>
<key>Name</key>
<string>get argument count</string>
</dict>
View
2 Quicksilver/Scripting/QuicksilverScripting.r
@@ -507,7 +507,7 @@ resource 'aete' (0, "Quicksilver") {
},
"get argument count",
- "Get the argument count for this action. Scripts with this handler can customize their argument count. Valid values are 1, 2.",
+ "Get the argument count for this action. Scripts with this handler can customize their argument count. Valid values are: 1 = 1st pane only; 2 = 1st pane and 3rd pane; 3 = 1st pane, and 3rd pane (optional).",
'DAED', 'garc',
'long',
"value to return to Quicksilver",

0 comments on commit 2461394

Please sign in to comment.