Revision: 12255
          http://bibdesk.svn.sourceforge.net/bibdesk/?rev=12255&view=rev
Author:   hofman
Date:     2008-01-04 10:43:33 -0800 (Fri, 04 Jan 2008)

Log Message:
-----------
Drag local file / remote URL from local file / remote URL column.

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

Modified: trunk/bibdesk/BibDocument_DataSource.m
===================================================================
--- trunk/bibdesk/BibDocument_DataSource.m      2008-01-04 13:38:08 UTC (rev 
12254)
+++ trunk/bibdesk/BibDocument_DataSource.m      2008-01-04 18:43:33 UTC (rev 
12255)
@@ -72,6 +72,7 @@
 #import "NSIndexSet_BDSKExtensions.h"
 #import "BDSKSearchGroup.h"
 #import "BDSKLinkedFile.h"
+#import "NSArray_BDSKExtensions.h"
 
 #define MAX_DRAG_IMAGE_WIDTH 700.0
 
@@ -579,6 +580,57 @@
                         [url writeToPasteboard:pboard];
                                                return success;
                                        }
+                               
+                }else if([dragColumnId isEqualToString:BDSKLocalFileString]){
+
+                    // if we have more than one files, we can't put file 
contents on the pasteboard, but most apps seem to handle file names just fine
+                    unsigned row = [rowIndexes firstIndex];
+                    BibItem *pub = nil;
+                    NSMutableArray *filePaths = [NSMutableArray 
arrayWithCapacity:[rowIndexes count]];
+                    NSEnumerator *fileEnum;
+                    BDSKLinkedFile *file;
+                    NSString *path;
+                    
+                    while(row != NSNotFound){
+                        pub = [shownPublications objectAtIndex:row];
+                        fileEnum = [[pub localFiles] objectEnumerator];
+                        
+                        while(file = [fileEnum nextObject]){
+                            path = [file path];
+                            if(path != nil){
+                                [filePaths addObject:path];
+                                NSError *xerror = nil;
+                                // we can always write xattrs; this doesn't 
alter the original file's content in any way, but fails if you have a really 
long abstract/annote
+                                if([[NSFileManager defaultManager] 
setExtendedAttributeNamed:OMNI_BUNDLE_IDENTIFIER @".bibtexstring" toValue:[[pub 
bibTeXString] dataUsingEncoding:NSUTF8StringEncoding] atPath:path options:nil 
error:&xerror] == NO)
+                                    NSLog(@"%@ line %d: adding xattrs failed 
with error %@", __FILENAMEASNSSTRING__, __LINE__, xerror);
+                            }
+                        }
+                        row = [rowIndexes indexGreaterThanIndex:row];
+                    }
+                    
+                    if([filePaths count]){
+                        [pboard declareTypes:[NSArray 
arrayWithObjects:NSFilenamesPboardType, nil] owner:nil];
+                        return [pboard setPropertyList:filePaths 
forType:NSFilenamesPboardType];
+                    }
+                    
+                               }else if([dragColumnId 
isEqualToString:BDSKRemoteURLString]){
+                                       // cache this so we know which column 
(field) was dragged
+                                       [self 
setPromiseDragColumnIdentifier:dragColumnId];
+                                       
+                                       BibItem *pub;
+                    NSURL *url;
+                    unsigned row = [rowIndexes firstIndex];
+                    while(row != NSNotFound){
+                        pub = [shownPublications objectAtIndex:row];
+                        if(url = [[pub remoteURLs] firstObject]){
+                            // put the URL and a webloc file promise on the 
pasteboard
+                            [pboard declareTypes:[NSArray 
arrayWithObjects:NSFilesPromisePboardType, NSURLPboardType, nil] owner:self];
+                            success = [pboard setPropertyList:[NSArray 
arrayWithObject:[[pub displayTitle] stringByAppendingPathExtension:@"webloc"]] 
forType:NSFilesPromisePboardType];
+                            [url writeToPasteboard:pboard];
+                            return success;
+                        }
+                        row = [rowIndexes indexGreaterThanIndex:row];
+                    }
                                }
                        }
                }


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: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit

Reply via email to