Revision: 15589 http://sourceforge.net/p/skim-app/code/15589 Author: hofman Date: 2025-07-02 16:23:14 +0000 (Wed, 02 Jul 2025) Log Message: ----------- convenience method to add multiple notes
Modified Paths: -------------- trunk/SKPDFView.m Modified: trunk/SKPDFView.m =================================================================== --- trunk/SKPDFView.m 2025-07-02 15:45:37 UTC (rev 15588) +++ trunk/SKPDFView.m 2025-07-02 16:23:14 UTC (rev 15589) @@ -208,6 +208,7 @@ - (void)beginNewUndoGroupIfNeeded; - (void)addAnnotation:(PDFAnnotation *)annotation toPage:(PDFPage *)page select:(BOOL)shouldSelect; +- (void)addAnnotations:(NSArray *)annotationsAndPages; - (void)removeAnnotation:(PDFAnnotation *)annotation; - (void)stopPacer; @@ -1243,25 +1244,14 @@ } else if ([newAnnotations count] > 0) { + NSMutableArray *newAnnotationsAndPages = [NSMutableArray array]; page = [self currentPage]; - - [self commitEditing]; - [self beginNewUndoGroupIfNeeded]; - for (PDFAnnotation *newAnnotation in newAnnotations) { - [newAnnotation setBounds:SKConstrainRect([newAnnotation bounds], [page boundsForBox:[self displayBox]])]; - - [newAnnotation registerUserName]; - [[self document] addAnnotation:newAnnotation toPage:page]; - + [newAnnotationsAndPages addObject:@[newAnnotation, page]]; } + [self addAnnotations:newAnnotationsAndPages]; - [[self undoManager] setActionName:NSLocalizedString(@"Add Note", @"Undo action name")]; - - if (toolMode == SKToolModeText || toolMode == SKToolModeNote) - [self setCurrentAnnotation:[newAnnotations lastObject]]; - } else { id str = nil; @@ -2389,6 +2379,20 @@ [self setCurrentAnnotation:annotation]; } +- (void)addAnnotations:(NSArray *)annotationsAndPages { + PDFAnnotation *annotation = nil; + [self commitEditing]; + [self beginNewUndoGroupIfNeeded]; + for (NSArray *annotationAndPage in annotationsAndPages) { + annotation = [annotationAndPage firstObject]; + [annotation registerUserName]; + [[self document] addAnnotation:annotation toPage:[annotationAndPage lastObject]]; + } + [[self undoManager] setActionName:NSLocalizedString(@"Add Note", @"Undo action name")]; + if (toolMode == SKToolModeText || toolMode == SKToolModeNote) + [self setCurrentAnnotation:annotation]; +} + - (void)removeAnnotation:(PDFAnnotation *)annotation { [[self document] removeAnnotation:annotation]; [[self undoManager] setActionName:NSLocalizedString(@"Remove Note", @"Undo action name")]; @@ -2454,23 +2458,10 @@ if ([newAnnotations count] > 0) { - [self commitEditing]; - [self beginNewUndoGroupIfNeeded]; + for (NSArray *annotationAndPage in newAnnotations) + [[annotationAndPage firstObject] setString:text ?: @""]; + [self addAnnotations:newAnnotations]; - for (NSArray *annotationAndPage in newAnnotations) { - newAnnotation = [annotationAndPage firstObject]; - page = [annotationAndPage lastObject]; - if ([text length] > 0 || [newAnnotation string] == nil) - [newAnnotation setString:text ?: @""]; - [newAnnotation registerUserName]; - [[self document] addAnnotation:newAnnotation toPage:page]; - } - - [[self undoManager] setActionName:NSLocalizedString(@"Add Note", @"Undo action name")]; - - if (toolMode == SKToolModeText || toolMode == SKToolModeNote) - [self setCurrentAnnotation:newAnnotation]; - return YES; } else if (newAnnotation) { 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