Revision: 13622
          http://sourceforge.net/p/skim-app/code/13622
Author:   hofman
Date:     2023-08-31 16:30:10 +0000 (Thu, 31 Aug 2023)
Log Message:
-----------
add/remove/move annotations in PDFDocument class, sending notifications that 
update the PDFView and window controllers. Undo implemented in main 
windowcontroller class.

Modified Paths:
--------------
    trunk/PDFDocument_SKExtensions.h
    trunk/PDFDocument_SKExtensions.m
    trunk/PDFPage_SKExtensions.m
    trunk/SKMainDocument.m
    trunk/SKMainWindowController.h
    trunk/SKMainWindowController.m
    trunk/SKMainWindowController_FullScreen.m
    trunk/SKMainWindowController_UI.m
    trunk/SKPDFView.h
    trunk/SKPDFView.m
    trunk/SKSnapshotWindowController.m

Modified: trunk/PDFDocument_SKExtensions.h
===================================================================
--- trunk/PDFDocument_SKExtensions.h    2023-08-31 09:35:13 UTC (rev 13621)
+++ trunk/PDFDocument_SKExtensions.h    2023-08-31 16:30:10 UTC (rev 13622)
@@ -39,6 +39,16 @@
 #import <Cocoa/Cocoa.h>
 #import <Quartz/Quartz.h>
 
+extern NSString *SKPDFDocumentDidAddAnnotationNotification;
+extern NSString *SKPDFDocumentWillRemoveAnnotationNotification;
+extern NSString *SKPDFDocumentDidRemoveAnnotationNotification;
+extern NSString *SKPDFDocumentWillMoveAnnotationNotification;
+extern NSString *SKPDFDocumentDidMoveAnnotationNotification;
+
+extern NSString *SKPDFDocumentAnnotationKey;
+extern NSString *SKPDFDocumentPageKey;
+extern NSString *SKPDFDocumentOldPageKey;
+
 typedef struct _SKLanguageDirectionAngles {
     NSInteger characterDirection;
     NSInteger lineDirection;
@@ -54,4 +64,7 @@
 - (NSDocument *)containingDocument;
 - (NSArray *)detectedWidgets;
 - (void)setContainingDocument:(NSDocument *)document;
+- (void)addAnnotation:(PDFAnnotation *)annotation toPage:(PDFPage *)page;
+- (void)removeAnnotation:(PDFAnnotation *)annotation;
+- (void)moveAnnotation:(PDFAnnotation *)annotation toPage:(PDFPage *)page;
 @end

Modified: trunk/PDFDocument_SKExtensions.m
===================================================================
--- trunk/PDFDocument_SKExtensions.m    2023-08-31 09:35:13 UTC (rev 13621)
+++ trunk/PDFDocument_SKExtensions.m    2023-08-31 16:30:10 UTC (rev 13622)
@@ -42,8 +42,18 @@
 #import "PDFPage_SKExtensions.h"
 #import "NSData_SKExtensions.h"
 #import "NSDocument_SKExtensions.h"
+#import "PDFAnnotation_SKExtensions.h"
 
+NSString *SKPDFDocumentDidAddAnnotationNotification = 
@"SKPDFDocumentDidAddAnnotationNotification";
+NSString *SKPDFDocumentWillRemoveAnnotationNotification = 
@"SKPDFDocumentWillRemoveAnnotationNotification";
+NSString *SKPDFDocumentDidRemoveAnnotationNotification = 
@"SKPDFDocumentDidRemoveAnnotationNotification";
+NSString *SKPDFDocumentWillMoveAnnotationNotification = 
@"SKPDFDocumentWillMoveAnnotationNotification";
+NSString *SKPDFDocumentDidMoveAnnotationNotification = 
@"SKPDFDocumentDidMoveAnnotationNotification";
 
+NSString *SKPDFDocumentAnnotationKey = @"annotation";
+NSString *SKPDFDocumentPageKey = @"page";
+NSString *SKPDFDocumentOldPageKey = @"oldPage";
+
 #if SDK_BEFORE(10_13)
 
 @interface PDFDocument (SKHighSierraDeclarations)
@@ -298,4 +308,31 @@
 
 - (NSArray *)detectedWidgets { return nil; }
 
+- (void)addAnnotation:(PDFAnnotation *)annotation toPage:(PDFPage *)page {
+    NSDictionary *userInfo = @{SKPDFDocumentAnnotationKey:annotation, 
SKPDFDocumentPageKey:page};
+    [page addAnnotation:annotation];
+    [[NSNotificationCenter defaultCenter] 
postNotificationName:SKPDFDocumentDidAddAnnotationNotification object:self 
userInfo:userInfo];
+}
+
+- (void)removeAnnotation:(PDFAnnotation *)annotation {
+    PDFPage *page = [annotation page];
+    NSDictionary *userInfo = @{SKPDFDocumentAnnotationKey:annotation, 
SKPDFDocumentPageKey:page};
+    [[NSNotificationCenter defaultCenter] 
postNotificationName:SKPDFDocumentWillRemoveAnnotationNotification object:self 
userInfo:userInfo];
+    [page removeAnnotation:annotation];
+    if (RUNNING(10_12) && [annotation isNote] && [[page annotations] 
containsObject:annotation])
+        [page removeAnnotation:annotation];
+    [[NSNotificationCenter defaultCenter] 
postNotificationName:SKPDFDocumentDidRemoveAnnotationNotification object:self 
userInfo:userInfo];
+}
+
+- (void)moveAnnotation:(PDFAnnotation *)annotation toPage:(PDFPage *)page {
+    PDFPage *oldPage = [annotation page];
+    NSDictionary *userInfo = @{SKPDFDocumentAnnotationKey:annotation, 
SKPDFDocumentPageKey:page, SKPDFDocumentOldPageKey:oldPage};
+    [[NSNotificationCenter defaultCenter] 
postNotificationName:SKPDFDocumentWillMoveAnnotationNotification object:self 
userInfo:userInfo];
+    [oldPage removeAnnotation:annotation];
+    if (RUNNING(10_12) && [annotation isNote] && [[oldPage annotations] 
containsObject:annotation])
+        [oldPage removeAnnotation:annotation];
+    [page addAnnotation:annotation];
+    [[NSNotificationCenter defaultCenter] 
postNotificationName:SKPDFDocumentDidMoveAnnotationNotification object:self 
userInfo:userInfo];
+}
+
 @end

Modified: trunk/PDFPage_SKExtensions.m
===================================================================
--- trunk/PDFPage_SKExtensions.m        2023-08-31 09:35:13 UTC (rev 13621)
+++ trunk/PDFPage_SKExtensions.m        2023-08-31 16:30:10 UTC (rev 13622)
@@ -38,8 +38,6 @@
 
 #import "PDFPage_SKExtensions.h"
 #import <SkimNotes/SkimNotes.h>
-#import "SKMainDocument.h"
-#import "SKPDFView.h"
 #import "SKReadingBar.h"
 #import "PDFSelection_SKExtensions.h"
 #import "SKRuntime.h"
@@ -752,10 +750,8 @@
 
 - (void)insertObject:(id)newNote inNotesAtIndex:(NSUInteger)anIndex {
     if ([self isEditable] && [[self document] allowsNotes]) {
-        SKPDFView *pdfView = [(SKMainDocument *)[self containingDocument] 
pdfView];
-        
-        [pdfView addAnnotation:newNote toPage:self];
-        [[pdfView undoManager] setActionName:NSLocalizedString(@"Add Note", 
@"Undo action name")];
+        [[self document] addAnnotation:newNote toPage:self];
+        [[[self containingDocument] undoManager] 
setActionName:NSLocalizedString(@"Add Note", @"Undo action name")];
     }
 }
 
@@ -762,10 +758,8 @@
 - (void)removeObjectFromNotesAtIndex:(NSUInteger)anIndex {
     if ([self isEditable] && [[self document] allowsNotes]) {
         PDFAnnotation *note = [[self notes] objectAtIndex:anIndex];
-        SKPDFView *pdfView = [(SKMainDocument *)[self containingDocument] 
pdfView];
-        
-        [pdfView removeAnnotation:note];
-        [[pdfView undoManager] setActionName:NSLocalizedString(@"Remove Note", 
@"Undo action name")];
+        [[self document] removeAnnotation:note];
+        [[[self containingDocument] undoManager] 
setActionName:NSLocalizedString(@"Remove Note", @"Undo action name")];
     }
 }
 

Modified: trunk/SKMainDocument.m
===================================================================
--- trunk/SKMainDocument.m      2023-08-31 09:35:13 UTC (rev 13621)
+++ trunk/SKMainDocument.m      2023-08-31 16:30:10 UTC (rev 13622)
@@ -1710,9 +1710,7 @@
     if ([[self pdfDocument] allowsNotes]) {
         PDFPage *page = [newNote page];
         if (page && [[page annotations] containsObject:newNote] == NO) {
-            SKPDFView *pdfView = [self pdfView];
-            
-            [pdfView addAnnotation:newNote toPage:page];
+            [[self pdfDocument] addAnnotation:newNote toPage:page];
             [[self undoManager] setActionName:NSLocalizedString(@"Add Note", 
@"Undo action name")];
         } else {
             [[NSScriptCommand currentCommand] 
setScriptErrorNumber:NSReceiversCantHandleCommandScriptError];
@@ -1724,7 +1722,7 @@
     if ([[self pdfDocument] allowsNotes]) {
         PDFAnnotation *note = [[self notes] objectAtIndex:anIndex];
         
-        [[self pdfView] removeAnnotation:note];
+        [[self pdfDocument] removeAnnotation:note];
         [[self undoManager] setActionName:NSLocalizedString(@"Remove Note", 
@"Undo action name")];
     }
 }

Modified: trunk/SKMainWindowController.h
===================================================================
--- trunk/SKMainWindowController.h      2023-08-31 09:35:13 UTC (rev 13621)
+++ trunk/SKMainWindowController.h      2023-08-31 16:30:10 UTC (rev 13622)
@@ -136,7 +136,10 @@
     SKSnapshotWindowController          *presentationPreview;
     NSButton                            *presentationNotesButton;
     NSTrackingArea                      *presentationNotesTrackingArea;
-
+    
+    NSMutableArray                      *presentationNotes;
+    NSUndoManager                       *presentationUndoManager;
+    
     NSButton                            *colorAccessoryView;
     NSButton                            *textColorAccessoryView;
     
@@ -271,6 +274,8 @@
 @property (nonatomic, retain) NSDocument *presentationNotesDocument;
 @property (nonatomic) NSInteger presentationNotesOffset;
 
+@property (nonatomic, readonly) NSUndoManager *presentationUndoManager;
+
 @property (nonatomic, copy) NSArray *tags;
 @property (nonatomic) double rating;
 

Modified: trunk/SKMainWindowController.m
===================================================================
--- trunk/SKMainWindowController.m      2023-08-31 09:35:13 UTC (rev 13621)
+++ trunk/SKMainWindowController.m      2023-08-31 16:30:10 UTC (rev 13622)
@@ -228,7 +228,7 @@
 @implementation SKMainWindowController
 
 @synthesize mainWindow, splitView, centerContentView, pdfSplitView, 
pdfContentView, statusBar, pdfView, secondaryPdfView, leftSideController, 
rightSideController, toolbarController, leftSideContentView, 
rightSideContentView, presentationNotesDocument, presentationNotesOffset, tags, 
rating, pageLabel, interactionMode, placeholderPdfDocument;
-@dynamic pdfDocument, presentationOptions, selectedNotes, hasNotes, 
widgetProperties, autoScales, leftSidePaneState, rightSidePaneState, 
findPaneState, leftSidePaneIsOpen, rightSidePaneIsOpen, recentInfoNeedsUpdate, 
searchString, hasOverview, notesMenu;
+@dynamic pdfDocument, presentationOptions, presentationUndoManager, 
selectedNotes, hasNotes, widgetProperties, autoScales, leftSidePaneState, 
rightSidePaneState, findPaneState, leftSidePaneIsOpen, rightSidePaneIsOpen, 
recentInfoNeedsUpdate, searchString, hasOverview, notesMenu;
 
 + (void)initialize {
     SKINITIALIZE;
@@ -319,6 +319,8 @@
     SKDESTROY(overviewContentView);
     SKDESTROY(fieldEditor);
     SKDESTROY(presentationNotesDocument);
+    SKDESTROY(presentationNotes);
+    SKDESTROY(presentationUndoManager);
     [super dealloc];
 }
 
@@ -1059,8 +1061,8 @@
             [pageIndexes addIndex:[annotation pageIndex]];
             PDFAnnotation *popup = [annotation popup];
             if (popup)
-                [pdfView removeAnnotation:popup];
-            [pdfView removeAnnotation:annotation];
+                [pdfDoc removeAnnotation:popup];
+            [pdfDoc removeAnnotation:annotation];
         }
         if (removeAllNotes)
             [self removeAllObjectsFromNotes];
@@ -1088,7 +1090,7 @@
                 pageIndex = [pdfDoc pageCount] - 1;
             [pageIndexes addIndex:pageIndex];
             PDFPage *page = [pdfDoc pageAtIndex:pageIndex];
-            [pdfView addAnnotation:annotation toPage:page];
+            [pdfDoc addAnnotation:annotation toPage:page];
             if (isConvert && [[annotation contents] length] == 0)
                 [annotation autoUpdateString];
             [notesToAdd addObject:annotation];
@@ -1575,6 +1577,12 @@
     }
 }
 
+- (NSUndoManager *)presentationUndoManager {
+    if (presentationUndoManager == nil)
+        presentationUndoManager = [[NSUndoManager alloc] init];
+    return presentationUndoManager;
+}
+
 - (BOOL)recentInfoNeedsUpdate {
     return mwcFlags.recentInfoNeedsUpdate && [self isWindowLoaded] && [[self 
window] delegate];
 }
@@ -2319,6 +2327,100 @@
     [self incrementProgressSheet];
 }
 
+- (void)handleDidAddAnnotationNotification:(NSNotification *)notification {
+    NSDictionary *userInfo = [notification userInfo];
+    PDFAnnotation *annotation = [userInfo 
objectForKey:SKPDFDocumentAnnotationKey];
+    PDFPage *page = [userInfo objectForKey:SKPDFDocumentPageKey];
+    NSUndoManager *undoManager = [self interactionMode] == SKPresentationMode 
? [self presentationUndoManager] : [[self document] undoManager];
+    
+    [[undoManager prepareWithInvocationTarget:[notification object]] 
removeAnnotation:annotation];
+    
+    if ([self interactionMode] == SKPresentationMode) {
+        if (presentationNotes == nil)
+            presentationNotes = [[NSMutableArray alloc] init];
+        [presentationNotes addObject:annotation];
+        if (page)
+            [self updateThumbnailAtPageIndex:[page pageIndex]];
+    } else {
+        if ([annotation isSkimNote] && mwcFlags.addOrRemoveNotesInBulk == 0) {
+            mwcFlags.updatingNoteSelection = 1;
+            [[self mutableArrayValueForKey:NOTES_KEY] addObject:annotation];
+            [rightSideController.noteArrayController rearrangeObjects]; // 
doesn't seem to be done automatically
+            mwcFlags.updatingNoteSelection = 0;
+            [rightSideController.noteOutlineView reloadData];
+        }
+        if (page) {
+            [self updateThumbnailAtPageIndex:[page pageIndex]];
+            for (SKSnapshotWindowController *wc in snapshots) {
+                if ([wc isPageVisible:page])
+                    [self snapshotNeedsUpdate:wc];
+            }
+            [secondaryPdfView setNeedsDisplayForAnnotation:annotation 
onPage:page];
+        }
+    }
+}
+
+- (void)handleDidRemoveAnnotationNotification:(NSNotification *)notification {
+    NSDictionary *userInfo = [notification userInfo];
+    PDFAnnotation *annotation = [userInfo 
objectForKey:SKPDFDocumentAnnotationKey];
+    PDFPage *page = [userInfo objectForKey:SKPDFDocumentPageKey];
+    NSUndoManager *undoManager = [self interactionMode] == SKPresentationMode 
? [self presentationUndoManager] : [[self document] undoManager];
+
+    [[undoManager prepareWithInvocationTarget:[notification object]] 
addAnnotation:annotation toPage:page];
+    
+    if ([self interactionMode] == SKPresentationMode) {
+        [presentationNotes removeObject:annotation];
+        if (page)
+            [self updateThumbnailAtPageIndex:[page pageIndex]];
+    } else {
+        if ([annotation isSkimNote] && mwcFlags.addOrRemoveNotesInBulk == 0) {
+            if ([[self selectedNotes] containsObject:annotation])
+                [rightSideController.noteOutlineView deselectAll:self];
+            
+            [[self windowControllerForNote:annotation] close];
+            
+            mwcFlags.updatingNoteSelection = 1;
+            [[self mutableArrayValueForKey:NOTES_KEY] removeObject:annotation];
+            [rightSideController.noteArrayController rearrangeObjects]; // 
doesn't seem to be done automatically
+            mwcFlags.updatingNoteSelection = 0;
+            [rightSideController.noteOutlineView reloadData];
+        }
+        if (page) {
+            [self updateThumbnailAtPageIndex:[page pageIndex]];
+            for (SKSnapshotWindowController *wc in snapshots) {
+                if ([wc isPageVisible:page])
+                    [self snapshotNeedsUpdate:wc];
+            }
+            [secondaryPdfView setNeedsDisplayForAnnotation:annotation 
onPage:page];
+        }
+    }
+}
+
+- (void)handleDidMoveAnnotationNotification:(NSNotification *)notification {
+    NSDictionary *userInfo = [notification userInfo];
+    PDFAnnotation *annotation = [userInfo 
objectForKey:SKPDFDocumentAnnotationKey];
+    PDFPage *oldPage = [userInfo objectForKey:SKPDFDocumentOldPageKey];
+    PDFPage *newPage = [userInfo objectForKey:SKPDFDocumentPageKey];
+    NSUndoManager *undoManager = [[self document] undoManager];
+
+    [[undoManager prepareWithInvocationTarget:[notification object]] 
moveAnnotation:annotation toPage:oldPage];
+    
+    if (oldPage || newPage) {
+        if (oldPage)
+            [self updateThumbnailAtPageIndex:[oldPage pageIndex]];
+        if (newPage)
+            [self updateThumbnailAtPageIndex:[newPage pageIndex]];
+        for (SKSnapshotWindowController *wc in snapshots) {
+            if ([wc isPageVisible:oldPage] || [wc isPageVisible:newPage])
+                [self snapshotNeedsUpdate:wc];
+        }
+        [secondaryPdfView requiresDisplay];
+    }
+    
+    [rightSideController.noteArrayController rearrangeObjects];
+    [rightSideController.noteOutlineView reloadData];
+}
+
 - (void)registerForDocumentNotifications {
     NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
     PDFDocument *pdfDoc = [pdfView document];
@@ -2330,6 +2432,12 @@
                              name:PDFDocumentDidEndPageWriteNotification 
object:pdfDoc];
     [nc addObserver:self 
selector:@selector(handlePageBoundsDidChangeNotification:) 
                              name:SKPDFPageBoundsDidChangeNotification 
object:pdfDoc];
+    [nc addObserver:self 
selector:@selector(handleDidAddAnnotationNotification:)
+                             name:SKPDFDocumentDidAddAnnotationNotification 
object:pdfDoc];
+    [nc addObserver:self 
selector:@selector(handleDidRemoveAnnotationNotification:)
+                             name:SKPDFDocumentDidRemoveAnnotationNotification 
object:pdfDoc];
+    [nc addObserver:self 
selector:@selector(handleDidMoveAnnotationNotification:)
+                             name:SKPDFDocumentDidMoveAnnotationNotification 
object:pdfDoc];
 }
 
 - (void)unregisterForDocumentNotifications {
@@ -2339,6 +2447,9 @@
     [nc removeObserver:self name:PDFDocumentDidEndWriteNotification 
object:pdfDoc];
     [nc removeObserver:self name:PDFDocumentDidEndPageWriteNotification 
object:pdfDoc];
     [nc removeObserver:self name:SKPDFPageBoundsDidChangeNotification 
object:pdfDoc];
+    [nc removeObserver:self name:SKPDFDocumentDidAddAnnotationNotification 
object:pdfDoc];
+    [nc removeObserver:self name:SKPDFDocumentDidRemoveAnnotationNotification 
object:pdfDoc];
+    [nc removeObserver:self name:SKPDFDocumentDidMoveAnnotationNotification 
object:pdfDoc];
 }
 
 #pragma mark Subwindows

Modified: trunk/SKMainWindowController_FullScreen.m
===================================================================
--- trunk/SKMainWindowController_FullScreen.m   2023-08-31 09:35:13 UTC (rev 
13621)
+++ trunk/SKMainWindowController_FullScreen.m   2023-08-31 16:30:10 UTC (rev 
13622)
@@ -480,6 +480,14 @@
     if ([self leftSidePaneIsOpen])
         [self hideSideWindow];
     
+    if ([presentationNotes count]) {
+        PDFDocument *pdfDoc = [self pdfDocument];
+        for (PDFAnnotation *annotation in presentationNotes)
+            [pdfDoc removeAnnotation:annotation];
+    }
+    SKDESTROY(presentationNotes);
+    SKDESTROY(presentationUndoManager);
+    
     // do this first, otherwise the navigation window may be covered by 
fadeWindow and then reveiled again, which looks odd
     [pdfView setInteractionMode:SKNormalMode];
     

Modified: trunk/SKMainWindowController_UI.m
===================================================================
--- trunk/SKMainWindowController_UI.m   2023-08-31 09:35:13 UTC (rev 13621)
+++ trunk/SKMainWindowController_UI.m   2023-08-31 16:30:10 UTC (rev 13622)
@@ -316,7 +316,7 @@
 
 - (NSUndoManager *)windowWillReturnUndoManager:(NSWindow *)sender {
     if ([self interactionMode] == SKPresentationMode)
-        return [pdfView temporaryUndoManager];
+        return [self presentationUndoManager];
     return [[self document] undoManager];
 }
 
@@ -896,7 +896,7 @@
 - (void)outlineView:(NSOutlineView *)ov deleteItems:(NSArray *)items  {
     if ([ov isEqual:rightSideController.noteOutlineView] && [items count]) {
         for (PDFAnnotation *item in [self noteItems:items])
-            [pdfView removeAnnotation:item];
+            [[self pdfDocument] removeAnnotation:item];
         [[[self document] undoManager] 
setActionName:NSLocalizedString(@"Remove Note", @"Undo action name")];
     }
 }
@@ -1517,12 +1517,6 @@
     [self toggleLeftSidePane:sender];
 }
 
-- (NSUndoManager *)undoManagerForPDFView:(PDFView *)sender {
-    if ([self interactionMode] == SKPresentationMode)
-        return [pdfView temporaryUndoManager];
-    return [[self document] undoManager];
-}
-
 - (void)PDFView:(PDFView *)sender rotatePageAtIndex:(NSUInteger)idx 
by:(NSInteger)rotation {
     [self rotatePageAtIndex:idx by:rotation];
 }
@@ -2023,81 +2017,6 @@
         [self updateRightStatus];
 }
 
-- (void)handleDidAddAnnotationNotification:(NSNotification *)notification {
-    PDFAnnotation *annotation = [[notification userInfo] 
objectForKey:SKPDFViewAnnotationKey];
-    PDFPage *page = [[notification userInfo] objectForKey:SKPDFViewPageKey];
-    
-    if ([[[notification userInfo] objectForKey:SKPDFViewTemporaryKey] 
boolValue] == NO) {
-        if ([annotation isSkimNote] && mwcFlags.addOrRemoveNotesInBulk == 0) {
-            mwcFlags.updatingNoteSelection = 1;
-            [[self mutableArrayValueForKey:NOTES_KEY] addObject:annotation];
-            [rightSideController.noteArrayController rearrangeObjects]; // 
doesn't seem to be done automatically
-            mwcFlags.updatingNoteSelection = 0;
-            [rightSideController.noteOutlineView reloadData];
-        }
-        if (page) {
-            [self updateThumbnailAtPageIndex:[page pageIndex]];
-            for (SKSnapshotWindowController *wc in snapshots) {
-                if ([wc isPageVisible:page])
-                    [self snapshotNeedsUpdate:wc];
-            }
-            [secondaryPdfView setNeedsDisplayForAnnotation:annotation 
onPage:page];
-        }
-    } else if (page) {
-        [self updateThumbnailAtPageIndex:[page pageIndex]];
-    }
-}
-
-- (void)handleDidRemoveAnnotationNotification:(NSNotification *)notification {
-    PDFAnnotation *annotation = [[notification userInfo] 
objectForKey:SKPDFViewAnnotationKey];
-    PDFPage *page = [[notification userInfo] objectForKey:SKPDFViewPageKey];
-    
-    if ([[[notification userInfo] objectForKey:SKPDFViewTemporaryKey] 
boolValue] == NO) {
-        if ([annotation isSkimNote] && mwcFlags.addOrRemoveNotesInBulk == 0) {
-            if ([[self selectedNotes] containsObject:annotation])
-                [rightSideController.noteOutlineView deselectAll:self];
-            
-            [[self windowControllerForNote:annotation] close];
-            
-            mwcFlags.updatingNoteSelection = 1;
-            [[self mutableArrayValueForKey:NOTES_KEY] removeObject:annotation];
-            [rightSideController.noteArrayController rearrangeObjects]; // 
doesn't seem to be done automatically
-            mwcFlags.updatingNoteSelection = 0;
-            [rightSideController.noteOutlineView reloadData];
-        }
-        if (page) {
-            [self updateThumbnailAtPageIndex:[page pageIndex]];
-            for (SKSnapshotWindowController *wc in snapshots) {
-                if ([wc isPageVisible:page])
-                    [self snapshotNeedsUpdate:wc];
-            }
-            [secondaryPdfView setNeedsDisplayForAnnotation:annotation 
onPage:page];
-        }
-    } else if (page) {
-        [self updateThumbnailAtPageIndex:[page pageIndex]];
-    }
-}
-
-- (void)handleDidMoveAnnotationNotification:(NSNotification *)notification {
-    PDFPage *oldPage = [[notification userInfo] 
objectForKey:SKPDFViewOldPageKey];
-    PDFPage *newPage = [[notification userInfo] 
objectForKey:SKPDFViewNewPageKey];
-    
-    if (oldPage || newPage) {
-        if (oldPage)
-            [self updateThumbnailAtPageIndex:[oldPage pageIndex]];
-        if (newPage)
-            [self updateThumbnailAtPageIndex:[newPage pageIndex]];
-        for (SKSnapshotWindowController *wc in snapshots) {
-            if ([wc isPageVisible:oldPage] || [wc isPageVisible:newPage])
-                [self snapshotNeedsUpdate:wc];
-        }
-        [secondaryPdfView requiresDisplay];
-    }
-    
-    [rightSideController.noteArrayController rearrangeObjects];
-    [rightSideController.noteOutlineView reloadData];
-}
-
 - (void)handleReadingBarDidChangeNotification:(NSNotification *)notification {
     NSDictionary *userInfo = [notification userInfo];
     PDFPage *oldPage = [userInfo objectForKey:SKPDFViewOldPageKey];
@@ -2159,12 +2078,6 @@
                              name:PDFViewDisplayBoxChangedNotification 
object:pdfView];
     [nc addObserver:self 
selector:@selector(handleCurrentAnnotationChangedNotification:)
                              
name:SKPDFViewCurrentAnnotationChangedNotification object:pdfView];
-    [nc addObserver:self 
selector:@selector(handleDidAddAnnotationNotification:) 
-                             name:SKPDFViewDidAddAnnotationNotification 
object:pdfView];
-    [nc addObserver:self 
selector:@selector(handleDidRemoveAnnotationNotification:) 
-                             name:SKPDFViewDidRemoveAnnotationNotification 
object:pdfView];
-    [nc addObserver:self 
selector:@selector(handleDidMoveAnnotationNotification:) 
-                             name:SKPDFViewDidMoveAnnotationNotification 
object:pdfView];
     [nc addObserver:self 
selector:@selector(handleReadingBarDidChangeNotification:) 
                              name:SKPDFViewReadingBarDidChangeNotification 
object:pdfView];
     // View

Modified: trunk/SKPDFView.h
===================================================================
--- trunk/SKPDFView.h   2023-08-31 09:35:13 UTC (rev 13621)
+++ trunk/SKPDFView.h   2023-08-31 16:30:10 UTC (rev 13622)
@@ -52,9 +52,6 @@
 extern NSString *SKPDFViewAnnotationModeChangedNotification;
 extern NSString *SKPDFViewTemporaryToolModeChangedNotification;
 extern NSString *SKPDFViewCurrentAnnotationChangedNotification;
-extern NSString *SKPDFViewDidAddAnnotationNotification;
-extern NSString *SKPDFViewDidRemoveAnnotationNotification;
-extern NSString *SKPDFViewDidMoveAnnotationNotification;
 extern NSString *SKPDFViewReadingBarDidChangeNotification;
 extern NSString *SKPDFViewSelectionChangedNotification;
 extern NSString *SKPDFViewMagnificationChangedNotification;
@@ -61,10 +58,8 @@
 extern NSString *SKPDFViewPacerStartedOrStoppedNotification;
 
 extern NSString *SKPDFViewAnnotationKey;
-extern NSString *SKPDFViewPageKey;
 extern NSString *SKPDFViewOldPageKey;
 extern NSString *SKPDFViewNewPageKey;
-extern NSString *SKPDFViewTemporaryKey;
 
 typedef NS_ENUM(NSInteger, SKToolMode) {
     SKTextToolMode,
@@ -143,9 +138,6 @@
        PDFAnnotation *currentAnnotation;
        PDFAnnotation *highlightAnnotation;
     
-    NSMutableArray *temporaryAnnotations;
-    NSUndoManager *temporaryUndoManager;
-    
     SKTextNoteEditor *editor;
     
     NSRect selectionRect;
@@ -242,10 +234,8 @@
 
 - (void)addAnnotationForContext:(id)sender;
 - (void)addAnnotationWithType:(SKNoteType)annotationType;
-- (void)addAnnotation:(PDFAnnotation *)annotation toPage:(PDFPage *)page;
 - (void)removeCurrentAnnotation:(id)sender;
 - (void)removeThisAnnotation:(id)sender;
-- (void)removeAnnotation:(PDFAnnotation *)annotation;
 
 - (void)editCurrentAnnotation:(id)sender;
 - (void)editThisAnnotation:(id)sender;
@@ -290,5 +280,4 @@
 - (void)PDFViewPerformHideFind:(PDFView *)sender;
 - (BOOL)PDFViewIsFindVisible:(PDFView *)sender;
 - (void)PDFView:(PDFView *)sender rotatePageAtIndex:(NSUInteger)idx 
by:(NSInteger)rotation;
-- (NSUndoManager *)undoManagerForPDFView:(PDFView *)sender;
 @end

Modified: trunk/SKPDFView.m
===================================================================
--- trunk/SKPDFView.m   2023-08-31 09:35:13 UTC (rev 13621)
+++ trunk/SKPDFView.m   2023-08-31 16:30:10 UTC (rev 13622)
@@ -119,9 +119,6 @@
 NSString *SKPDFViewTemporaryToolModeChangedNotification = 
@"SKPDFViewTemporaryToolModeChangedNotification";
 NSString *SKPDFViewAnnotationModeChangedNotification = 
@"SKPDFViewAnnotationModeChangedNotification";
 NSString *SKPDFViewCurrentAnnotationChangedNotification = 
@"SKPDFViewCurrentAnnotationChangedNotification";
-NSString *SKPDFViewDidAddAnnotationNotification = 
@"SKPDFViewDidAddAnnotationNotification";
-NSString *SKPDFViewDidRemoveAnnotationNotification = 
@"SKPDFViewDidRemoveAnnotationNotification";
-NSString *SKPDFViewDidMoveAnnotationNotification = 
@"SKPDFViewDidMoveAnnotationNotification";
 NSString *SKPDFViewReadingBarDidChangeNotification = 
@"SKPDFViewReadingBarDidChangeNotification";
 NSString *SKPDFViewSelectionChangedNotification = 
@"SKPDFViewSelectionChangedNotification";
 NSString *SKPDFViewMagnificationChangedNotification = 
@"SKPDFViewMagnificationChangedNotification";
@@ -128,10 +125,8 @@
 NSString *SKPDFViewPacerStartedOrStoppedNotification = 
@"SKPDFViewPacerStartedOrStoppedNotification";
 
 NSString *SKPDFViewAnnotationKey = @"annotation";
-NSString *SKPDFViewPageKey = @"page";
 NSString *SKPDFViewOldPageKey = @"oldPage";
 NSString *SKPDFViewNewPageKey = @"newPage";
-NSString *SKPDFViewTemporaryKey = @"temporary";
 
 #define SKMoveReadingBarModifiersKey @"SKMoveReadingBarModifiers"
 #define SKResizeReadingBarModifiersKey @"SKResizeReadingBarModifiers"
@@ -265,6 +260,8 @@
 
 - (void)handlePageChangedNotification:(NSNotification *)notification;
 - (void)handleScaleChangedNotification:(NSNotification *)notification;
+- (void)registerForDocumentNotifications;
+- (void)unregisterForDocumentNotifications;
 
 @end
 
@@ -273,7 +270,7 @@
 @implementation SKPDFView
 
 @synthesize toolMode, annotationMode, temporaryToolMode, interactionMode, 
currentAnnotation, readingBar, pacerSpeed, transitionController, 
typeSelectHelper, syncDot, zooming;
-@dynamic extendedDisplayMode, displaysHorizontally, displaysRightToLeft, 
hideNotes, hasReadingBar, hasPacer, currentSelectionPage, currentSelectionRect, 
currentMagnification, needsRewind, editing, temporaryUndoManager;
+@dynamic extendedDisplayMode, displaysHorizontally, displaysRightToLeft, 
hideNotes, hasReadingBar, hasPacer, currentSelectionPage, currentSelectionRect, 
currentMagnification, needsRewind, editing;
 
 + (void)initialize {
     SKINITIALIZE;
@@ -379,8 +376,6 @@
     // we should have been cleaned up in setDelegate:nil which is called from 
windowWillClose:
     SKDESTROY(syncDot);
     SKDESTROY(currentAnnotation);
-    SKDESTROY(temporaryAnnotations);
-    SKDESTROY(temporaryUndoManager);
     SKDESTROY(typeSelectHelper);
     SKDESTROY(transitionController);
     SKDESTROY(navWindow);
@@ -639,8 +634,14 @@
         [self setReadingBar:nil];
     }
     
+    if ([self document])
+        [self unregisterForDocumentNotifications];
+    
     [super setDocument:document];
     
+    if (document)
+        [self registerForDocumentNotifications];
+    
     [self resetPDFToolTipRects];
     
     if (readingBarPageIndex != NSNotFound) {
@@ -661,19 +662,6 @@
     [loupeController updateContents];
 }
 
-- (NSUndoManager *)undoManager {
-    if ([[self delegate] respondsToSelector:@selector(undoManagerForPDFView:)])
-        return [[self delegate] undoManagerForPDFView:self];
-    else
-        return [super undoManager];
-}
-
-- (NSUndoManager *)temporaryUndoManager {
-    if (temporaryUndoManager == nil)
-        temporaryUndoManager = [[NSUndoManager alloc] init];
-    return temporaryUndoManager;
-}
-
 - (void)setBackgroundColor:(NSColor *)newBackgroundColor {
     [super setBackgroundColor:newBackgroundColor];
     [loupeController updateBackgroundColor];
@@ -740,12 +728,6 @@
             [NSCursor setHiddenUntilMouseMoves:NO];
             if ([[self documentView] isHidden])
                 [[self documentView] setHidden:NO];
-            if (temporaryAnnotations) {
-                for (PDFAnnotation *annotation in temporaryAnnotations)
-                    [self removeTemporaryAnnotation:annotation];
-                SKDESTROY(temporaryAnnotations);
-                SKDESTROY(temporaryUndoManager);
-            }
         }
         interactionMode = newInteractionMode;
         if (interactionMode == SKPresentationMode) {
@@ -1400,7 +1382,7 @@
             
             [newAnnotation registerUserName];
             [self beginNewUndoGroupIfNeededWithCommit:YES];
-            [self addAnnotation:newAnnotation toPage:page];
+            [[self document] addAnnotation:newAnnotation toPage:page];
             
             [self setCurrentAnnotation:newAnnotation];
 
@@ -1473,7 +1455,7 @@
             
             [newAnnotation registerUserName];
             [self beginNewUndoGroupIfNeededWithCommit:YES];
-            [self addAnnotation:newAnnotation toPage:page];
+            [[self document] addAnnotation:newAnnotation toPage:page];
             [[self undoManager] setActionName:NSLocalizedString(@"Add Note", 
@"Undo action name")];
 
             [self setCurrentAnnotation:newAnnotation];
@@ -2661,7 +2643,7 @@
             if ([text length] > 0 || [newAnnotation string] == nil)
                 [newAnnotation setString:text ?: @""];
             [newAnnotation registerUserName];
-            [self addAnnotation:newAnnotation toPage:page];
+            [[self document] addAnnotation:newAnnotation toPage:page];
             if ([text length] == 0 && isInitial == NO)
                 [newAnnotation autoUpdateString];
         }
@@ -2676,7 +2658,7 @@
         if (annotationType != SKLineNote && annotationType != SKInkNote && 
[text length] > 0)
             [newAnnotation setString:text];
         [newAnnotation registerUserName];
-        [self addAnnotation:newAnnotation toPage:page];
+        [[self document] addAnnotation:newAnnotation toPage:page];
         if ([text length] == 0 && isInitial == NO)
             [newAnnotation autoUpdateString];
         if ([newAnnotation string] == nil)
@@ -2867,20 +2849,9 @@
     [self addAnnotationWithType:[sender tag] context:[sender 
representedObject]];
 }
 
-- (void)addAnnotation:(PDFAnnotation *)annotation toPage:(PDFPage *)page {
-    [[[self undoManager] prepareWithInvocationTarget:self] 
removeAnnotation:annotation];
-    [annotation setShouldDisplay:pdfvFlags.hideNotes == NO || [annotation 
isSkimNote] == NO];
-    [annotation setShouldPrint:pdfvFlags.hideNotes == NO || [annotation 
isSkimNote] == NO];
-    [page addAnnotation:annotation];
-    [self setNeedsDisplayForAnnotation:annotation];
-    [self annotationsChangedOnPage:page];
-    [self resetPDFToolTipRects];
-    [[NSNotificationCenter defaultCenter] 
postNotificationName:SKPDFViewDidAddAnnotationNotification object:self 
userInfo:@{SKPDFViewPageKey:page, SKPDFViewAnnotationKey:annotation}];
-}
-
 - (void)removeCurrentAnnotation:(id)sender{
     if ([currentAnnotation isSkimNote]) {
-        [self removeAnnotation:currentAnnotation];
+        [[self document] removeAnnotation:currentAnnotation];
         [[self undoManager] setActionName:NSLocalizedString(@"Remove Note", 
@"Undo action name")];
     }
 }
@@ -2889,79 +2860,9 @@
     PDFAnnotation *annotation = [sender representedObject];
     
     if (annotation)
-        [self removeAnnotation:annotation];
+        [[self document] removeAnnotation:annotation];
 }
 
-- (void)removeAnnotation:(PDFAnnotation *)annotation {
-    if (currentAnnotation == annotation) {
-        [self setCurrentAnnotation:nil];
-        [self beginNewUndoGroupIfNeededWithCommit:NO];
-    }
-    
-    PDFAnnotation *wasAnnotation = [annotation retain];
-    PDFPage *page = [[wasAnnotation page] retain];
-    
-    [[[self undoManager] prepareWithInvocationTarget:self] 
addAnnotation:wasAnnotation toPage:page];
-    [self setNeedsDisplayForAnnotation:wasAnnotation];
-    [page removeAnnotation:wasAnnotation];
-    [self annotationsChangedOnPage:page];
-    if ([wasAnnotation isNote]) {
-        if (RUNNING(10_12) && [[page annotations] 
containsObject:wasAnnotation])
-            [page removeAnnotation:wasAnnotation];
-        [self resetPDFToolTipRects];
-    }
-    [[NSNotificationCenter defaultCenter] 
postNotificationName:SKPDFViewDidRemoveAnnotationNotification object:self
-                                                      
userInfo:@{SKPDFViewAnnotationKey:wasAnnotation, SKPDFViewPageKey:page}];
-    [wasAnnotation release];
-    [page release];
-}
-
-- (void)moveAnnotation:(PDFAnnotation *)annotation toPage:(PDFPage *)page {
-    PDFPage *oldPage = [[annotation page] retain];
-    [[[self undoManager] prepareWithInvocationTarget:self] 
moveAnnotation:annotation toPage:oldPage];
-    [[self undoManager] setActionName:NSLocalizedString(@"Edit Note", @"Undo 
action name")];
-    [self setNeedsDisplayForAnnotation:annotation];
-    [annotation retain];
-    [oldPage removeAnnotation:annotation];
-    [page addAnnotation:annotation];
-    [annotation release];
-    [self setNeedsDisplayForAnnotation:annotation];
-    [self annotationsChangedOnPage:oldPage];
-    [self annotationsChangedOnPage:page];
-    if ([annotation isNote])
-        [self resetPDFToolTipRects];
-    if ([self isEditingAnnotation:annotation])
-        [editor layoutWithEvent:nil];
-    [[NSNotificationCenter defaultCenter] 
postNotificationName:SKPDFViewDidMoveAnnotationNotification object:self 
userInfo:@{SKPDFViewOldPageKey:oldPage, SKPDFViewNewPageKey:page, 
SKPDFViewAnnotationKey:annotation}];
-    [oldPage release];
-}
-
-- (void)addTemporaryAnnotation:(PDFAnnotation *)annotation toPage:(PDFPage 
*)page {
-    [[[self temporaryUndoManager] prepareWithInvocationTarget:self] 
removeTemporaryAnnotation:annotation];
-    if (temporaryAnnotations == nil)
-        temporaryAnnotations = [[NSMutableArray alloc] init];
-    [annotation setShouldPrint:NO];
-    [temporaryAnnotations addObject:annotation];
-    [page addAnnotation:annotation];
-    [self setNeedsDisplayForAnnotation:annotation];
-    [self annotationsChangedOnPage:page];
-    [[NSNotificationCenter defaultCenter] 
postNotificationName:SKPDFViewDidAddAnnotationNotification object:self 
userInfo:@{SKPDFViewAnnotationKey:annotation, SKPDFViewPageKey:page, 
SKPDFViewTemporaryKey:@YES}];
-}
-
-- (void)removeTemporaryAnnotation:(PDFAnnotation *)annotation {
-    PDFAnnotation *wasAnnotation = [annotation retain];
-    PDFPage *page = [[wasAnnotation page] retain];
-    
-    [[[self temporaryUndoManager] prepareWithInvocationTarget:self] 
addTemporaryAnnotation:wasAnnotation toPage:page];
-    [self setNeedsDisplayForAnnotation:wasAnnotation];
-    [temporaryAnnotations removeObject:annotation];
-    [page removeAnnotation:wasAnnotation];
-    [self annotationsChangedOnPage:page];
-    [wasAnnotation release];
-    [[NSNotificationCenter defaultCenter] 
postNotificationName:SKPDFViewDidRemoveAnnotationNotification object:self 
userInfo:@{SKPDFViewAnnotationKey:wasAnnotation, SKPDFViewPageKey:page, 
SKPDFViewTemporaryKey:@YES}];
-    [page release];
-}
-
 - (void)editThisAnnotation:(id)sender {
     [self editAnnotation:[sender representedObject]];
 }
@@ -3337,6 +3238,86 @@
 
 #pragma mark Notification handling
 
+- (void)handleDidAddAnnotationNotification:(NSNotification *)notification {
+    NSDictionary *userInfo = [notification userInfo];
+    PDFAnnotation *annotation = [userInfo 
objectForKey:SKPDFDocumentAnnotationKey];
+    PDFPage *page = [userInfo objectForKey:SKPDFDocumentPageKey];
+    
+    [annotation setShouldDisplay:pdfvFlags.hideNotes == NO || [annotation 
isSkimNote] == NO || interactionMode == SKPresentationMode];
+    [annotation setShouldPrint:(pdfvFlags.hideNotes == NO || [annotation 
isSkimNote] == NO) && interactionMode != SKPresentationMode];
+    
+    [self setNeedsDisplayForAnnotation:annotation];
+    [self annotationsChangedOnPage:page];
+    [self resetPDFToolTipRects];
+}
+
+- (void)handleWillRemoveAnnotationNotification:(NSNotification *)notification {
+    PDFAnnotation *annotation = [[notification userInfo] 
objectForKey:SKPDFDocumentAnnotationKey];
+    
+    if (currentAnnotation == annotation) {
+        [self setCurrentAnnotation:nil];
+        [self beginNewUndoGroupIfNeededWithCommit:NO];
+    }
+    
+    [self setNeedsDisplayForAnnotation:annotation];
+}
+
+- (void)handleDidRemoveAnnotationNotification:(NSNotification *)notification {
+    NSDictionary *userInfo = [notification userInfo];
+    PDFAnnotation *annotation = [userInfo 
objectForKey:SKPDFDocumentAnnotationKey];
+    PDFPage *page = [userInfo objectForKey:SKPDFDocumentPageKey];
+    
+    [self annotationsChangedOnPage:page];
+    if ([annotation isNote])
+        [self resetPDFToolTipRects];
+}
+
+- (void)handleWillMoveAnnotationNotification:(NSNotification *)notification {
+    PDFAnnotation *annotation = [[notification userInfo] 
objectForKey:SKPDFDocumentAnnotationKey];
+    
+    [self setNeedsDisplayForAnnotation:annotation];
+}
+
+- (void)handleDidMoveAnnotationNotification:(NSNotification *)notification {
+    NSDictionary *userInfo = [notification userInfo];
+    PDFAnnotation *annotation = [userInfo 
objectForKey:SKPDFDocumentAnnotationKey];
+    PDFPage *page = [userInfo objectForKey:SKPDFDocumentPageKey];
+    PDFPage *oldPage = [userInfo objectForKey:SKPDFDocumentOldPageKey];
+    
+    [self setNeedsDisplayForAnnotation:annotation];
+    [self annotationsChangedOnPage:oldPage];
+    [self annotationsChangedOnPage:page];
+    if ([annotation isNote])
+        [self resetPDFToolTipRects];
+    if ([self isEditingAnnotation:annotation])
+        [editor layoutWithEvent:nil];
+}
+
+- (void)registerForDocumentNotifications {
+    NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
+    PDFDocument *pdfDoc = [self document];
+    [nc addObserver:self 
selector:@selector(handleDidAddAnnotationNotification:)
+                             name:SKPDFDocumentDidAddAnnotationNotification 
object:pdfDoc];
+    [nc addObserver:self 
selector:@selector(handleWillRemoveAnnotationNotification:)
+                             
name:SKPDFDocumentWillRemoveAnnotationNotification object:pdfDoc];
+    [nc addObserver:self 
selector:@selector(handleDidRemoveAnnotationNotification:)
+                             name:SKPDFDocumentDidRemoveAnnotationNotification 
object:pdfDoc];
+    [nc addObserver:self 
selector:@selector(handleWillMoveAnnotationNotification:)
+                             name:SKPDFDocumentWillMoveAnnotationNotification 
object:pdfDoc];
+    [nc addObserver:self 
selector:@selector(handleDidMoveAnnotationNotification:)
+                             name:SKPDFDocumentDidMoveAnnotationNotification 
object:pdfDoc];
+}
+
+- (void)unregisterForDocumentNotifications {
+    NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
+    PDFDocument *pdfDoc = [self document];
+    [nc removeObserver:self name:SKPDFDocumentDidAddAnnotationNotification 
object:pdfDoc];
+    [nc removeObserver:self name:SKPDFDocumentWillRemoveAnnotationNotification 
object:pdfDoc];
+    [nc removeObserver:self name:SKPDFDocumentDidRemoveAnnotationNotification 
object:pdfDoc];
+    [nc removeObserver:self name:SKPDFDocumentWillMoveAnnotationNotification 
object:pdfDoc];
+    [nc removeObserver:self name:SKPDFDocumentDidMoveAnnotationNotification 
object:pdfDoc];
+}
+
 - (void)handlePageChangedNotification:(NSNotification *)notification {
     if ([self displayMode] == kPDFDisplaySinglePage || [self displayMode] == 
kPDFDisplayTwoUp) {
         [editor layoutWithEvent:nil];
@@ -4076,7 +4057,8 @@
     if (newActivePage) { // newActivePage should never be nil, but just to be 
sure
         if (newActivePage != [currentAnnotation page]) {
             // move the annotation to the new page
-            [self moveAnnotation:currentAnnotation toPage:newActivePage];
+            [[self document] moveAnnotation:currentAnnotation 
toPage:newActivePage];
+            [[self undoManager] setActionName:NSLocalizedString(@"Edit Note", 
@"Undo action name")];
         }
         
         NSRect newBounds = [currentAnnotation bounds];
@@ -4459,7 +4441,7 @@
             PDFAnnotation *newAnnotation = [PDFAnnotation 
newSkimNoteWithProperties:[newCurrentAnnotation SkimNoteProperties]];
             [newAnnotation registerUserName];
             [self beginNewUndoGroupIfNeededWithCommit:YES];
-            [self addAnnotation:newAnnotation toPage:page];
+            [[self document] addAnnotation:newAnnotation toPage:page];
             [[self undoManager] setActionName:NSLocalizedString(@"Add Note", 
@"Undo action name")];
             newCurrentAnnotation = newAnnotation;
             [newAnnotation release];
@@ -4493,9 +4475,9 @@
                 [self beginNewUndoGroupIfNeededWithCommit:YES];
                 [newAnnotation setColor:[currentAnnotation color]];
                 [newAnnotation registerUserName];
-                [self removeAnnotation:newCurrentAnnotation];
+                [[self document] removeAnnotation:newCurrentAnnotation];
                 [self removeCurrentAnnotation:nil];
-                [self addAnnotation:newAnnotation toPage:page];
+                [[self document] addAnnotation:newAnnotation toPage:page];
                 [[self undoManager] setActionName:NSLocalizedString(@"Join 
Notes", @"Undo action name")];
                 newCurrentAnnotation = newAnnotation;
             }
@@ -4626,13 +4608,11 @@
         if (interactionMode != SKPresentationMode) {
             [annotation registerUserName];
             [self beginNewUndoGroupIfNeededWithCommit:NO];
-            [self addAnnotation:annotation toPage:page];
-            [[self undoManager] setActionName:NSLocalizedString(@"Add Note", 
@"Undo action name")];
-        } else {
-            if (tmpColor)
-                [annotation setColor:tmpColor];
-            [self addTemporaryAnnotation:annotation toPage:page];
+        } else if (tmpColor) {
+            [annotation setColor:tmpColor];
         }
+        [[self document] addAnnotation:annotation toPage:page];
+        [[self undoManager] setActionName:NSLocalizedString(@"Add Note", 
@"Undo action name")];
         
         [paths release];
         [annotation release];
@@ -4661,7 +4641,7 @@
         
         for (PDFAnnotation *annotation in annotations) {
             if ([annotation isSkimNote] && [annotation hitTest:point] && [self 
isEditingAnnotation:annotation] == NO) {
-                [self removeAnnotation:annotation];
+                [[self document] removeAnnotation:annotation];
                 [[self undoManager] setActionName:NSLocalizedString(@"Remove 
Note", @"Undo action name")];
                 break;
             }

Modified: trunk/SKSnapshotWindowController.m
===================================================================
--- trunk/SKSnapshotWindowController.m  2023-08-31 09:35:13 UTC (rev 13621)
+++ trunk/SKSnapshotWindowController.m  2023-08-31 16:30:10 UTC (rev 13622)
@@ -42,7 +42,6 @@
 #import <Quartz/Quartz.h>
 #import "SKSnapshotPDFView.h"
 #import <SkimNotes/SkimNotes.h>
-#import "SKPDFView.h"
 #import "SKSnapshotWindow.h"
 #import "NSWindowController_SKExtensions.h"
 #import "SKStringConstants.h"
@@ -63,6 +62,7 @@
 #import "NSView_SKExtensions.h"
 #import "NSScreen_SKExtensions.h"
 #import "SKApplication.h"
+#import "PDFDocument_SKExtensions.h"
 
 #define EM_DASH_CHARACTER (unichar)0x2014
 
@@ -208,22 +208,20 @@
 }
 
 - (void)handleDidAddRemoveAnnotationNotification:(NSNotification 
*)notification {
-    PDFAnnotation *annotation = [[notification userInfo] 
objectForKey:SKPDFViewAnnotationKey];
-    PDFPage *page = [[notification userInfo] objectForKey:SKPDFViewPageKey];
-    if ([[page document] isEqual:[pdfView document]] && [self 
isPageVisible:page])
+    PDFAnnotation *annotation = [[notification userInfo] 
objectForKey:SKPDFDocumentAnnotationKey];
+    PDFPage *page = [[notification userInfo] 
objectForKey:SKPDFDocumentPageKey];
+    if ([self isPageVisible:page])
         [self setNeedsDisplayForAnnotation:annotation onPage:page];
 }
 
 - (void)handleDidMoveAnnotationNotification:(NSNotification *)notification {
     PDFAnnotation *annotation = [notification object];
-    PDFPage *oldPage = [[notification userInfo] 
objectForKey:SKPDFViewOldPageKey];
-    PDFPage *newPage = [[notification userInfo] 
objectForKey:SKPDFViewNewPageKey];
-    if ([[newPage document] isEqual:[pdfView document]]) {
-        if ([self isPageVisible:oldPage])
-            [self setNeedsDisplayForAnnotation:annotation onPage:oldPage];
-        if ([self isPageVisible:newPage])
-            [self setNeedsDisplayForAnnotation:annotation onPage:newPage];
-    }
+    PDFPage *oldPage = [[notification userInfo] 
objectForKey:SKPDFDocumentOldPageKey];
+    PDFPage *newPage = [[notification userInfo] 
objectForKey:SKPDFDocumentPageKey];
+    if ([self isPageVisible:oldPage])
+        [self setNeedsDisplayForAnnotation:annotation onPage:oldPage];
+    if ([self isPageVisible:newPage])
+        [self setNeedsDisplayForAnnotation:annotation onPage:newPage];
 }
 
 - (void)windowWillClose:(NSNotification *)notification {
@@ -273,12 +271,13 @@
                                                  
name:NSViewBoundsDidChangeNotification object:clipView];
     [[NSNotificationCenter defaultCenter] addObserver:self 
selector:@selector(handleViewChangedNotification:) 
                                                  
name:SKSnapshotViewChangedNotification object:self];
+    PDFDocument *pdfDoc = [pdfView document];
        [[NSNotificationCenter defaultCenter] addObserver:self 
selector:@selector(handleDidAddRemoveAnnotationNotification:) 
-                                                 
name:SKPDFViewDidAddAnnotationNotification object:nil];    
+                                                 
name:SKPDFDocumentDidAddAnnotationNotification object:pdfDoc];
        [[NSNotificationCenter defaultCenter] addObserver:self 
selector:@selector(handleDidAddRemoveAnnotationNotification:) 
-                                                 
name:SKPDFViewDidRemoveAnnotationNotification object:nil];    
+                                                 
name:SKPDFDocumentDidRemoveAnnotationNotification object:pdfDoc];
        [[NSNotificationCenter defaultCenter] addObserver:self 
selector:@selector(handleDidMoveAnnotationNotification:) 
-                                                 
name:SKPDFViewDidMoveAnnotationNotification object:nil];    
+                                                 
name:SKPDFDocumentDidMoveAnnotationNotification object:pdfDoc];
     if ([[self delegate] 
respondsToSelector:@selector(snapshotController:didFinishSetup:)])
         DISPATCH_MAIN_AFTER_SEC(SMALL_DELAY, ^{
             [[self delegate] snapshotController:self didFinishSetup:openType];

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