Revision: 27272
          http://sourceforge.net/p/bibdesk/svn/27272
Author:   hofman
Date:     2022-03-06 22:41:53 +0000 (Sun, 06 Mar 2022)
Log Message:
-----------
Determine whether to remember items or its derived data for promised copy 
implicitly based on pasteboard

Modified Paths:
--------------
    trunk/bibdesk/BDSKItemPasteboardHelper.h
    trunk/bibdesk/BDSKItemPasteboardHelper.m
    trunk/bibdesk/BibDocument.m
    trunk/bibdesk/BibDocument_DataSource.m

Modified: trunk/bibdesk/BDSKItemPasteboardHelper.h
===================================================================
--- trunk/bibdesk/BDSKItemPasteboardHelper.h    2022-03-06 20:07:20 UTC (rev 
27271)
+++ trunk/bibdesk/BDSKItemPasteboardHelper.h    2022-03-06 22:41:53 UTC (rev 
27272)
@@ -57,7 +57,7 @@
 
 - (void)terminate;
 
-- (void)writeItems:(NSArray *)items textRepresentation:(id)text 
forDragCopyType:(BDSKDragCopyType)dragCopyType toPasteboard:(NSPasteboard 
*)pboard converted:(BOOL)converted;
+- (void)writeItems:(NSArray *)items textRepresentation:(id)text 
forDragCopyType:(BDSKDragCopyType)dragCopyType toPasteboard:(NSPasteboard 
*)pboard;
 
 - (NSArray *)promisedItemsForPasteboard:(NSPasteboard *)pboard;
 - (void)clearPromisedTypesForPasteboard:(NSPasteboard *)pboard;

Modified: trunk/bibdesk/BDSKItemPasteboardHelper.m
===================================================================
--- trunk/bibdesk/BDSKItemPasteboardHelper.m    2022-03-06 20:07:20 UTC (rev 
27271)
+++ trunk/bibdesk/BDSKItemPasteboardHelper.m    2022-03-06 22:41:53 UTC (rev 
27272)
@@ -52,7 +52,7 @@
 - (BDSKDragCopyType)promisedDragCopyTypeForPasteboard:(NSPasteboard *)pboard;
 - (NSString *)promisedBibTeXStringForPasteboard:(NSPasteboard *)pboard;
 - (NSArray *)promisedCiteKeysForPasteboard:(NSPasteboard *)pboard;
-- (void)setPromisedTypes:(NSMutableArray *)types items:(NSArray *)items 
dragCopyType:(BDSKDragCopyType)dragCopyType forPasteboard:(NSPasteboard 
*)pboard converted:(BOOL)converted;
+- (void)setPromisedTypes:(NSMutableArray *)types items:(NSArray *)items 
dragCopyType:(BDSKDragCopyType)dragCopyType forPasteboard:(NSPasteboard 
*)pboard;
 - (void)removePromisedType:(NSString *)type forPasteboard:(NSPasteboard 
*)pboard;
 - (void)removePromisedTypesForPasteboard:(NSPasteboard *)pboard;
 
@@ -112,11 +112,12 @@
 
 #pragma mark Promising and adding data
 
-- (void)writeItems:(NSArray *)items textRepresentation:(id)text 
forDragCopyType:(BDSKDragCopyType)dragCopyType toPasteboard:(NSPasteboard 
*)pboard converted:(BOOL)converted {
+- (void)writeItems:(NSArray *)items textRepresentation:(id)text 
forDragCopyType:(BDSKDragCopyType)dragCopyType toPasteboard:(NSPasteboard 
*)pboard {
     
     NSMutableArray *types = [NSMutableArray array];
+    BOOL shouldArchive = pboard == [NSPasteboard generalPasteboard];
     
-    if (converted == NO)
+    if (shouldArchive == NO)
         [types addObject:BDSKPasteboardTypePublications];
     
     switch (dragCopyType) {
@@ -139,7 +140,7 @@
     BDSKASSERT([promisedPboardTypes objectForKey:[pboard name]] == nil);
     
     if ([types count])
-        [self setPromisedTypes:types items:items dragCopyType:dragCopyType 
forPasteboard:pboard converted:converted];
+        [self setPromisedTypes:types items:items dragCopyType:dragCopyType 
forPasteboard:pboard];
     
     NSPasteboardItem *item = nil;
     BOOL needsWrite = NO;
@@ -154,7 +155,7 @@
     }
     if (text)
         [item setString:text forType:NSPasteboardTypeString];
-    if (converted)
+    if (shouldArchive)
         [item setData:[BibItem archivedPublications:items] 
forType:BDSKPasteboardTypePublications];
     if ([types count])
         [item setDataProvider:self forTypes:types];
@@ -333,17 +334,17 @@
        return [self pasteboardIsValid:pboard] ? [[promisedPboardTypes 
objectForKey:[pboard name]] objectForKey:@"citeKeys"] : nil;
 }
 
-- (void)setPromisedTypes:(NSMutableArray *)types items:(NSArray *)items 
dragCopyType:(BDSKDragCopyType)dragCopyType forPasteboard:(NSPasteboard 
*)pboard converted:(BOOL)converted {
+- (void)setPromisedTypes:(NSMutableArray *)types items:(NSArray *)items 
dragCopyType:(BDSKDragCopyType)dragCopyType forPasteboard:(NSPasteboard 
*)pboard {
     if ([self pasteboardIsValid:pboard]) {
         NSMutableDictionary *dict = [NSMutableDictionary 
dictionaryWithObjectsAndKeys:types, @"types", [NSNumber 
numberWithInteger:dragCopyType], @"dragCopyType", nil];
-        if (converted == NO) {
+        if ([types containsObject:BDSKPasteboardTypePublications]) {
+            [dict setObject:items forKey:@"items"];
+        } else {
             NSString *bibString = [delegate pasteboardHelper:self 
bibTeXStringForItems:items];
             if (bibString != nil) {
                 [dict setObject:bibString forKey:@"bibTeXString"];
                 [dict setObject:[items valueForKey:@"citeKey"] 
forKey:@"citeKeys"];
             }
-        } else {
-            [dict setObject:items forKey:@"items"];
         }
         if (promisedPboardTypes == nil) {
             promisedPboardTypes = [[NSMutableDictionary alloc] 
initWithCapacity:2];
@@ -369,7 +370,7 @@
             [promisedPboardTypes release];
             promisedPboardTypes = nil;
             // we used promisedPboardTypes != nil to signal we retained 
ourselves
-            // see setPromisedTypes:items:dragCopyType:forPasteboard:converted:
+            // see setPromisedTypes:items:dragCopyType:forPasteboard:
             [self autorelease];
         }
     }

Modified: trunk/bibdesk/BibDocument.m
===================================================================
--- trunk/bibdesk/BibDocument.m 2022-03-06 20:07:20 UTC (rev 27271)
+++ trunk/bibdesk/BibDocument.m 2022-03-06 22:41:53 UTC (rev 27272)
@@ -1591,7 +1591,7 @@
     NSPasteboard *pboard = [NSPasteboard pasteboardWithUniqueName];
     if (pboardHelper == nil)
         pboardHelper = [[BDSKItemPasteboardHelper alloc] 
initWithDelegate:self];
-    [pboardHelper writeItems:[self publicationsForSaving] 
textRepresentation:nil forDragCopyType:BDSKDragCopyLTB toPasteboard:pboard 
converted:NO];
+    [pboardHelper writeItems:[self publicationsForSaving] 
textRepresentation:nil forDragCopyType:BDSKDragCopyLTB toPasteboard:pboard];
     NSArray *ltbStrings = [pboard readObjectsForClasses:[NSArray 
arrayWithObject:[NSString class]] options:[NSDictionary dictionary]];
     [pboard clearContents]; // this will clear the pasteboard helper for this 
pasteboard
     [pboardHelper clearPromisedTypesForPasteboard:pboard]; // just to be sure

Modified: trunk/bibdesk/BibDocument_DataSource.m
===================================================================
--- trunk/bibdesk/BibDocument_DataSource.m      2022-03-06 20:07:20 UTC (rev 
27271)
+++ trunk/bibdesk/BibDocument_DataSource.m      2022-03-06 22:41:53 UTC (rev 
27272)
@@ -450,7 +450,7 @@
     
     if (pboardHelper == nil)
         pboardHelper = [[BDSKItemPasteboardHelper alloc] 
initWithDelegate:self];
-    [pboardHelper writeItems:pubs textRepresentation:text 
forDragCopyType:dragCopyType toPasteboard:pboard converted:pboard == 
[NSPasteboard generalPasteboard]];
+    [pboardHelper writeItems:pubs textRepresentation:text 
forDragCopyType:dragCopyType toPasteboard:pboard];
     
     return YES;
 }

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

Reply via email to