Revision: 27609
http://sourceforge.net/p/bibdesk/svn/27609
Author: hofman
Date: 2022-06-11 09:19:42 +0000 (Sat, 11 Jun 2022)
Log Message:
-----------
Allow passing pubs to import script command, can be useful for merging in
external publications
Modified Paths:
--------------
trunk/bibdesk/BibDocument+Scripting.m
trunk/bibdesk/Scripting/BibDesk.sdef
Modified: trunk/bibdesk/BibDocument+Scripting.m
===================================================================
--- trunk/bibdesk/BibDocument+Scripting.m 2022-06-11 08:56:53 UTC (rev
27608)
+++ trunk/bibdesk/BibDocument+Scripting.m 2022-06-11 09:19:42 UTC (rev
27609)
@@ -1034,7 +1034,7 @@
// The 'searchTerm' parameter gives the search term to use with an
optional 'server' parameter
// The 'with' parameter gives a URL to attach
NSDictionary *params = [command evaluatedArguments];
- id string = [params objectForKey:@"from"];
+ id source = [params objectForKey:@"from"];
id searchTerm = [params objectForKey:@"searchTerm"];
id url = [params objectForKey:@"attach"];
id wait = [params objectForKey:@"wait"];
@@ -1045,7 +1045,7 @@
BDSKServerInfo *serverInfo = nil;
// make sure we get something valid as input
- if (string == nil && searchTerm == nil && url == nil) {
+ if (source == nil && searchTerm == nil && url == nil) {
[command setScriptErrorNumber:NSRequiredArgumentsMissingScriptError];
[command setScriptErrorString:@"Either 'from', 'with, or 'for search
term' must be specified."];
return nil;
@@ -1058,13 +1058,13 @@
return nil;
}
- if ([string isKindOfClass:[NSURL class]]) {
- string = [NSString stringWithContentsOfURL:string guessedEncoding:0];
- if (string == nil) {
+ if ([source isKindOfClass:[NSURL class]]) {
+ source = [NSString stringWithContentsOfURL:source guessedEncoding:0];
+ if (source == nil) {
[command setScriptErrorNumber:NSArgumentsWrongScriptError];
return nil;
}
- } else if (string && [string isKindOfClass:[NSString class]] == NO) {
+ } else if (source && [source isKindOfClass:[NSString class]] == NO &&
[source isKindOfClass:[NSArray class]] == NO) {
[command setScriptErrorNumber:NSArgumentsWrongScriptError];
return nil;
}
@@ -1075,7 +1075,7 @@
}
// get the serverInfo if needed
- if (string == nil && searchTerm) {
+ if (source == nil && searchTerm) {
id server = [params objectForKey:@"server"];
// the server can be a scriptingServerInfo dictionary, a .bdsksearch
file URL, a x-bdsk-search URL, or a default server name
if ([server isKindOfClass:[NSDictionary class]] && [server count] == 1
&& [server objectForKey:@"name"])
@@ -1111,7 +1111,7 @@
handler = ^(NSArray *result){
BibItem *pub = [result firstObject];
if (pub) {
- if (url != nil && (string != nil || searchTerm != nil)) {
+ if (url != nil && (source != nil || searchTerm != nil)) {
if ([[NSUserDefaults standardUserDefaults]
boolForKey:BDSKUseLocalUrlAndUrlKey]) {
[pub setField:[url isFileURL] ? BDSKLocalUrlString :
BDSKUrlString toURLValue:url basePath:[self basePath]];
} else {
@@ -1138,7 +1138,7 @@
} else {
handler = ^(NSArray *result){
if ([result count] > 0) {
- if (url != nil && (string != nil || searchTerm != nil)) {
+ if (url != nil && (source != nil || searchTerm != nil)) {
if ([[NSUserDefaults standardUserDefaults]
boolForKey:BDSKUseLocalUrlAndUrlKey]) {
for (BibItem *pub in result)
[pub setField:[url isFileURL] ? BDSKLocalUrlString
: BDSKUrlString toURLValue:url basePath:[self basePath]];
@@ -1153,8 +1153,17 @@
}
// finally get the pubs and process them
- if (string) {
- pubs = [BDSKStringParser itemsFromString:string
ofType:BDSKStringTypeUnknown owner:self error:NULL];
+ if ([source isKindOfClass:[NSString class]]) {
+ pubs = [BDSKStringParser itemsFromString:source
ofType:BDSKStringTypeUnknown owner:self error:NULL];
+ } else if ([source isKindOfClass:[NSArray class]]) {
+ NSMutableArray *tmpPubs = [NSMutableArray array];
+ for (BibItem *pub in source) {
+ // get complex strings with the correct macroResolver
+ pub = [pub copyWithMacroResolver:[self macroResolver]];
+ [tmpPubs addObject:pub];
+ [pub release];
+ }
+ pubs = tmpPubs;
} else if (searchTerm) {
pubs = [BDSKGroupSearch searchUsingSearchTerm:searchTerm
serverInfo:serverInfo macroResolver:[self macroResolver]
completionHandler:synchronous ? nil : handler];
if (synchronous == NO)
Modified: trunk/bibdesk/Scripting/BibDesk.sdef
===================================================================
--- trunk/bibdesk/Scripting/BibDesk.sdef 2022-06-11 08:56:53 UTC (rev
27608)
+++ trunk/bibdesk/Scripting/BibDesk.sdef 2022-06-11 09:19:42 UTC (rev
27609)
@@ -563,6 +563,7 @@
description="The string or file containing publications in a
supported string format or DOI. Either this, 'attaching', or 'for search term'
must be specified.">
<type type="text"/>
<type type="file"/>
+ <type type="publication" list="yes"/>
<cocoa key="from"/>
</parameter>
<parameter name="attaching" code="Atch" optional="yes"
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit