Revision: 15396
          http://sourceforge.net/p/skim-app/code/15396
Author:   hofman
Date:     2025-06-07 15:11:08 +0000 (Sat, 07 Jun 2025)
Log Message:
-----------
check whether popup is in annotations rather than checking page property, 
because the page property rremains after removal

Modified Paths:
--------------
    trunk/PDFDocument_SKExtensions.m
    trunk/SKMainWindowController.m

Modified: trunk/PDFDocument_SKExtensions.m
===================================================================
--- trunk/PDFDocument_SKExtensions.m    2025-06-07 09:16:04 UTC (rev 15395)
+++ trunk/PDFDocument_SKExtensions.m    2025-06-07 15:11:08 UTC (rev 15396)
@@ -303,7 +303,7 @@
     PDFAnnotation *popup = [annotation popup];
     NSDictionary *userInfo = @{SKPDFDocumentAnnotationKey:annotation, 
SKPDFDocumentPageKey:page};
     [page addAnnotation:annotation];
-    if (popup && [popup page] == nil)
+    if (popup && [[page annotations] containsObject:popup] == NO)
         [page addAnnotation:popup];
     [[NSNotificationCenter defaultCenter] 
postNotificationName:SKPDFDocumentDidAddAnnotationNotification object:self 
userInfo:userInfo];
 }
@@ -314,7 +314,7 @@
     NSDictionary *userInfo = @{SKPDFDocumentAnnotationKey:annotation, 
SKPDFDocumentPageKey:page};
     [[NSNotificationCenter defaultCenter] 
postNotificationName:SKPDFDocumentWillRemoveAnnotationNotification object:self 
userInfo:userInfo];
     [page removeAnnotation:annotation];
-    if (popup && [popup page])
+    if (popup && [[page annotations] containsObject:popup])
         [page removeAnnotation:popup];
     [[NSNotificationCenter defaultCenter] 
postNotificationName:SKPDFDocumentDidRemoveAnnotationNotification object:self 
userInfo:userInfo];
 }

Modified: trunk/SKMainWindowController.m
===================================================================
--- trunk/SKMainWindowController.m      2025-06-07 09:16:04 UTC (rev 15395)
+++ trunk/SKMainWindowController.m      2025-06-07 15:11:08 UTC (rev 15396)
@@ -965,6 +965,58 @@
     return properties;
 }
 
+- (void)addAnnotations:(NSArray *)notesToAdd removeAnnotations:(NSArray 
*)notesToRemove {
+    PDFDocument *pdfDoc = [pdfView document];
+    NSMutableIndexSet *pageIndexes = [NSMutableIndexSet indexSet];
+    NSMutableArray *added = [NSMutableArray array];
+    NSMutableArray *removed = [NSMutableArray array];
+    NSMutableArray *addedSkimNotes = [NSMutableArray array];
+    NSMutableIndexSet *removedIndexes = [NSMutableIndexSet indexSet];
+    
+    mwcFlags.addOrRemoveNotesInBulk = 1;
+    
+    if ([notesToRemove count]) {
+        for (PDFAnnotation *annotation in notesToRemove) {
+            [removed addObject:@[annotation, [annotation page]]];
+            if ([annotation isSkimNote])
+                [removedIndexes addIndex:[notes indexOfObject:annotation]];
+            [pageIndexes addIndex:[annotation pageIndex]];
+            [pdfDoc removeAnnotation:annotation];
+        }
+    }
+
+    if ([notesToAdd count]) {
+        for (NSArray *annotationAndPage in notesToAdd) {
+            PDFAnnotation *annotation = [annotationAndPage firstObject];
+            [added addObject:annotation];
+            if ([annotation isSkimNote])
+                [addedSkimNotes addObject:annotation];
+            [pageIndexes addIndex:[annotation pageIndex]];
+            [pdfDoc addAnnotation:annotation toPage:[annotationAndPage 
lastObject]];
+        }
+    }
+
+    mwcFlags.addOrRemoveNotesInBulk = 0;
+    
+    [[[self undoManager] prepareWithInvocationTarget:self] 
addAnnotations:removed removeAnnotations:added];
+    
+    if ([removedIndexes count])
+        [[self mutableArrayValueForKey:NOTES_KEY] 
removeObjectsAtIndexes:removedIndexes];
+    if ([addedSkimNotes count])
+        [self insertNotes:addedSkimNotes atIndexes:[NSIndexSet 
indexSetWithIndexesInRange:NSMakeRange([notes count], [addedSkimNotes count])]];
+    
+    // make sure we clear the undo handling
+    undoGroupOldPropertiesPerNote = nil;
+    [rightSideController.noteArrayController rearrangeObjects]; // doesn't 
seem to be done automatically
+    [rightSideController.noteOutlineView reloadData];
+    [self updateThumbnailsAtPageIndexes:pageIndexes];
+    for (SKSnapshotWindowController *wc in snapshots) {
+        if ([wc isPageInIndexesVisible:pageIndexes])
+            [self snapshotNeedsUpdate:wc lowPriority:NO];
+    }
+    [pdfView resetPDFToolTipRects];
+}
+
 - (void)addAnnotationsFromDictionaries:(NSArray *)noteDicts 
toDocument:(PDFDocument *)pdfDoc pageIndexes:(NSMutableIndexSet *)pageIndexes 
autoUpdate:(BOOL)autoUpdate {
     NSMutableArray *notesToAdd = [NSMutableArray array];
     BOOL shouldDisplay = [pdfView hideNotes] == NO;

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