Revision: 9527
http://sourceforge.net/p/skim-app/code/9527
Author: hofman
Date: 2017-12-05 22:14:46 +0000 (Tue, 05 Dec 2017)
Log Message:
-----------
Replace converted notes in bulk
Modified Paths:
--------------
trunk/SKMainDocument.m
trunk/SKMainWindowController.h
trunk/SKMainWindowController.m
Modified: trunk/SKMainDocument.m
===================================================================
--- trunk/SKMainDocument.m 2017-12-05 21:27:56 UTC (rev 9526)
+++ trunk/SKMainDocument.m 2017-12-05 22:14:46 UTC (rev 9527)
@@ -207,7 +207,7 @@
[self tryToUnlockDocument:pdfDoc];
[[self mainWindowController] setPdfDocument:pdfDoc];
- [[self mainWindowController] addAnnotationsFromDictionaries:[tmpData
noteDicts] replace:YES];
+ [[self mainWindowController] addAnnotationsFromDictionaries:[tmpData
noteDicts] removeAnnotations:[self notes] autoUpdate:NO];
if ([tmpData presentationOptions])
[[self mainWindowController] setPresentationOptions:[tmpData
presentationOptions]];
@@ -1025,7 +1025,7 @@
}
if (array) {
- [[self mainWindowController] addAnnotationsFromDictionaries:array
replace:replace];
+ [[self mainWindowController] addAnnotationsFromDictionaries:array
removeAnnotations:replace ? [self notes] : nil autoUpdate:NO];
[[self undoManager] setActionName:replace ?
NSLocalizedString(@"Replace Notes", @"Undo action name") :
NSLocalizedString(@"Add Notes", @"Undo action name")];
} else
NSBeep();
@@ -1080,7 +1080,8 @@
NSInteger i, count = [pdfDoc pageCount];
NSMapTable *offsets = nil;
NSMutableArray *annotations = nil;
-
+ NSMutableArray *noteDicts = nil;
+
for (i = 0; i < count; i++) {
PDFPage *page = [pdfDoc pageAtIndex:i];
NSPoint pageOrigin = [page boundsForBox:kPDFDisplayBoxMediaBox].origin;
@@ -1090,6 +1091,12 @@
if (annotations == nil)
annotations = [[NSMutableArray alloc] init];
[annotations addObject:annotation];
+ NSDictionary *properties = [annotation SkimNoteProperties];
+ if ([[annotation type] isEqualToString:SKNTextString])
+ properties = [SKNPDFAnnotationNote
textToNoteSkimNoteProperties:properties];
+ if (noteDicts == nil)
+ noteDicts = [[NSMutableArray alloc] init];
+ [noteDicts addObject:properties];
}
}
@@ -1129,33 +1136,16 @@
dispatch_async(dispatch_get_main_queue(), ^{
- SKPDFView *pdfView = [self pdfView];
- for (PDFAnnotation *annotation in annotations) {
- NSDictionary *properties = [annotation SkimNoteProperties];
- if ([[annotation type] isEqualToString:SKNTextString])
- properties = [SKNPDFAnnotationNote
textToNoteSkimNoteProperties:properties];
- PDFAnnotation *newAnnotation = [[PDFAnnotation alloc]
initSkimNoteWithProperties:properties];
- if (newAnnotation) {
- // this is only to make sure markup annotations
generate the lineRects, for thread safety
- [newAnnotation boundsOrder];
- PDFAnnotation *popup = [annotation popup];
- if (popup)
- [pdfView removeAnnotation:popup];
- [pdfView addAnnotation:newAnnotation
toPage:[annotation page]];
- [pdfView removeAnnotation:annotation];
- if ([[newAnnotation contents] length] == 0)
- [newAnnotation autoUpdateString];
- [newAnnotation release];
- }
- }
-
+ [[self mainWindowController]
addAnnotationsFromDictionaries:noteDicts removeAnnotations:annotations
autoUpdate:YES];
+
[self setPDFData:pdfData pageOffsets:offsets];
[[self undoManager] setActionName:NSLocalizedString(@"Convert
Notes", @"Undo action name")];
[offsets release];
+ [noteDicts release];
[annotations release];
-
+
[[self mainWindowController] dismissProgressSheet];
});
});
Modified: trunk/SKMainWindowController.h
===================================================================
--- trunk/SKMainWindowController.h 2017-12-05 21:27:56 UTC (rev 9526)
+++ trunk/SKMainWindowController.h 2017-12-05 22:14:46 UTC (rev 9527)
@@ -309,7 +309,7 @@
- (void)updateSnapshotsIfNeeded;
- (void)updateSnapshot:(NSTimer *)timer;
-- (void)addAnnotationsFromDictionaries:(NSArray *)noteDicts
replace:(BOOL)replace;
+- (void)addAnnotationsFromDictionaries:(NSArray *)noteDicts
removeAnnotations:(NSArray *)notesToRemove autoUpdate:(BOOL)autoUpdate;
- (void)applySetup:(NSDictionary *)setup;
- (NSDictionary *)currentSetup;
Modified: trunk/SKMainWindowController.m
===================================================================
--- trunk/SKMainWindowController.m 2017-12-05 21:27:56 UTC (rev 9526)
+++ trunk/SKMainWindowController.m 2017-12-05 22:14:46 UTC (rev 9527)
@@ -836,7 +836,7 @@
}
}
-- (void)addAnnotationsFromDictionaries:(NSArray *)noteDicts
replace:(BOOL)replace {
+- (void)addAnnotationsFromDictionaries:(NSArray *)noteDicts
removeAnnotations:(NSArray *)notesToRemove autoUpdate:(BOOL)autoUpdate {
PDFAnnotation *annotation;
PDFDocument *pdfDoc = [pdfView document];
NSMutableArray *notesToAdd = [NSMutableArray array];
@@ -845,13 +845,22 @@
// we want to do this in bulk as binding can be very slow and there are
potentially many notes
mwcFlags.addOrRemoveNotesInBulk = 1;
- if (replace) {
- [pdfView removePDFToolTipRects];
- // remove the current annotations
- [pdfView setActiveAnnotation:nil];
- for (annotation in [[notes copy] autorelease])
+ if ([notesToRemove count]) {
+ // notesToRemove is either all notes, no notes, or non Skim notes
+ BOOL removeAllNotes = [[notesToRemove firstObject] isSkimNote];
+ if (removeAllNotes) {
+ [pdfView removePDFToolTipRects];
+ // remove the current annotations
+ [pdfView setActiveAnnotation:nil];
+ }
+ for (annotation in [[notesToRemove copy] autorelease]) {
+ PDFAnnotation *popup = [annotation popup];
+ if (popup)
+ [pdfView removeAnnotation:popup];
[pdfView removeAnnotation:annotation];
- [self removeAllObjectsFromNotes];
+ }
+ if (removeAllNotes)
+ [self removeAllObjectsFromNotes];
}
// create new annotations from the dictionary and add them to their page
and to the document
@@ -867,6 +876,8 @@
pageIndex = [pdfDoc pageCount] - 1;
PDFPage *page = [pdfDoc pageAtIndex:pageIndex];
[pdfView addAnnotation:annotation toPage:page];
+ if (autoUpdate && [[annotation contents] length] == 0)
+ [annotation autoUpdateString];
[notesToAdd addObject:annotation];
[annotation release];
}
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