Revision: 28317
http://sourceforge.net/p/bibdesk/svn/28317
Author: hofman
Date: 2023-07-16 14:39:50 +0000 (Sun, 16 Jul 2023)
Log Message:
-----------
change relative local files in fields when saving bibtex to a different loaction
Modified Paths:
--------------
trunk/bibdesk/BibDocument.m
trunk/bibdesk/BibItem.h
trunk/bibdesk/BibItem.m
Modified: trunk/bibdesk/BibDocument.m
===================================================================
--- trunk/bibdesk/BibDocument.m 2023-07-15 09:05:29 UTC (rev 28316)
+++ trunk/bibdesk/BibDocument.m 2023-07-16 14:39:50 UTC (rev 28317)
@@ -1430,6 +1430,8 @@
options |= BDSKBibTeXOptionTeXify;
if (drop)
options |= BDSKBibTeXOptionDropInternal;
+ if (aBasePath && [self fileURL] && [aBasePath isEqualToString:[self
basePath]] == NO)
+ options |= BDSKBibTeXOptionRedirectRelativeFiles;
if([[NSUserDefaults standardUserDefaults]
boolForKey:BDSKShouldUseTemplateFileKey]){
NSMutableString *templateFile = [NSMutableString
stringWithContentsOfFile:[[[NSUserDefaults standardUserDefaults]
stringForKey:BDSKOutputTemplateFileKey] stringByExpandingTildeInPath]
usedEncoding:NULL error:NULL] ?: [NSMutableString string];
Modified: trunk/bibdesk/BibItem.h
===================================================================
--- trunk/bibdesk/BibItem.h 2023-07-15 09:05:29 UTC (rev 28316)
+++ trunk/bibdesk/BibItem.h 2023-07-16 14:39:50 UTC (rev 28317)
@@ -71,7 +71,8 @@
BDSKBibTeXOptionTeXify = 1,
BDSKBibTeXOptionDropLinkedURLs = 2,
BDSKBibTeXOptionDropNonStandard = 4,
- BDSKBibTeXOptionDropInternal = 6
+ BDSKBibTeXOptionDropInternal = 6,
+ BDSKBibTeXOptionRedirectRelativeFiles = 8
};
typedef NS_ENUM(NSInteger, BDSKFieldAction) {
Modified: trunk/bibdesk/BibItem.m
===================================================================
--- trunk/bibdesk/BibItem.m 2023-07-15 09:05:29 UTC (rev 28316)
+++ trunk/bibdesk/BibItem.m 2023-07-16 14:39:50 UTC (rev 28317)
@@ -1847,7 +1847,8 @@
BOOL shouldNormalizeAuthors = [sud
boolForKey:BDSKShouldSaveNormalizedAuthorNamesKey];
NSMutableSet *knownKeys = nil;
- NSSet *urlKeys = nil;
+ NSSet *urlKeys = nil;
+ NSSet *fileKeys = nil;
NSString *field;
NSString *value;
NSMutableData *data = [NSMutableData dataWithCapacity:200];
@@ -1856,7 +1857,8 @@
BOOL shouldTeXify = (options & BDSKBibTeXOptionTeXify) != 0;
BOOL dropLinkedURLs = (options & BDSKBibTeXOptionDropLinkedURLs) != 0;
BOOL dropInternal = (options & BDSKBibTeXOptionDropNonStandard) != 0;
-
+ BOOL redirectRelPaths = (options & BDSKBibTeXOptionRedirectRelativeFiles)
!= 0;
+
BDSKTypeManager *btm = [BDSKTypeManager sharedManager];
NSString *type = [self pubType];
NSAssert1(type != nil, @"Tried to use a nil pubtype in %@.", [self
citeKey]);
@@ -1891,8 +1893,10 @@
}
// Sets are used directly instead of the NSString category methods because
+[BDSKTypeManager sharedManager] uses @synchronized, which kills performance in
a loop.
- if(shouldTeXify)
+ if(shouldTeXify)
urlKeys = [btm allURLFieldsSet];
+ if(redirectRelPaths)
+ fileKeys = [btm localFileFieldsSet];
NSSet *personFields = [btm personFieldsSet];
// citekey is the only thing that could fail here, and that's not likely
if we read it in originally
@@ -1925,6 +1929,9 @@
if(shouldTeXify && NO == [urlKeys containsObject:field])
value = [value stringByTeXifyingString];
+ if(redirectRelPaths && [fileKeys containsObject:field] && [value
hasCaseInsensitivePrefix:@"file://"] == NO && [value isAbsolutePath] == NO &&
[[self URLForField:field] checkResourceIsReachableAndReturnError:NULL])
+ value = [[[self URLForField:field] path]
relativePathFromPath:basePath];
+
// We used to keep empty strings in fields as markers for the
editor; now they're generally nil
BOOL isEmpty = [NSString isEmptyAsComplexString:value];
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