Revision: 11521
          http://bibdesk.svn.sourceforge.net/bibdesk/?rev=11521&view=rev
Author:   hofman
Date:     2007-11-09 17:35:24 -0800 (Fri, 09 Nov 2007)

Log Message:
-----------
Change local-url when autofiling would change full url to relative path or vv.

Modified Paths:
--------------
    trunk/bibdesk/BDSKFiler.m

Modified: trunk/bibdesk/BDSKFiler.m
===================================================================
--- trunk/bibdesk/BDSKFiler.m   2007-11-10 00:10:42 UTC (rev 11520)
+++ trunk/bibdesk/BDSKFiler.m   2007-11-10 01:35:24 UTC (rev 11521)
@@ -112,6 +112,7 @@
        BibItem *paper = nil;
        NSString *path = nil;
        NSString *newPath = nil;
+       NSString *newRelativePath = nil;
        NSMutableArray *fileInfoDicts = [NSMutableArray 
arrayWithCapacity:numberOfPapers];
        NSMutableDictionary *info = nil;
        BOOL useRelativePath = [[OFPreferenceWrapper sharedPreferenceWrapper] 
boolForKey:BDSKAutoFileUsesRelativePathKey];
@@ -176,6 +177,9 @@
                        paper = (BibItem *)paperInfo;
                        path = [paper localUrlPathInheriting:NO];
                        newPath = [[NSURL URLWithString:[paper 
suggestedLocalUrl]] path];
+            newRelativePath = newPath;
+            if ([newPath hasPrefix:papersFolderPath])
+                newRelativePath = [newPath 
substringFromIndex:[papersFolderPath length]];
                }else{
                        // an explicit move, possibly from undo: a list of info 
dictionaries
                        paper = [paperInfo objectForKey:@"paper"];
@@ -188,16 +192,22 @@
                        [progressIndicator displayIfNeeded];
                }
                        
-               if([NSString isEmptyString:path] || [NSString 
isEmptyString:newPath] || 
-                  [path isEqualToString:newPath])
+               if([NSString isEmptyString:path] || [NSString 
isEmptyString:newPath]){
                        continue;
-               
+               }else if([path isEqualToString:newPath]){
+            // we still want to change the field when we change from full URL 
to relative path or v.v.
+            oldValue = [paper valueOfField:field inherit:NO];
+            BOOL wasRelative = [oldValue hasPrefix:@"file://"] == NO && 
[oldValue isAbsolutePath] == NO;
+            if (initial == NO || useRelativePath != wasRelative || 
[newRelativePath isAbsolutePath] == NO)
+                continue;
+        }
+        
                info = [NSMutableDictionary dictionaryWithCapacity:6];
                [info setObject:paper forKey:@"paper"];
         error = nil;
         oldValue  = [[NSURL fileURLWithPath:path] absoluteString]; // we don't 
use the field value, as we might have already changed it in undo or find/replace
         
-        if(check && ![paper canSetLocalUrl]){
+        if(check && NO == [paper canSetLocalUrl]){
             
             [info setObject:NSLocalizedString(@"Incomplete information to 
generate file name.",@"") forKey:@"status"];
             [info setObject:[NSNumber 
numberWithInt:BDSKIncompleteFieldsErrorMask] forKey:@"flag"];
@@ -206,7 +216,7 @@
             [info setObject:newPath forKey:@"newPath"];
             [self insertObject:info inErrorInfoDictsAtIndex:[self 
countOfErrorInfoDicts]];
             
-        }else if(![fm movePath:path toPath:newPath force:force error:&error]){ 
+        }else if(NO == [path isEqualToString:newPath] && NO == [fm 
movePath:path toPath:newPath force:force error:&error]){ 
             
             NSDictionary *errorInfo = [error userInfo];
             NSString *fix = [errorInfo 
objectForKey:NSLocalizedRecoverySuggestionErrorKey];
@@ -222,14 +232,7 @@
                        
                        newValue  = [[NSURL fileURLWithPath:newPath] 
absoluteString];
                        if(initial) {// otherwise will be done by undo of 
setField:
-                if(useRelativePath){
-                    NSString *relativePath = newPath;
-                    if ([newPath hasPrefix:papersFolderPath])
-                        relativePath = [newPath 
substringFromIndex:[papersFolderPath length]];
-                    [paper setField:field toValue:relativePath];
-                }else{
-                    [paper setField:field toValue:newValue];
-                }
+                [paper setField:field toValue:useRelativePath ? 
newRelativePath : newValue];
                        }else{
                 // make sure the UI is notified that the linked file has 
changed, as this is often called after setField:toValue:
                 NSString *value = [paper valueOfField:field];


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

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit

Reply via email to