Revision: 12369
          http://bibdesk.svn.sourceforge.net/bibdesk/?rev=12369&view=rev
Author:   hofman
Date:     2008-01-08 09:51:09 -0800 (Tue, 08 Jan 2008)

Log Message:
-----------
Allow passing a URL for template parsing from AppleScript.

Modified Paths:
--------------
    trunk/bibdesk/BDSKExportUsingTemplateCommand.m
    trunk/bibdesk/BDSKTemplatedTextCommand.m
    trunk/bibdesk/Scripting/BibDesk.sdef

Modified: trunk/bibdesk/BDSKExportUsingTemplateCommand.m
===================================================================
--- trunk/bibdesk/BDSKExportUsingTemplateCommand.m      2008-01-08 17:38:28 UTC 
(rev 12368)
+++ trunk/bibdesk/BDSKExportUsingTemplateCommand.m      2008-01-08 17:51:09 UTC 
(rev 12369)
@@ -71,16 +71,23 @@
        }
        
        // the 'using' parameters gives the template name to use
-       NSString *templateStyle = [params objectForKey:@"using"];
-       // make sure we get something
+       id templateStyle = [params objectForKey:@"using"];
+       BDSKTemplate *template = nil;
+    // make sure we get something
        if (!templateStyle) {
                [self 
setScriptErrorNumber:NSRequiredArgumentsMissingScriptError]; 
                return [NSArray array];
        }
        // make sure we get the right thing
-       if (![templateStyle isKindOfClass:[NSString class]] ) {
+       if ([templateStyle isKindOfClass:[NSString class]] ) {
+        template = [BDSKTemplate templateForStyle:templateStyle];
+       } else if ([templateStyle isKindOfClass:[NSURL class]] ) {
+        NSString *fileType = [[templateStyle path] pathExtension];
+        template = [BDSKTemplate templateWithName:@"" 
mainPageURL:templateStyle fileType:fileType ? fileType : @"txt"];
+       }
+    if (template == nil) {
                [self setScriptErrorNumber:NSArgumentsWrongScriptError]; 
-                       return nil;
+        return nil;
        }
        
        // the 'to' parameters gives the file to save to, either as a path or a 
url (it seems)
@@ -124,7 +131,6 @@
         items = publications;
     }
     
-    BDSKTemplate *template = [BDSKTemplate templateForStyle:templateStyle];
     NSData *fileData = nil;
     
     if ([template templateFormat] & BDSKRichTextTemplateFormat) {

Modified: trunk/bibdesk/BDSKTemplatedTextCommand.m
===================================================================
--- trunk/bibdesk/BDSKTemplatedTextCommand.m    2008-01-08 17:38:28 UTC (rev 
12368)
+++ trunk/bibdesk/BDSKTemplatedTextCommand.m    2008-01-08 17:51:09 UTC (rev 
12369)
@@ -71,17 +71,24 @@
                return @"";
        }
        
-       // the 'using' parameters gives the template name to use
-       NSString *templateStyle = [params objectForKey:@"using"];
-       // make sure we get something
+       // the 'using' parameters gives the template name or file to use
+       id templateStyle = [params objectForKey:@"using"];
+       BDSKTemplate *template = nil;
+    // make sure we get something
        if (!templateStyle) {
                [self 
setScriptErrorNumber:NSRequiredArgumentsMissingScriptError]; 
                return [NSArray array];
        }
        // make sure we get the right thing
-       if (![templateStyle isKindOfClass:[NSString class]] ) {
+       if ([templateStyle isKindOfClass:[NSString class]] ) {
+        template = [BDSKTemplate templateForStyle:templateStyle];
+       } else if ([templateStyle isKindOfClass:[NSURL class]] ) {
+        NSString *fileType = [[templateStyle path] pathExtension];
+        template = [BDSKTemplate templateWithName:@"" 
mainPageURL:templateStyle fileType:fileType ? fileType : @"txt"];
+       }
+    if (template == nil) {
                [self setScriptErrorNumber:NSArgumentsWrongScriptError]; 
-                       return @"";
+        return @"";
        }
        
        // the 'for' parameter can select the items to template
@@ -105,7 +112,6 @@
         items = publications;
     }
     
-    BDSKTemplate *template = [BDSKTemplate templateForStyle:templateStyle];
     NSString *templatedText = nil;
     
     if ([template templateFormat] & BDSKRichTextTemplateFormat) {
@@ -148,16 +154,23 @@
        }
        
        // the 'using' parameters gives the template name to use
-       NSString *templateStyle = [params objectForKey:@"using"];
-       // make sure we get something
+       id templateStyle = [params objectForKey:@"using"];
+       BDSKTemplate *template = nil;
+    // make sure we get something
        if (!templateStyle) {
                [self 
setScriptErrorNumber:NSRequiredArgumentsMissingScriptError]; 
                return [NSArray array];
        }
        // make sure we get the right thing
-       if (![templateStyle isKindOfClass:[NSString class]] ) {
+       if ([templateStyle isKindOfClass:[NSString class]] ) {
+        template = [BDSKTemplate templateForStyle:templateStyle];
+       } else if ([templateStyle isKindOfClass:[NSURL class]] ) {
+        NSString *fileType = [[templateStyle path] pathExtension];
+        template = [BDSKTemplate templateWithName:@"" 
mainPageURL:templateStyle fileType:fileType ? fileType : @"txt"];
+       }
+    if (template == nil) {
                [self setScriptErrorNumber:NSArgumentsWrongScriptError]; 
-                       return [[[NSTextStorage alloc] init] autorelease];;
+        return [[[NSTextStorage alloc] init] autorelease];;
        }
        
        // the 'for' parameter can select the items to template
@@ -181,8 +194,6 @@
         items = publications;
     }
     
-    BDSKTemplate *template = [BDSKTemplate templateForStyle:templateStyle];
-    
     if ([template templateFormat] & BDSKRichTextTemplateFormat) {
         NSAttributedString *templatedRichText = [BDSKTemplateObjectProxy 
attributedStringByParsingTemplate:template withObject:document 
publications:items documentAttributes:NULL];
         return [[[NSTextStorage alloc] 
initWithAttributedString:templatedRichText] autorelease];

Modified: trunk/bibdesk/Scripting/BibDesk.sdef
===================================================================
--- trunk/bibdesk/Scripting/BibDesk.sdef        2008-01-08 17:38:28 UTC (rev 
12368)
+++ trunk/bibdesk/Scripting/BibDesk.sdef        2008-01-08 17:51:09 UTC (rev 
12369)
@@ -883,8 +883,10 @@
             <cocoa name="templatedText" class="BDSKTemplatedTextCommand"/>
             <direct-parameter type="document"
                 description="The object responding to the command, the 
document."/>
-            <parameter name="using" code="usng" type="text"
-                description="The name of the template to use.">
+            <parameter name="using" code="usng"
+                description="The name or file of the template to use.">
+                <type type="text"/>
+                <type type="file"/>
                 <cocoa key="using"/>
             </parameter>
             <parameter name="for" code="for " optional="yes"
@@ -902,8 +904,10 @@
             <cocoa name="templatedRichText" 
class="BDSKTemplatedRichTextCommand"/>
             <direct-parameter type="document"
                 description="The object responding to the command, the 
document."/>
-            <parameter name="using" code="usng" type="text"
-                description="The name of the template to use.">
+            <parameter name="using" code="usng"
+                description="The name or file of the template to use.">
+                <type type="text"/>
+                <type type="file"/>
                 <cocoa key="using"/>
             </parameter>
             <parameter name="for" code="for " optional="yes"
@@ -921,8 +925,10 @@
             <cocoa name="exportUsingTemplate" 
class="BDSKExportUsingTemplateCommand"/>
             <direct-parameter type="document"
                 description="The object responding to the command, the 
document."/>
-            <parameter name="using template" code="uset" type="text"
-                description="The name of the template to use.">
+            <parameter name="using template" code="uset"
+                description="The name or file of the template to use.">
+                <type type="text"/>
+                <type type="file"/>
                 <cocoa key="using"/>
             </parameter>
             <parameter name="to" code="to  " type="file"


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit

Reply via email to