Revision: 13430
          http://sourceforge.net/p/skim-app/code/13430
Author:   hofman
Date:     2023-04-29 16:27:52 +0000 (Sat, 29 Apr 2023)
Log Message:
-----------
add page labels when copying multiple pages

Modified Paths:
--------------
    trunk/PDFPage_SKExtensions.m
    trunk/SKThumbnailView.m

Modified: trunk/PDFPage_SKExtensions.m
===================================================================
--- trunk/PDFPage_SKExtensions.m        2023-04-29 16:08:05 UTC (rev 13429)
+++ trunk/PDFPage_SKExtensions.m        2023-04-29 16:27:52 UTC (rev 13430)
@@ -332,9 +332,7 @@
 // the page is set as owner in -filePromise
 - (void)pasteboard:(NSPasteboard *)pboard item:(NSPasteboardItem *)item 
provideDataForType:(NSString *)type {
     if ([type isEqualToString:(NSString *)kPasteboardTypeFileURLPromise]) {
-        NSURL *dropDestination = [pboard pasteLocationURL];
-        NSString *filename = [NSString stringWithFormat:@"%@ %c %@", ([[[self 
containingDocument] displayName] stringByDeletingPathExtension] ?: @"PDF"), 
'-', [NSString stringWithFormat:NSLocalizedString(@"Page %@", @""), [self 
displayLabel]]];
-        NSURL *fileURL = [dropDestination URLByAppendingPathComponent:filename 
isDirectory:NO];
+        NSString *label = [self displayLabel];
         NSString *pathExt = nil;
         NSData *data = nil;
         
@@ -342,8 +340,15 @@
             pathExt = @"pdf";
             NSIndexSet *pageIndexes = nil;
             NSData *indexData = [item dataForType:SKPasteboardTypePageIndexes];
-            if (indexData)
+            if (indexData) {
                 pageIndexes = [NSKeyedUnarchiver 
unarchiveObjectWithData:indexData];
+                NSMutableArray *labels = [NSMutableArray array];
+                [pageIndexes enumerateIndexesUsingBlock:^(NSUInteger i, BOOL 
*stop){
+                    [labels addObject:[[self document] pageAtIndex:i]];
+                }];
+                if ([labels count])
+                    label = [labels componentsJoinedByString:@", "];
+            }
             data = [self dataRepresentationForPageIndexes:pageIndexes];
         } else {
             pathExt = @"tiff";
@@ -350,6 +355,9 @@
             data = [self TIFFDataForRect:[self 
boundsForBox:kPDFDisplayBoxCropBox]];
         }
         
+        NSURL *dropDestination = [pboard pasteLocationURL];
+        NSString *filename = [NSString stringWithFormat:@"%@ %c %@", ([[[self 
containingDocument] displayName] stringByDeletingPathExtension] ?: @"PDF"), 
'-', [NSString stringWithFormat:NSLocalizedString(@"Page %@", @""), label]];
+        NSURL *fileURL = [dropDestination URLByAppendingPathComponent:filename 
isDirectory:NO];
         fileURL = [[fileURL URLByAppendingPathExtension:pathExt] 
uniqueFileURL];
         if ([data writeToURL:fileURL atomically:YES])
             [item setString:[fileURL absoluteString] forType:type];
@@ -368,7 +376,16 @@
 
 // the page is set as delegate in -filePromise
 - (NSString *)filePromiseProvider:(NSFilePromiseProvider *)filePromiseProvider 
fileNameForType:(NSString *)fileType {
-    NSString *filename = [NSString stringWithFormat:@"%@ %c %@", ([[[self 
containingDocument] displayName] stringByDeletingPathExtension] ?: @"PDF"), 
'-', [NSString stringWithFormat:NSLocalizedString(@"Page %@", @""), [self 
displayLabel]]];
+    NSString *label = [self displayLabel];
+    NSIndexSet *pageIndexes = [filePromiseProvider userInfo];
+    if (pageIndexes && [[self document] allowsPrinting]) {
+        NSMutableArray *labels = [NSMutableArray array];
+        [pageIndexes enumerateIndexesUsingBlock:^(NSUInteger i, BOOL *stop){
+            [labels addObject:[[self document] pageAtIndex:i]];
+        }];
+        label = [labels componentsJoinedByString:@", "];
+    }
+    NSString *filename = [NSString stringWithFormat:@"%@ %c %@", ([[[self 
containingDocument] displayName] stringByDeletingPathExtension] ?: @"PDF"), 
'-', [NSString stringWithFormat:NSLocalizedString(@"Page %@", @""), label]];
     NSString *pathExt = [[self document] allowsPrinting] ? @"pdf" : @"tiff";
     return [filename stringByAppendingPathExtension:pathExt];
 }

Modified: trunk/SKThumbnailView.m
===================================================================
--- trunk/SKThumbnailView.m     2023-04-29 16:08:05 UTC (rev 13429)
+++ trunk/SKThumbnailView.m     2023-04-29 16:27:52 UTC (rev 13430)
@@ -454,10 +454,11 @@
     NSString *name = [[[[self window] windowController] document] displayName];
     if (selectionIndexes) {
         [selectionIndexes enumerateIndexesUsingBlock:^(NSUInteger i, BOOL 
*stop){
-            NSURL *url = [[[page document] pageAtIndex:i] skimURL];
+            PDFPage *aPage = [[page document] pageAtIndex:i];
+            NSURL *url = [aPage skimURL];
             if (url) {
                 [urls addObject:url];
-                [names addObject:name];
+                [names addObject:[name stringByAppendingFormat:@" (%@)", 
[NSString stringWithFormat:NSLocalizedString(@"Page %@", @""), [aPage 
displayLabel]]]];
             }
         }];
     } else {

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



_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to