Revision: 9521
          http://sourceforge.net/p/skim-app/code/9521
Author:   hofman
Date:     2017-12-05 16:07:47 +0000 (Tue, 05 Dec 2017)
Log Message:
-----------
do slow part of note conversion in background on 10.12+

Modified Paths:
--------------
    trunk/SKMainDocument.m

Modified: trunk/SKMainDocument.m
===================================================================
--- trunk/SKMainDocument.m      2017-12-05 15:55:43 UTC (rev 9520)
+++ trunk/SKMainDocument.m      2017-12-05 16:07:47 UTC (rev 9521)
@@ -1118,29 +1118,48 @@
     }
     
     if (didConvert) {
+        
         // if pdfDocWithoutNotes was nil, the document was not encrypted, so 
no need to try to unlock
         if (pdfDocWithoutNotes == nil)
             pdfDocWithoutNotes = [[[PDFDocument alloc] initWithData:pdfData] 
autorelease];
-        count = [pdfDocWithoutNotes pageCount];
-        for (i = 0; i < count; i++) {
-            PDFPage *page = [pdfDocWithoutNotes pageAtIndex:i];
+        
+        dispatch_queue_t queue = floor(NSAppKitVersionNumber) > 
NSAppKitVersionNumber10_11 ? 
dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0) : 
dispatch_get_main_queue();
+
+        dispatch_async(queue, ^(){
+        
+            NSInteger i, count = [pdfDocWithoutNotes pageCount];
+            for (i = 0; i < count; i++) {
+                PDFPage *page = [pdfDocWithoutNotes pageAtIndex:i];
+                
+                for (PDFAnnotation *annotation in [[[page annotations] copy] 
autorelease]) {
+                    if ([annotation isConvertibleAnnotation])
+                        [page removeAnnotation:annotation];
+                }
+            }
             
-            for (PDFAnnotation *annotation in [[[page annotations] copy] 
autorelease]) {
-                if ([annotation isSkimNote] == NO && [annotation 
isConvertibleAnnotation])
-                    [page removeAnnotation:annotation];
-            }
-        }
+            NSData *pdfData = [pdfDocWithoutNotes dataRepresentation];
+            
+            dispatch_async(dispatch_get_main_queue(), ^(){
+                [self setPDFData:pdfData pageOffsets:offsets];
+            
+                [[self undoManager] setActionName:NSLocalizedString(@"Convert 
Notes", @"Undo action name")];
+                
+                [offsets release];
+                
+                [[pdfDocWithoutNotes outlineRoot] clearDocument];
+                
+                [[self mainWindowController] dismissProgressSheet];
+            });
+        });
         
-        [self setPDFData:[pdfDocWithoutNotes dataRepresentation] 
pageOffsets:offsets];
+    } else {
         
-        [[self undoManager] setActionName:NSLocalizedString(@"Convert Notes", 
@"Undo action name")];
+        [offsets release];
+
+        [[pdfDocWithoutNotes outlineRoot] clearDocument];
+        
+        [[self mainWindowController] dismissProgressSheet];
     }
-    
-    [offsets release];
-
-    [[pdfDocWithoutNotes outlineRoot] clearDocument];
-    
-    [[self mainWindowController] dismissProgressSheet];
 }
 
 - (void)beginConvertNotesPasswordSheetForPDFDocument:(PDFDocument *)pdfDoc {

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


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to