Revision: 15405
          http://sourceforge.net/p/skim-app/code/15405
Author:   hofman
Date:     2025-06-08 08:45:07 +0000 (Sun, 08 Jun 2025)
Log Message:
-----------
separate methods to add and remove annotations oin bulk for add/replace and for 
convert

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

Modified: trunk/SKMainDocument.m
===================================================================
--- trunk/SKMainDocument.m      2025-06-08 08:37:40 UTC (rev 15404)
+++ trunk/SKMainDocument.m      2025-06-08 08:45:07 UTC (rev 15405)
@@ -1202,7 +1202,7 @@
             
             dispatch_async(dispatch_get_main_queue(), ^{
                 
-                [[self mainWindowController] 
addAnnotationsFromDictionaries:noteDicts removeAnnotations:annotations];
+                [[self mainWindowController] 
addConvertedAnnotationsFromDictionaries:noteDicts 
removeAnnotations:annotations];
                 
                 [self setPDFData:data pageOffsets:offsets];
                 

Modified: trunk/SKMainWindowController.h
===================================================================
--- trunk/SKMainWindowController.h      2025-06-08 08:37:40 UTC (rev 15404)
+++ trunk/SKMainWindowController.h      2025-06-08 08:45:07 UTC (rev 15405)
@@ -318,6 +318,7 @@
 
 - (void)setPdfDocument:(nullable PDFDocument *)pdfDocument 
addAnnotationsFromDictionaries:(nullable NSArray<NSDictionary<NSString *, id> 
*> *)noteDicts;
 - (void)addAnnotationsFromDictionaries:(NSArray<NSDictionary<NSString *, id> 
*> *)noteDicts removeAnnotations:(nullable NSArray<PDFAnnotation *> 
*)notesToRemove;
+- (void)addConvertedAnnotationsFromDictionaries:(NSArray<NSDictionary<NSString 
*, id> *> *)noteDicts removeAnnotations:(nullable NSArray<PDFAnnotation *> 
*)notesToRemove;
 
 - (void)applySetup:(NSDictionary<NSString *, id> *)setup;
 - (NSDictionary<NSString *, id> *)currentSetup;

Modified: trunk/SKMainWindowController.m
===================================================================
--- trunk/SKMainWindowController.m      2025-06-08 08:37:40 UTC (rev 15404)
+++ trunk/SKMainWindowController.m      2025-06-08 08:45:07 UTC (rev 15405)
@@ -984,7 +984,7 @@
             [pdfDoc removeAnnotation:annotation];
         }
     }
-
+    
     if ([notesAndPagesToAdd count]) {
         BOOL shouldDisplay = [pdfView hideNotes] == NO;
         for (NSArray *annotationAndPage in notesAndPagesToAdd) {
@@ -997,7 +997,7 @@
             [pdfDoc addAnnotation:annotation toPage:page];
         }
     }
-
+    
     mwcFlags.addOrRemoveNotesInBulk = 0;
     
     [[[[self document] undoManager] prepareWithInvocationTarget:self] 
addAnnotations:removedNotesAndPages removeAnnotations:addedNotes];
@@ -1050,32 +1050,34 @@
 }
 
 - (void)addAnnotationsFromDictionaries:(NSArray *)noteDicts 
removeAnnotations:(NSArray *)notesToRemove {
-    // notesToRemove is either nil (add), self.notes (replace), or non Skim 
notes (convert)
-    BOOL isAddOrReplace = [notesToRemove count] == 0 || [[notesToRemove 
firstObject] isSkimNote];
-    NSMutableArray *widgetDicts = isAddOrReplace ? [NSMutableArray array] : 
nil;
-    NSArray *notesAndPagesToAdd = [self 
annotationsAndPagesFromDictionaries:noteDicts forDocument:[pdfView document] 
autoUpdate:isAddOrReplace == NO widgetDictionaries:widgetDicts];
+    NSMutableArray *widgetDicts = [NSMutableArray array];
+    NSArray *notesAndPagesToAdd = [self 
annotationsAndPagesFromDictionaries:noteDicts forDocument:[pdfView document] 
autoUpdate:NO widgetDictionaries:widgetDicts];
     
-    if (isAddOrReplace) {
-        if ([notesToRemove count]) {
-            [pdfView removePDFToolTipRects];
-            // remove the current annotations
-            [pdfView setCurrentAnnotation:nil];
+    if ([notesToRemove count]) {
+        [pdfView removePDFToolTipRects];
+        // remove the current annotations
+        [pdfView setCurrentAnnotation:nil];
+    }
+    
+    if (notesToRemove && [widgets count]) {
+        for (PDFAnnotation *widget in widgets) {
+            id origValue = [widgetValues objectForKey:widget];
+            if ([([widget objectValue] ?: @"") isEqual:(origValue ?: @"")] == 
NO)
+                [widget setObjectValue:origValue];
         }
-        
-        if (notesToRemove && [widgets count]) {
-            for (PDFAnnotation *widget in widgets) {
-                id origValue = [widgetValues objectForKey:widget];
-                if ([([widget objectValue] ?: @"") isEqual:(origValue ?: @"")] 
== NO)
-                    [widget setObjectValue:origValue];
-            }
-        }
-        if ([widgetDicts count])
-            [self changeWidgetsFromDictionaries:widgetDicts];
     }
+    if ([widgetDicts count])
+        [self changeWidgetsFromDictionaries:widgetDicts];
     
     [self addAnnotations:notesAndPagesToAdd removeAnnotations:notesToRemove];
 }
 
+- (void)addConvertedAnnotationsFromDictionaries:(NSArray *)noteDicts 
removeAnnotations:(NSArray *)notesToRemove {
+    NSArray *notesAndPagesToAdd = [self 
annotationsAndPagesFromDictionaries:noteDicts forDocument:[pdfView document] 
autoUpdate:YES widgetDictionaries:nil];
+    
+    [self addAnnotations:notesAndPagesToAdd removeAnnotations:notesToRemove];
+}
+
 - (void)setPdfDocument:(PDFDocument *)pdfDocument 
addAnnotationsFromDictionaries:(NSArray *)noteDicts {
     PDFDocument *pdfDoc = pdfDocument;
     NSMutableArray *widgetProperties = nil;

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



_______________________________________________
Skim-app-commit mailing list
Skim-app-commit@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to