Revision: 18465
          http://bibdesk.svn.sourceforge.net/bibdesk/?rev=18465&view=rev
Author:   hofman
Date:     2012-02-02 13:14:04 +0000 (Thu, 02 Feb 2012)
Log Message:
-----------
Move code to (un)archive an array of pubs to BibItem class

Modified Paths:
--------------
    trunk/bibdesk/BDSKEditor.m
    trunk/bibdesk/BDSKItemPasteboardHelper.m
    trunk/bibdesk/BibDocument.h
    trunk/bibdesk/BibDocument.m
    trunk/bibdesk/BibDocument_Groups.m
    trunk/bibdesk/BibItem.h
    trunk/bibdesk/BibItem.m

Modified: trunk/bibdesk/BDSKEditor.m
===================================================================
--- trunk/bibdesk/BDSKEditor.m  2012-02-02 12:59:05 UTC (rev 18464)
+++ trunk/bibdesk/BDSKEditor.m  2012-02-02 13:14:04 UTC (rev 18465)
@@ -2701,7 +2701,7 @@
        }else if([pboardType isEqualToString:BDSKBibItemPboardType]){
                NSData *pbData = [pboard dataForType:BDSKBibItemPboardType];
         // we can't just unarchive, as this gives complex strings with the 
wrong macroResolver
-               draggedPubs = [[self document] 
publicationsFromArchivedData:pbData];
+               draggedPubs = [BibItem publicationsFromArchivedData:pbData 
macroResolver:[publication macroResolver]];
        }
     
     // this happens when we didn't find a valid pboardType or parsing failed
@@ -3018,7 +3018,7 @@
             if ([pboard availableTypeFromArray:[NSArray 
arrayWithObjects:BDSKBibItemPboardType, nil]]) {
                 
                 NSData *pbData = [pboard dataForType:BDSKBibItemPboardType];
-                NSArray *draggedPubs = [[self document] 
publicationsFromArchivedData:pbData];
+                NSArray *draggedPubs = [BibItem 
publicationsFromArchivedData:pbData macroResolver:[publication macroResolver]];
                 NSString *crossref = [[draggedPubs firstObject] citeKey];
                 
                 if ([NSString isEmptyString:crossref])
@@ -3053,7 +3053,7 @@
             if ([pboard availableTypeFromArray:[NSArray 
arrayWithObjects:BDSKBibItemPboardType, nil]]) {
                 
                 NSData *pbData = [pboard dataForType:BDSKBibItemPboardType];
-                NSArray *draggedPubs = [[self document] 
publicationsFromArchivedData:pbData];
+                NSArray *draggedPubs = [BibItem 
publicationsFromArchivedData:pbData macroResolver:[publication macroResolver]];
                 
                 if ([draggedPubs count]) {
                     

Modified: trunk/bibdesk/BDSKItemPasteboardHelper.m
===================================================================
--- trunk/bibdesk/BDSKItemPasteboardHelper.m    2012-02-02 12:59:05 UTC (rev 
18464)
+++ trunk/bibdesk/BDSKItemPasteboardHelper.m    2012-02-02 13:14:04 UTC (rev 
18465)
@@ -37,6 +37,7 @@
 
 #import "BDSKItemPasteboardHelper.h"
 #import "BibDocument.h"
+#import "BibItem.h"
 #import "NSArray_BDSKExtensions.h"
 #import "WebURLsWithTitles.h"
 
@@ -183,14 +184,11 @@
        NSArray *items = [self promisedItemsForPasteboard:pboard];
     
     if([type isEqualToString:BDSKBibItemPboardType]){
-        NSMutableData *data = [NSMutableData data];
+        NSData *data = nil;
         
-        if(items != nil){
-            NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] 
initForWritingWithMutableData:data];
-            [archiver encodeObject:items forKey:@"publications"];
-            [archiver finishEncoding];
-            [archiver release];
-        }else NSBeep();
+        if(items != nil)
+            data = [BibItem archivedPublications:items];
+        else NSBeep();
         
         [pboard setData:data forType:BDSKBibItemPboardType];
     }else{

Modified: trunk/bibdesk/BibDocument.h
===================================================================
--- trunk/bibdesk/BibDocument.h 2012-02-02 12:59:05 UTC (rev 18464)
+++ trunk/bibdesk/BibDocument.h 2012-02-02 13:14:04 UTC (rev 18465)
@@ -368,7 +368,6 @@
 /* Paste related methods */
 - (void)addPublications:(NSArray *)newPubs publicationsToAutoFile:(NSArray 
*)pubsToAutoFile temporaryCiteKey:(NSString *)tmpCiteKey 
selectLibrary:(BOOL)shouldSelect edit:(BOOL)shouldEdit;
 - (NSArray *)addPublicationsFromPasteboard:(NSPasteboard *)pb 
selectLibrary:(BOOL)select verbose:(BOOL)verbose error:(NSError **)error;
-- (NSArray *)publicationsFromArchivedData:(NSData *)data;
 - (NSArray *)publicationsForString:(NSString *)string 
type:(BDSKStringType)type verbose:(BOOL)verbose error:(NSError **)error;
 - (NSArray *)publicationsForFiles:(NSArray *)filenames;
 - (NSArray *)publicationsForURL:(NSURL *)aURL title:(NSString *)aTitle;

Modified: trunk/bibdesk/BibDocument.m
===================================================================
--- trunk/bibdesk/BibDocument.m 2012-02-02 12:59:05 UTC (rev 18464)
+++ trunk/bibdesk/BibDocument.m 2012-02-02 13:14:04 UTC (rev 18465)
@@ -2181,7 +2181,7 @@
     
     if([type isEqualToString:BDSKBibItemPboardType]){
         NSData *pbData = [pb dataForType:BDSKBibItemPboardType];
-               newPubs = [self publicationsFromArchivedData:pbData];
+               newPubs = [BibItem publicationsFromArchivedData:pbData 
macroResolver:[self macroResolver]];
     } else if([type isEqualToString:BDSKReferenceMinerStringPboardType]){ // 
pasteboard type from Reference Miner, determined using Pasteboard Peeker
         NSString *pbString = [pb 
stringForType:BDSKReferenceMinerStringPboardType];    
         // sniffing the string for RIS is broken because RefMiner puts junk at 
the beginning
@@ -2229,23 +2229,6 @@
     return newPubs;
 }
 
-- (NSArray *)publicationsFromArchivedData:(NSData *)data{
-    NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] 
initForReadingWithData:data];
-    
-    [NSString setMacroResolverForUnarchiving:macroResolver];
-    
-    NSArray *newPubs = [unarchiver decodeObjectForKey:@"publications"];
-    [unarchiver finishDecoding];
-    [unarchiver release];
-    
-    [NSString setMacroResolverForUnarchiving:nil];
-    
-    // we set the macroResolver so we know the fields of this item may refer 
to it, so we can prevent scripting from adding this to the wrong document
-    [newPubs setValue:macroResolver forKey:@"macroResolver"];
-    
-    return newPubs;
-}
-
 // pass BDSKUnkownStringType to allow BDSKStringParser to sniff the text and 
determine the format
 - (NSArray *)publicationsForString:(NSString *)string 
type:(BDSKStringType)type verbose:(BOOL)verbose error:(NSError **)outError {
     NSArray *newPubs = nil;

Modified: trunk/bibdesk/BibDocument_Groups.m
===================================================================
--- trunk/bibdesk/BibDocument_Groups.m  2012-02-02 12:59:05 UTC (rev 18464)
+++ trunk/bibdesk/BibDocument_Groups.m  2012-02-02 13:14:04 UTC (rev 18465)
@@ -1276,16 +1276,8 @@
         return [NSArray array];
     
     // archive and unarchive mainly to get complex strings with the correct 
macroResolver
-    NSMutableData *data = [NSMutableData data];
-    NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] 
initForWritingWithMutableData:data];
-    NSArray *newPubs;
+    NSArray *newPubs = [BibItem publicationsFromArchivedData:[BibItem 
archivedPublications:array] macroResolver:[self macroResolver]];
     
-    [archiver encodeObject:array forKey:@"publications"];
-    [archiver finishEncoding];
-    [archiver release];
-    
-    newPubs = [self publicationsFromArchivedData:data];
-    
     [self addPublications:newPubs publicationsToAutoFile:nil 
temporaryCiteKey:nil selectLibrary:YES edit:NO];
        
        [[self undoManager] setActionName:NSLocalizedString(@"Merge External 
Publications", @"Undo action name")];
@@ -1596,7 +1588,7 @@
     [archiver finishEncoding];
     [archiver release];
     
-    newPubs = [self publicationsFromArchivedData:data];
+    newPubs = [BibItem publicationsFromArchivedData:data macroResolver:[self 
macroResolver]];
        
     [self addPublications:newPubs publicationsToAutoFile:nil 
temporaryCiteKey:nil selectLibrary:NO edit:NO];
     

Modified: trunk/bibdesk/BibItem.h
===================================================================
--- trunk/bibdesk/BibItem.h     2012-02-02 12:59:05 UTC (rev 18464)
+++ trunk/bibdesk/BibItem.h     2012-02-02 13:14:04 UTC (rev 18465)
@@ -103,6 +103,9 @@
 
 + (NSString *)defaultCiteKey;
 
++ (NSData *)archivedPublications:(NSArray *)array;
++ (NSArray *)publicationsFromArchivedData:(NSData *)data 
macroResolver:(BDSKMacroResolver *)aMacroResolver;
+
 - (NSArray *)files;
 - (NSUInteger)countOfFiles;
 - (BDSKLinkedFile *)objectInFilesAtIndex:(NSUInteger)idx;

Modified: trunk/bibdesk/BibItem.m
===================================================================
--- trunk/bibdesk/BibItem.m     2012-02-02 12:59:05 UTC (rev 18464)
+++ trunk/bibdesk/BibItem.m     2012-02-02 13:14:04 UTC (rev 18465)
@@ -527,6 +527,36 @@
 }
 #endif
 
+#pragma mark Archiving
+
++ (NSData *)archivedPublications:(NSArray *)array {
+    NSMutableData *data = [NSMutableData data];
+    NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] 
initForWritingWithMutableData:data];
+    
+    [archiver encodeObject:array forKey:@"publications"];
+    [archiver finishEncoding];
+    [archiver release];
+    
+    return data;
+}
+
++ (NSArray *)publicationsFromArchivedData:(NSData *)data 
macroResolver:(BDSKMacroResolver *)aMacroResolver {
+    NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] 
initForReadingWithData:data];
+    
+    [NSString setMacroResolverForUnarchiving:aMacroResolver];
+    
+    NSArray *pubs = [unarchiver decodeObjectForKey:@"publications"];
+    [unarchiver finishDecoding];
+    [unarchiver release];
+    
+    [NSString setMacroResolverForUnarchiving:nil];
+    
+    // we set the macroResolver so we know the fields of this item may refer 
to it, so we can prevent scripting from adding this to the wrong document
+    [pubs setValue:aMacroResolver forKey:@"macroResolver"];
+    
+    return pubs;
+}
+
 #pragma mark -
 
 - (void)customFieldsDidChange:(NSNotification *)aNotification{

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


------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit

Reply via email to