Revision: 22270
          http://sourceforge.net/p/bibdesk/svn/22270
Author:   hofman
Date:     2018-05-31 14:56:18 +0000 (Thu, 31 May 2018)
Log Message:
-----------
Add URLs to field when using fields rather than lined files in various places

Modified Paths:
--------------
    trunk/bibdesk/BDSKDBLPGroupServer.m
    trunk/bibdesk/BDSKFileMatcher.m
    trunk/bibdesk/BDSKImportCommand.m
    trunk/bibdesk/BDSKMathSciNetParser.m
    trunk/bibdesk/BDSKNumdamParser.m
    trunk/bibdesk/BDSKProjectEuclidParser.m
    trunk/bibdesk/BDSKTextImportController.m
    trunk/bibdesk/BDSKZentralblattParser.m

Modified: trunk/bibdesk/BDSKDBLPGroupServer.m
===================================================================
--- trunk/bibdesk/BDSKDBLPGroupServer.m 2018-05-31 14:31:51 UTC (rev 22269)
+++ trunk/bibdesk/BDSKDBLPGroupServer.m 2018-05-31 14:56:18 UTC (rev 22270)
@@ -174,7 +174,8 @@
 
 static void fixEEURL(BibItem *pub)
 {
-    NSMutableString *URLString = [NSMutableString stringWithString:[pub 
valueOfField:[@"ee" fieldName] inherit:NO]];
+    NSString *eeField = [@"ee" fieldName];
+    NSMutableString *URLString = [NSMutableString stringWithString:[pub 
valueOfField:eeField inherit:NO]];
     // some URLs have been converted for compatibility with TeX
     [URLString replaceOccurrencesOfString:@"{\\&}" withString:@"&" options:0 
range:NSMakeRange(0, [URLString length])];
     NSURL *aURL;
@@ -186,8 +187,12 @@
             aURL = [NSURL URLWithString:URLString];
         }
         
-        if ([pub addFileForURL:aURL autoFile:NO runScriptHook:NO])
-            [pub setField:[@"ee" fieldName] toValue:nil];
+        if ([[NSUserDefaults standardUserDefaults] 
boolForKey:BDSKUseLocalUrlAndUrlKey]) {
+            [pub setField:BDSKUrlString toValue:[aURL absoluteString]];
+            [pub setField:eeField toValue:nil];
+        } else if ([pub addFileForURL:aURL autoFile:NO runScriptHook:NO]) {
+            [pub setField:eeField toValue:nil];
+        }
     }
 }
 

Modified: trunk/bibdesk/BDSKFileMatcher.m
===================================================================
--- trunk/bibdesk/BDSKFileMatcher.m     2018-05-31 14:31:51 UTC (rev 22269)
+++ trunk/bibdesk/BDSKFileMatcher.m     2018-05-31 14:56:18 UTC (rev 22270)
@@ -303,7 +303,10 @@
         return NO;
     
     BibItem *pub = [item valueForKey:@"pub"];
-    [pub addFileForURL:[fileURLs objectAtIndex:0] autoFile:NO 
runScriptHook:YES];
+    if ([[NSUserDefaults standardUserDefaults] 
boolForKey:BDSKUseLocalUrlAndUrlKey])
+        [pub setField:BDSKLocalUrlString toValue:[[fileURLs objectAtIndex:0] 
absoluteString]];
+    else
+        [pub addFileForURL:[fileURLs objectAtIndex:0] autoFile:NO 
runScriptHook:YES];
     [[pub undoManager] setActionName:NSLocalizedString(@"Edit Publication", 
@"Undo action name")];
     return YES;
 }

Modified: trunk/bibdesk/BDSKImportCommand.m
===================================================================
--- trunk/bibdesk/BDSKImportCommand.m   2018-05-31 14:31:51 UTC (rev 22269)
+++ trunk/bibdesk/BDSKImportCommand.m   2018-05-31 14:56:18 UTC (rev 22270)
@@ -191,8 +191,13 @@
        }
        if ([pubs count] > 0) {
         if (url != nil && (string != nil || searchTerm != nil)) {
-            for (BibItem *pub in pubs)
-                [pub addFileForURL:url autoFile:NO runScriptHook:NO];
+            if ([[NSUserDefaults standardUserDefaults] 
boolForKey:BDSKUseLocalUrlAndUrlKey]) {
+                for (BibItem *pub in pubs)
+                    [pub setField:[url isFileURL] ? BDSKLocalUrlString : 
BDSKUrlString toValue:[url absoluteString]];
+            } else {
+                for (BibItem *pub in pubs)
+                    [pub addFileForURL:url autoFile:NO runScriptHook:NO];
+            }
         }
        [document importPublications:pubs publicationsToAutoFile:([url 
isFileURL] ? pubs : nil) temporaryCiteKey:nil options:BDSKImportAggregate | 
BDSKImportNoEdit];
     }

Modified: trunk/bibdesk/BDSKMathSciNetParser.m
===================================================================
--- trunk/bibdesk/BDSKMathSciNetParser.m        2018-05-31 14:31:51 UTC (rev 
22269)
+++ trunk/bibdesk/BDSKMathSciNetParser.m        2018-05-31 14:56:18 UTC (rev 
22270)
@@ -176,10 +176,14 @@
     }
     
     // Add a URL reference pointing to the review's web page to each record.
+    BOOL useUrl = [[NSUserDefaults standardUserDefaults] 
boolForKey:BDSKUseLocalUrlAndUrlKey];
     for (BibItem * item in results) {
         NSString * MRNumber = [[item citeKey] stringByRemovingPrefix:@"MR"];
         NSURL * MRItemURL = [[NSURL URLWithString:[@"/mathscinet-getitem?mr=" 
stringByAppendingString:MRNumber] relativeToURL:[download URL]] absoluteURL];
-        [item addFileForURL:MRItemURL autoFile:NO runScriptHook:NO];
+        if (useUrl)
+            [item setField:BDSKUrlString toValue:[MRItemURL absoluteString]];
+        else
+            [item addFileForURL:MRItemURL autoFile:NO runScriptHook:NO];
     }
     
     return results;

Modified: trunk/bibdesk/BDSKNumdamParser.m
===================================================================
--- trunk/bibdesk/BDSKNumdamParser.m    2018-05-31 14:31:51 UTC (rev 22269)
+++ trunk/bibdesk/BDSKNumdamParser.m    2018-05-31 14:56:18 UTC (rev 22270)
@@ -143,6 +143,7 @@
     NSDictionary *contextInfo = [download contextInfo];
     Class parserClass = (Class)[contextInfo objectForKey:@"parserClass"];
     NSString *content = [contextInfo objectForKey:@"content"];
+    BOOL useUrl = [[NSUserDefaults standardUserDefaults] 
boolForKey:BDSKUseLocalUrlAndUrlKey];
     
     results = [parserClass itemsFromDownload:download owner:[self delegate] 
error:outError];
     
@@ -156,11 +157,15 @@
                 NSString * myURLString = [[match string] 
substringWithRange:[match rangeAtIndex:1]];
                 NSURL * myURL = [NSURL URLWithString:myURLString];
                 if ( myURL ) {
+                    if ( useUrl ) {
                     BOOL added = [(BibItem *)item addFileForURL:myURL 
autoFile:NO runScriptHook:NO];
-                    if (added) {
+                    if ( added ) {
                         NSIndexSet * indexSet = [NSIndexSet 
indexSetWithIndex:[(BibItem *)item countOfFiles] - 1];
                         [(BibItem *)item moveFilesAtIndexes:indexSet 
toIndex:0];
                     }
+                    } else if ([NSString isEmptyString:[(BibItem *)item 
valueOfField:BDSKUrlString]]) {
+                        [(BibItem *)item setField:BDSKUrlString toValue:[myURL 
absoluteString]];
+                    }
                 }
             }
         }

Modified: trunk/bibdesk/BDSKProjectEuclidParser.m
===================================================================
--- trunk/bibdesk/BDSKProjectEuclidParser.m     2018-05-31 14:31:51 UTC (rev 
22269)
+++ trunk/bibdesk/BDSKProjectEuclidParser.m     2018-05-31 14:56:18 UTC (rev 
22270)
@@ -135,6 +135,7 @@
     NSDictionary *contextInfo = [download contextInfo];
     Class parserClass = (Class)[contextInfo objectForKey:@"parserClass"];
     NSString *myIdentifier = [contextInfo objectForKey:@"myIdentifier"];
+    BOOL useUrl = [[NSUserDefaults standardUserDefaults] 
boolForKey:BDSKUseLocalUrlAndUrlKey];
     
     results = [parserClass itemsFromDownload:download owner:[self delegate] 
error:&error];
     
@@ -148,10 +149,14 @@
             NSURL * projectEuclidURL = [NSURL 
URLWithString:projectEuclidURLString];
             
             if ( projectEuclidURL ) {
-                BOOL added = [(BibItem *)item addFileForURL:projectEuclidURL 
autoFile:NO runScriptHook:NO];
-                if ( added ) {
-                    NSIndexSet * indexSet = [NSIndexSet 
indexSetWithIndex:[(BibItem *)item countOfFiles] - 1];
-                    [(BibItem *)item moveFilesAtIndexes:indexSet toIndex:0];
+                if (useUrl == NO) {
+                    BOOL added = [(BibItem *)item 
addFileForURL:projectEuclidURL autoFile:NO runScriptHook:NO];
+                    if ( added ) {
+                        NSIndexSet * indexSet = [NSIndexSet 
indexSetWithIndex:[(BibItem *)item countOfFiles] - 1];
+                        [(BibItem *)item moveFilesAtIndexes:indexSet 
toIndex:0];
+                    }
+                } else if ([NSString isEmptyString:[(BibItem *)item 
valueOfField:BDSKUrlString]]) {
+                    [(BibItem *)item setField:BDSKUrlString 
toValue:[projectEuclidURL absoluteString]];
                 }
             }
         }

Modified: trunk/bibdesk/BDSKTextImportController.m
===================================================================
--- trunk/bibdesk/BDSKTextImportController.m    2018-05-31 14:31:51 UTC (rev 
22269)
+++ trunk/bibdesk/BDSKTextImportController.m    2018-05-31 14:56:18 UTC (rev 
22270)
@@ -413,7 +413,10 @@
        NSURL *aURL = [webView URL];
        
        if (aURL) {
-        [[self publication] addFileForURL:aURL autoFile:YES runScriptHook:NO];
+        if ([[NSUserDefaults standardUserDefaults] 
boolForKey:BDSKUseLocalUrlAndUrlKey])
+            [[self publication] setField:[aURL isFileURL] ? BDSKLocalUrlString 
: BDSKUrlString toValue:[aURL absoluteString]];
+        else
+            [[self publication] addFileForURL:aURL autoFile:YES 
runScriptHook:NO];
         [[self undoManager] setActionName:NSLocalizedString(@"Edit 
Publication", @"Undo action name")];
        }
 }
@@ -422,7 +425,10 @@
        NSURL *aURL = (NSURL *)[sender representedObject];
        
        if (aURL) {
-        [[self publication] addFileForURL:aURL autoFile:YES runScriptHook:NO];
+        if ([[NSUserDefaults standardUserDefaults] 
boolForKey:BDSKUseLocalUrlAndUrlKey])
+            [[self publication] setField:[aURL isFileURL] ? BDSKLocalUrlString 
: BDSKUrlString toValue:[aURL absoluteString]];
+        else
+            [[self publication] addFileForURL:aURL autoFile:YES 
runScriptHook:NO];
         [[self undoManager] setActionName:NSLocalizedString(@"Edit 
Publication", @"Undo action name")];
        }
 }
@@ -445,7 +451,10 @@
         if (result == NSFileHandlingPanelOKButton) {
             NSURL *fileURL = [sPanel URL];
             if ([[[[webView mainFrame] dataSource] data] writeToURL:fileURL 
atomically:YES]) {
-                [[self publication] addFileForURL:fileURL autoFile:YES 
runScriptHook:NO];
+                if ([[NSUserDefaults standardUserDefaults] 
boolForKey:BDSKUseLocalUrlAndUrlKey])
+                    [[self publication] setField:BDSKLocalUrlString 
toValue:[fileURL absoluteString]];
+                else
+                    [[self publication] addFileForURL:fileURL autoFile:YES 
runScriptHook:NO];
                 [[self undoManager] setActionName:NSLocalizedString(@"Edit 
Publication", @"Undo action name")];
             } else {
                 NSLog(@"Could not write downloaded file.");
@@ -739,7 +748,10 @@
 - (void)setLocalUrlFromDownload{
        NSURL *fileURL = [NSURL fileURLWithPath:downloadFileName];
        
-    [[self publication] addFileForURL:fileURL autoFile:YES runScriptHook:NO];
+    if ([[NSUserDefaults standardUserDefaults] 
boolForKey:BDSKUseLocalUrlAndUrlKey])
+        [[self publication] setField:BDSKLocalUrlString toValue:[fileURL 
absoluteString]];
+    else
+        [[self publication] addFileForURL:fileURL autoFile:YES 
runScriptHook:NO];
     [[self undoManager] setActionName:NSLocalizedString(@"Edit Publication", 
@"Undo action name")];
 }
 

Modified: trunk/bibdesk/BDSKZentralblattParser.m
===================================================================
--- trunk/bibdesk/BDSKZentralblattParser.m      2018-05-31 14:31:51 UTC (rev 
22269)
+++ trunk/bibdesk/BDSKZentralblattParser.m      2018-05-31 14:56:18 UTC (rev 
22270)
@@ -158,6 +158,7 @@
     bibTeXString = [umlautFixer replaceWithString:@"{$1}" 
inString:bibTeXString];
     
     NSArray * results = [BDSKBibTeXParser itemsFromString:bibTeXString 
owner:owner error: outError];
+    BOOL useUrl = [[NSUserDefaults standardUserDefaults] 
boolForKey:BDSKUseLocalUrlAndUrlKey];
     
     // Add a URL reference to the review's web page to each record.
     for (BibItem * item in results) {
@@ -164,7 +165,10 @@
         NSString * ZMathID = [item citeKey];
         NSString * ZMathItemURLString = [NSString 
stringWithFormat:@"https://zbmath.org/search/?format=complete&q=an:%@";, 
ZMathID];
         NSURL * ZMathItemURL = [NSURL URLWithString:ZMathItemURLString];
-        [item addFileForURL:ZMathItemURL autoFile:NO runScriptHook:NO];
+        if ( useUrl == NO )
+            [item addFileForURL:ZMathItemURL autoFile:NO runScriptHook:NO];
+        else if ([NSString isEmptyString:[item valueOfField:BDSKUrlString]])
+            [item setField:BDSKUrlString toValue:[ZMathItemURL 
absoluteString]];
     }
     
     return results;

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


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Bibdesk-commit mailing list
Bibdesk-commit@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit

Reply via email to