Revision: 12372
http://bibdesk.svn.sourceforge.net/bibdesk/?rev=12372&view=rev
Author: hofman
Date: 2008-01-08 11:12:08 -0800 (Tue, 08 Jan 2008)
Log Message:
-----------
Allow passing a template string for template parsing from AppleScript.
Modified Paths:
--------------
trunk/bibdesk/BDSKExportUsingTemplateCommand.m
trunk/bibdesk/BDSKTemplate.h
trunk/bibdesk/BDSKTemplate.m
trunk/bibdesk/BDSKTemplatedTextCommand.m
trunk/bibdesk/Scripting/BibDesk.sdef
Modified: trunk/bibdesk/BDSKExportUsingTemplateCommand.m
===================================================================
--- trunk/bibdesk/BDSKExportUsingTemplateCommand.m 2008-01-08 18:22:13 UTC
(rev 12371)
+++ trunk/bibdesk/BDSKExportUsingTemplateCommand.m 2008-01-08 19:12:08 UTC
(rev 12372)
@@ -72,11 +72,13 @@
// the 'using' parameters gives the template name to use
id templateStyle = [params objectForKey:@"using"];
+ id templateString = [params objectForKey:@"usingText"];
+ id templateAttrString = [params objectForKey:@"usingRichText"];
BDSKTemplate *template = nil;
// make sure we get something
- if (!templateStyle) {
+ if (templateStyle == nil && templateString == nil && templateAttrString
== nil) {
[self
setScriptErrorNumber:NSRequiredArgumentsMissingScriptError];
- return [NSArray array];
+ return nil;
}
// make sure we get the right thing
if ([templateStyle isKindOfClass:[NSString class]] ) {
@@ -84,7 +86,11 @@
} else if ([templateStyle isKindOfClass:[NSURL class]] ) {
NSString *fileType = [[templateStyle path] pathExtension];
template = [BDSKTemplate templateWithName:@""
mainPageURL:templateStyle fileType:fileType ? fileType : @"txt"];
- }
+ } else if ([templateString isKindOfClass:[NSString class]] ) {
+ template = [BDSKTemplate templateWithString:templateString
fileType:@"txt"];
+ } else if ([templateAttrString isKindOfClass:[NSAttributedString
class]] ) {
+ template = [BDSKTemplate
templateWithAttributedString:templateAttrString fileType:@"rtf"];
+ }
if (template == nil) {
[self setScriptErrorNumber:NSArgumentsWrongScriptError];
return nil;
Modified: trunk/bibdesk/BDSKTemplate.h
===================================================================
--- trunk/bibdesk/BDSKTemplate.h 2008-01-08 18:22:13 UTC (rev 12371)
+++ trunk/bibdesk/BDSKTemplate.h 2008-01-08 19:12:08 UTC (rev 12372)
@@ -92,6 +92,8 @@
+ (BDSKTemplate *)templateForStyle:(NSString *)styleName;
+ (BDSKTemplate *)templateWithName:(NSString *)name mainPageURL:(NSURL
*)fileURL fileType:(NSString *)fileType;
++ (id)templateWithString:(NSString *)string fileType:(NSString *)fileType;
++ (id)templateWithAttributedString:(NSAttributedString *)attributedString
fileType:(NSString *)fileType;
// service templates
+ (BDSKTemplate *)templateForCiteService;
Modified: trunk/bibdesk/BDSKTemplate.m
===================================================================
--- trunk/bibdesk/BDSKTemplate.m 2008-01-08 18:22:13 UTC (rev 12371)
+++ trunk/bibdesk/BDSKTemplate.m 2008-01-08 19:12:08 UTC (rev 12372)
@@ -45,6 +45,8 @@
NSString *BDSKTemplateRoleString = @"role";
NSString *BDSKTemplateNameString = @"name";
NSString *BDSKTemplateFileURLString = @"representedFileURL";
+NSString *BDSKTemplateStringString = @"string";
+NSString *BDSKTemplateAttributedStringString = @"attributedString";
NSString *BDSKExportTemplateTree = @"BDSKExportTemplateTree";
NSString *BDSKServiceTemplateTree = @"BDSKServiceTemplateTree";
NSString *BDSKTemplateAccessoryString = @"Accessory File";
@@ -320,16 +322,35 @@
return template;
}
++ (id)templateWithString:(NSString *)string fileType:(NSString *)fileType;
+{
+ BDSKTemplate *template = [[[BDSKTemplate alloc] init] autorelease];
+ [template setValue:fileType forKey:BDSKTemplateRoleString];
+ [template setValue:string forKey:BDSKTemplateStringString];
+ return template;
+}
+
++ (id)templateWithAttributedString:(NSAttributedString *)attributedString
fileType:(NSString *)fileType;
+{
+ BDSKTemplate *template = [[[BDSKTemplate alloc] init] autorelease];
+ [template setValue:fileType forKey:BDSKTemplateRoleString];
+ [template setValue:attributedString
forKey:BDSKTemplateAttributedStringString];
+ return template;
+}
+
#pragma mark Instance methods
- (BDSKTemplateFormat)templateFormat;
{
- OBASSERT([self isLeaf] == NO);
+ OBASSERT([self parent] == nil);
NSString *extension = [[self valueForKey:BDSKTemplateRoleString]
lowercaseString];
+ BDSKTemplateFormat format = BDSKUnknownTemplateFormat;
NSURL *url = [self mainPageTemplateURL];
- BDSKTemplateFormat format = BDSKUnknownTemplateFormat;
+ NSString *string = nil;
+ NSAttributedString *attrString = nil;
+ BOOL isValid = (url = [self mainPageTemplateURL]) || (string = [self
mainPageString]) || (attrString = [self
mainPageAttributedStringWithDocumentAttributes:NULL]);
- if (extension == nil || url == nil) {
+ if (extension == nil || isValid == NO) {
format = BDSKUnknownTemplateFormat;
} else if ([extension isEqualToString:@"rtf"]) {
format = BDSKRTFTemplateFormat;
@@ -338,8 +359,10 @@
} else if ([extension isEqualToString:@"doc"]) {
format = BDSKDocTemplateFormat;
} else if ([extension isEqualToString:@"html"] || [extension
isEqualToString:@"htm"]) {
- NSString *htmlString = [[[NSString alloc] initWithData:[NSData
dataWithContentsOfURL:url] encoding:NSUTF8StringEncoding] autorelease];
- if (htmlString == nil)
+ NSString *htmlString = url == nil ? string : [[[NSString alloc]
initWithData:[NSData dataWithContentsOfURL:url] encoding:NSUTF8StringEncoding]
autorelease];
+ if (attrString)
+ format = BDSKRichHTMLTemplateFormat;
+ else if (htmlString == nil)
format = BDSKUnknownTemplateFormat;
else if ([htmlString rangeOfString:@"<$"].location == NSNotFound &&
[htmlString rangeOfString:@"<$"].location != NSNotFound)
format = BDSKRichHTMLTemplateFormat;
@@ -353,25 +376,36 @@
- (NSString *)fileExtension;
{
- OBASSERT([self isLeaf] == NO);
+ OBASSERT([self parent] == nil);
return [self valueForKey:BDSKTemplateRoleString];
}
- (NSString *)mainPageString;
{
- OBASSERT([self isLeaf] == NO);
- return [NSString stringWithContentsOfURL:[self mainPageTemplateURL]
encoding:NSUTF8StringEncoding error:NULL];
+ OBASSERT([self parent] == nil);
+ NSURL *mainPageURL = [self mainPageTemplateURL];
+ if (mainPageURL) {
+ return [NSString stringWithContentsOfURL:[self mainPageTemplateURL]
encoding:NSUTF8StringEncoding error:NULL];
+ } else {
+ return [self valueForKey:BDSKTemplateStringString];
+ }
}
- (NSAttributedString
*)mainPageAttributedStringWithDocumentAttributes:(NSDictionary **)docAttributes;
{
- OBASSERT([self isLeaf] == NO);
- return [[[NSAttributedString alloc] initWithURL:[self mainPageTemplateURL]
documentAttributes:docAttributes] autorelease];
+ OBASSERT([self parent] == nil);
+ NSURL *mainPageURL = [self mainPageTemplateURL];
+ if (mainPageURL) {
+ return [[[NSAttributedString alloc] initWithURL:[self
mainPageTemplateURL] documentAttributes:docAttributes] autorelease];
+ } else {
+ if (docAttributes) *docAttributes = nil;
+ return [self valueForKey:BDSKTemplateAttributedStringString];
+ }
}
- (NSString *)stringForType:(NSString *)type;
{
- OBASSERT([self isLeaf] == NO);
+ OBASSERT([self parent] == nil);
NSURL *theURL = nil;
if(nil != type)
theURL = [self templateURLForType:type];
@@ -383,13 +417,12 @@
if([type isEqualToString:BDSKTemplateMainPageString] == NO)
return nil;
// get the item template from the main page template
- theURL = [self mainPageTemplateURL];
- return itemTemplateSubstring([NSString stringWithContentsOfURL:theURL
encoding:NSUTF8StringEncoding error:NULL]);
+ return itemTemplateSubstring([self mainPageString]);
}
- (NSAttributedString *)attributedStringForType:(NSString *)type;
{
- OBASSERT([self isLeaf] == NO);
+ OBASSERT([self parent] == nil);
NSURL *theURL = nil;
if(nil != type)
theURL = [self templateURLForType:type];
@@ -401,32 +434,32 @@
- (NSString *)scriptPath;
{
- OBASSERT([self isLeaf] == NO);
+ OBASSERT([self parent] == nil);
return [NSString stringWithContentsOfURL:[self scriptURL]
encoding:NSUTF8StringEncoding error:NULL];
}
- (NSURL *)mainPageTemplateURL;
{
- OBASSERT([self isLeaf] == NO);
+ OBASSERT([self parent] == nil);
return [self templateURLForType:BDSKTemplateMainPageString];
}
- (NSURL *)defaultItemTemplateURL;
{
- OBASSERT([self isLeaf] == NO);
+ OBASSERT([self parent] == nil);
return [self templateURLForType:BDSKTemplateDefaultItemString];
}
- (NSURL *)templateURLForType:(NSString *)pubType;
{
- OBASSERT([self isLeaf] == NO);
+ OBASSERT([self parent] == nil);
NSParameterAssert(nil != pubType);
return [[self childForRole:pubType] representedFileURL];
}
- (NSArray *)accessoryFileURLs;
{
- OBASSERT([self isLeaf] == NO);
+ OBASSERT([self parent] == nil);
NSMutableArray *fileURLs = [NSMutableArray array];
NSEnumerator *childE = [[self children] objectEnumerator];
BDSKTemplate *aChild;
@@ -443,7 +476,7 @@
- (NSURL *)scriptURL;
{
- OBASSERT([self isLeaf] == NO);
+ OBASSERT([self parent] == nil);
return [[self childForRole:BDSKTemplateScriptString] representedFileURL];
}
@@ -464,7 +497,7 @@
- (id)childForRole:(NSString *)role;
{
- OBASSERT([self isLeaf] == NO);
+ OBASSERT([self parent] == nil);
NSParameterAssert(nil != role);
NSEnumerator *nodeE = [[self children] objectEnumerator];
id aNode = nil;
Modified: trunk/bibdesk/BDSKTemplatedTextCommand.m
===================================================================
--- trunk/bibdesk/BDSKTemplatedTextCommand.m 2008-01-08 18:22:13 UTC (rev
12371)
+++ trunk/bibdesk/BDSKTemplatedTextCommand.m 2008-01-08 19:12:08 UTC (rev
12372)
@@ -73,11 +73,12 @@
// the 'using' parameters gives the template name or file to use
id templateStyle = [params objectForKey:@"using"];
+ id templateString = [params objectForKey:@"usingText"];
BDSKTemplate *template = nil;
// make sure we get something
- if (!templateStyle) {
+ if (templateStyle == nil && templateString == nil) {
[self
setScriptErrorNumber:NSRequiredArgumentsMissingScriptError];
- return [NSArray array];
+ return @"";
}
// make sure we get the right thing
if ([templateStyle isKindOfClass:[NSString class]] ) {
@@ -85,7 +86,9 @@
} else if ([templateStyle isKindOfClass:[NSURL class]] ) {
NSString *fileType = [[templateStyle path] pathExtension];
template = [BDSKTemplate templateWithName:@""
mainPageURL:templateStyle fileType:fileType ? fileType : @"txt"];
- }
+ } else if ([templateString isKindOfClass:[NSString class]] ) {
+ template = [BDSKTemplate templateWithString:templateString
fileType:@"txt"];
+ }
if (template == nil) {
[self setScriptErrorNumber:NSArgumentsWrongScriptError];
return @"";
@@ -155,22 +158,25 @@
// the 'using' parameters gives the template name to use
id templateStyle = [params objectForKey:@"using"];
+ id templateAttrString = [params objectForKey:@"usingRichText"];
BDSKTemplate *template = nil;
// make sure we get something
- if (!templateStyle) {
+ if (templateStyle == nil && templateAttrString == nil) {
[self
setScriptErrorNumber:NSRequiredArgumentsMissingScriptError];
- return [NSArray array];
+ return [[[NSTextStorage alloc] init] autorelease];
}
// make sure we get the right thing
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"];
- }
+ template = [BDSKTemplate templateWithName:@""
mainPageURL:templateStyle fileType:fileType ? fileType : @"rtf"];
+ } else if ([templateAttrString isKindOfClass:[NSAttributedString
class]] ) {
+ template = [BDSKTemplate
templateWithAttributedString:templateAttrString fileType:@"rtf"];
+ }
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
Modified: trunk/bibdesk/Scripting/BibDesk.sdef
===================================================================
--- trunk/bibdesk/Scripting/BibDesk.sdef 2008-01-08 18:22:13 UTC (rev
12371)
+++ trunk/bibdesk/Scripting/BibDesk.sdef 2008-01-08 19:12:08 UTC (rev
12372)
@@ -883,12 +883,16 @@
<cocoa name="templatedText" class="BDSKTemplatedTextCommand"/>
<direct-parameter type="document"
description="The object responding to the command, the
document."/>
- <parameter name="using" code="usng"
- description="The name or file of the template to use.">
+ <parameter name="using" code="usng" optional="yes"
+ description="The name or file of the template to use. Either
this or 'using text' should be used.">
<type type="text"/>
<type type="file"/>
<cocoa key="using"/>
</parameter>
+ <parameter name="using text" code="usTx" type="text" optional="yes"
+ description="The template text to use. Either this or 'using'
should be used.">
+ <cocoa key="usingText"/>
+ </parameter>
<parameter name="for" code="for " optional="yes"
description="Specifies the publication or list of publications
to parse.">
<type type="publication" list="yes"/>
@@ -904,12 +908,16 @@
<cocoa name="templatedRichText"
class="BDSKTemplatedRichTextCommand"/>
<direct-parameter type="document"
description="The object responding to the command, the
document."/>
- <parameter name="using" code="usng"
- description="The name or file of the template to use.">
+ <parameter name="using" code="usng" optional="yes"
+ description="The name or file of the template to use. Either
this or 'using rich text' should be used.">
<type type="text"/>
<type type="file"/>
<cocoa key="using"/>
</parameter>
+ <parameter name="using rich text" code="usRT" type="rich text"
optional="yes"
+ description="The template rich text to use. Either this or
'using' should be used.">
+ <cocoa key="usingRichText"/>
+ </parameter>
<parameter name="for" code="for " optional="yes"
description="Specifies the publication or list of publications
to parse.">
<type type="publication" list="yes"/>
@@ -926,11 +934,19 @@
<direct-parameter type="document"
description="The object responding to the command, the
document."/>
<parameter name="using template" code="uset"
- description="The name or file of the template to use.">
+ description="The name or file of the template to use. Either
this, 'using text', or 'using rich text' should be used.">
<type type="text"/>
<type type="file"/>
<cocoa key="using"/>
</parameter>
+ <parameter name="using text" code="usTx" type="text" optional="yes"
+ description="The template text to use. Either this, 'using',
or 'using rich text' should be used.">
+ <cocoa key="usingText"/>
+ </parameter>
+ <parameter name="using rich text" code="usRT" type="rich text"
optional="yes"
+ description="The template rich text to use. Either this,
'using', or 'using text' should be used.">
+ <cocoa key="usingRichText"/>
+ </parameter>
<parameter name="to" code="to " type="file"
description="The file to export to">
<cocoa key="to"/>
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