Revision: 4997
http://skim-app.svn.sourceforge.net/skim-app/?rev=4997&view=rev
Author: hofman
Date: 2008-11-26 18:14:00 +0000 (Wed, 26 Nov 2008)
Log Message:
-----------
Remove and move code for note conversion. Normalize anchored note properties in
single place.
Modified Paths:
--------------
trunk/SKFDFParser.m
trunk/SKMainWindowController.h
trunk/SKMainWindowController.m
trunk/SKMainWindowController_UI.m
trunk/SKNPDFAnnotationNote_SKExtensions.h
trunk/SKNPDFAnnotationNote_SKExtensions.m
trunk/SKPDFDocument.m
Modified: trunk/SKFDFParser.m
===================================================================
--- trunk/SKFDFParser.m 2008-11-26 14:10:13 UTC (rev 4996)
+++ trunk/SKFDFParser.m 2008-11-26 18:14:00 UTC (rev 4997)
@@ -43,6 +43,7 @@
#import "NSGeometry_SKExtensions.h"
#import "SKStringConstants.h"
#import <SkimNotes/SkimNotes.h>
+#import "SKNPDFAnnotationNote_SKExtensions.h"
SKFDFString SKFDFFDFKey = "FDF";
SKFDFString SKFDFAnnotationsKey = "Annots";
@@ -216,28 +217,6 @@
[contents release];
}
- if (success) {
- NSSet *validTypes = [NSSet setWithObjects:SKNFreeTextString,
SKNNoteString, SKNCircleString, SKNSquareString, SKNHighlightString,
SKNUnderlineString, SKNStrikeOutString, SKNLineString, SKNInkString, nil];
- NSString *type = [dictionary objectForKey:SKNPDFAnnotationTypeKey];
- NSString *contents;
- if ([type isEqualToString:SKNTextString]) {
- [dictionary setObject:SKNNoteString
forKey:SKNPDFAnnotationTypeKey];
- if (contents = [dictionary
objectForKey:SKNPDFAnnotationContentsKey]) {
- NSRange r = [contents rangeOfString:@" "];
- if (NSMaxRange(r) < [contents length]) {
- NSFont *font = [NSFont fontWithName:[[NSUserDefaults
standardUserDefaults] stringForKey:SKAnchoredNoteFontNameKey]
- size:[[NSUserDefaults
standardUserDefaults] floatForKey:SKAnchoredNoteFontSizeKey]];
- NSAttributedString *attrString = [[[NSAttributedString
alloc] initWithString:[contents substringFromIndex:NSMaxRange(r)]
-
attributes:[NSDictionary dictionaryWithObjectsAndKeys:font,
NSFontAttributeName, nil]] autorelease];
- [dictionary setObject:attrString
forKey:SKNPDFAnnotationTextKey];
- [dictionary setObject:[contents
substringToIndex:r.location] forKey:SKNPDFAnnotationContentsKey];
- }
- }
- } else if ([validTypes containsObject:type] == NO) {
- success = NO;
- }
- }
-
if (success && CGPDFDictionaryGetArray(annot, SKFDFAnnotationBoundsKey,
&array)) {
CGPDFReal l, b, r, t;
if (CGPDFArrayGetCount(array) == 4 && CGPDFArrayGetNumber(array, 0,
&l) && CGPDFArrayGetNumber(array, 1, &b) && CGPDFArrayGetNumber(array, 2, &r)
&& CGPDFArrayGetNumber(array, 3, &t)) {
@@ -248,6 +227,16 @@
success = NO;
}
+ if (success) {
+ NSSet *validTypes = [NSSet setWithObjects:SKNFreeTextString,
SKNNoteString, SKNCircleString, SKNSquareString, SKNHighlightString,
SKNUnderlineString, SKNStrikeOutString, SKNLineString, SKNInkString, nil];
+ NSString *type = [dictionary objectForKey:SKNPDFAnnotationTypeKey];
+ if ([type isEqualToString:SKNTextString]) {
+ [dictionary setDictionary:[SKNPDFAnnotationNote
textToNoteSkimNoteProperties:dictionary]];
+ } else if ([validTypes containsObject:type] == NO) {
+ success = NO;
+ }
+ }
+
if (success && CGPDFDictionaryGetInteger(annot,
SKFDFAnnotationPageIndexKey, &integer)) {
[dictionary setObject:[NSNumber numberWithInt:integer]
forKey:SKNPDFAnnotationPageIndexKey];
} else {
Modified: trunk/SKMainWindowController.h
===================================================================
--- trunk/SKMainWindowController.h 2008-11-26 14:10:13 UTC (rev 4996)
+++ trunk/SKMainWindowController.h 2008-11-26 18:14:00 UTC (rev 4997)
@@ -430,9 +430,6 @@
- (void)updateNoteSelection;
-- (void)addNote:(PDFAnnotation *)note;
-- (void)removeNote:(PDFAnnotation *)note;
-
- (void)updateThumbnailSelection;
- (void)resetThumbnails;
- (void)resetThumbnailSizeIfNeeded;
Modified: trunk/SKMainWindowController.m
===================================================================
--- trunk/SKMainWindowController.m 2008-11-26 14:10:13 UTC (rev 4996)
+++ trunk/SKMainWindowController.m 2008-11-26 18:14:00 UTC (rev 4997)
@@ -3700,22 +3700,6 @@
[noteOutlineView reloadData];
}
-- (void)addNote:(PDFAnnotation *)note {
- updatingNoteSelection = YES;
- [[self mutableArrayValueForKey:SKMainWindowNotesKey] addObject:note];
- [noteArrayController rearrangeObjects]; // doesn't seem to be done
automatically
- updatingNoteSelection = NO;
- [noteOutlineView reloadData];
-}
-
-- (void)removeNote:(PDFAnnotation *)note {
- updatingNoteSelection = YES;
- [[self mutableArrayValueForKey:SKMainWindowNotesKey] removeObject:note];
- [noteArrayController rearrangeObjects]; // doesn't seem to be done
automatically
- updatingNoteSelection = NO;
- [noteOutlineView reloadData];
-}
-
#pragma mark Snapshots
- (void)resetSnapshotSizeIfNeeded {
Modified: trunk/SKMainWindowController_UI.m
===================================================================
--- trunk/SKMainWindowController_UI.m 2008-11-26 14:10:13 UTC (rev 4996)
+++ trunk/SKMainWindowController_UI.m 2008-11-26 18:14:00 UTC (rev 4997)
@@ -1483,9 +1483,13 @@
PDFAnnotation *annotation = [[notification userInfo]
objectForKey:SKPDFViewAnnotationKey];
PDFPage *page = [[notification userInfo] objectForKey:SKPDFViewPageKey];
- if ([annotation isSkimNote])
- [self addNote:annotation];
-
+ if ([annotation isSkimNote]) {
+ updatingNoteSelection = YES;
+ [[self mutableArrayValueForKey:SKMainWindowNotesKey]
addObject:annotation];
+ [noteArrayController rearrangeObjects]; // doesn't seem to be done
automatically
+ updatingNoteSelection = NO;
+ [noteOutlineView reloadData];
+ }
if (page) {
[self updateThumbnailAtPageIndex:[page pageIndex]];
NSEnumerator *snapshotEnum = [snapshots objectEnumerator];
@@ -1516,7 +1520,11 @@
}
}
- [self removeNote:annotation];
+ updatingNoteSelection = YES;
+ [[self mutableArrayValueForKey:SKMainWindowNotesKey]
removeObject:annotation];
+ [noteArrayController rearrangeObjects]; // doesn't seem to be done
automatically
+ updatingNoteSelection = NO;
+ [noteOutlineView reloadData];
}
if (page) {
[self updateThumbnailAtPageIndex:[page pageIndex]];
@@ -1528,7 +1536,6 @@
}
[secondaryPdfView setNeedsDisplayForAnnotation:annotation onPage:page];
}
- [noteOutlineView reloadData];
}
- (void)handleDidMoveAnnotationNotification:(NSNotification *)notification {
Modified: trunk/SKNPDFAnnotationNote_SKExtensions.h
===================================================================
--- trunk/SKNPDFAnnotationNote_SKExtensions.h 2008-11-26 14:10:13 UTC (rev
4996)
+++ trunk/SKNPDFAnnotationNote_SKExtensions.h 2008-11-26 18:14:00 UTC (rev
4997)
@@ -53,5 +53,6 @@
#pragma mark -
@interface SKNPDFAnnotationNote (SKExtensions)
++ (NSDictionary *)textToNoteSkimNoteProperties:(NSDictionary *)properties;
- (void)setRichText:(id)newText;
@end
Modified: trunk/SKNPDFAnnotationNote_SKExtensions.m
===================================================================
--- trunk/SKNPDFAnnotationNote_SKExtensions.m 2008-11-26 14:10:13 UTC (rev
4996)
+++ trunk/SKNPDFAnnotationNote_SKExtensions.m 2008-11-26 18:14:00 UTC (rev
4997)
@@ -53,6 +53,30 @@
@implementation SKNPDFAnnotationNote (SKExtensions)
++ (NSDictionary *)textToNoteSkimNoteProperties:(NSDictionary *)properties {
+ if ([[properties objectForKey:SKNPDFAnnotationTypeKey]
isEqualToString:SKNTextString]) {
+ NSMutableDictionary *mutableProperties = [[properties mutableCopy]
autorelease];
+ NSRect bounds = NSRectFromString([properties
objectForKey:SKNPDFAnnotationBoundsKey]);
+ NSString *contents = [properties
objectForKey:SKNPDFAnnotationContentsKey];
+ [mutableProperties setObject:SKNNoteString
forKey:SKNPDFAnnotationTypeKey];
+ bounds.size = SKNPDFAnnotationNoteSize;
+ [mutableProperties setObject:NSStringFromRect(bounds)
forKey:SKNPDFAnnotationBoundsKey];
+ if (contents) {
+ NSRange r = [contents rangeOfString:@" "];
+ if (NSMaxRange(r) < [contents length]) {
+ NSFont *font = [NSFont fontWithName:[[NSUserDefaults
standardUserDefaults] stringForKey:SKAnchoredNoteFontNameKey]
+ size:[[NSUserDefaults
standardUserDefaults] floatForKey:SKAnchoredNoteFontSizeKey]];
+ NSAttributedString *attrString = [[[NSAttributedString alloc]
initWithString:[contents substringFromIndex:NSMaxRange(r)]
+ attributes:[NSDictionary
dictionaryWithObjectsAndKeys:font, NSFontAttributeName, nil]] autorelease];
+ [mutableProperties setObject:attrString
forKey:SKNPDFAnnotationTextKey];
+ [mutableProperties setObject:[contents
substringToIndex:r.location] forKey:SKNPDFAnnotationContentsKey];
+ }
+ }
+ return mutableProperties;
+ }
+ return properties;
+}
+
- (id)initSkimNoteWithBounds:(NSRect)bounds {
if (self = [super initSkimNoteWithBounds:bounds]) {
[self setColor:[[NSUserDefaults standardUserDefaults]
colorForKey:SKAnchoredNoteColorKey]];
Modified: trunk/SKPDFDocument.m
===================================================================
--- trunk/SKPDFDocument.m 2008-11-26 14:10:13 UTC (rev 4996)
+++ trunk/SKPDFDocument.m 2008-11-26 18:14:00 UTC (rev 4997)
@@ -94,9 +94,6 @@
- (void)setNoteDicts:(NSArray *)array;
- (void)setPassword:(NSString *)newPassword;
-- (void)addAsNote:(PDFAnnotation *)annotation;
-- (void)removeAsNote:(PDFAnnotation *)annotation;
-
- (void)tryToUnlockDocument:(PDFDocument *)document;
- (void)checkFileUpdatesIfNeeded;
@@ -855,24 +852,6 @@
contextInfo:NULL];
}
-- (void)addAsNote:(PDFAnnotation *)annotation {
- [[[self undoManager] prepareWithInvocationTarget:self]
removeAsNote:annotation];
- [[[self undoManager] prepareWithInvocationTarget:annotation]
setShouldDisplay:[annotation shouldDisplay]];
- [[[self undoManager] prepareWithInvocationTarget:annotation]
setShouldPrint:[annotation shouldPrint]];
- [annotation setShouldDisplay:[[self pdfView] hideNotes] == NO];
- [annotation setShouldPrint:[[self pdfView] hideNotes] == NO];
- [annotation setSkimNote:YES];
- [[self mainWindowController] addNote:annotation];
-}
-
-- (void)removeAsNote:(PDFAnnotation *)annotation {
- [[[self undoManager] prepareWithInvocationTarget:self]
addAsNote:annotation];
- if ([[self pdfView] activeAnnotation] == annotation)
- [[self pdfView] setActiveAnnotation:nil];
- [annotation setSkimNote:NO];
- [[self mainWindowController] removeNote:annotation];
-}
-
- (void)convertNotesSheetDidEnd:(NSAlert *)alert returnCode:(int)returnCode
contextInfo:(void *)contextInfo {
if (returnCode == NSAlertAlternateReturn)
return;
@@ -895,26 +874,8 @@
while (annotation = [annEnum nextObject]) {
if ([annotation isSkimNote] == NO && [annotation
isConvertibleAnnotation]) {
NSDictionary *properties = [annotation SkimNoteProperties];
- if ([[annotation type] isEqualToString:SKNTextString]) {
- NSMutableDictionary *tmpProperties = [[properties
mutableCopy] autorelease];
- NSRect bounds = NSRectFromString([properties
objectForKey:SKNPDFAnnotationBoundsKey]);
- NSString *contents = [properties
objectForKey:SKNPDFAnnotationContentsKey];
- [tmpProperties setObject:SKNNoteString
forKey:SKNPDFAnnotationTypeKey];
- bounds.size = SKNPDFAnnotationNoteSize;
- [tmpProperties setObject:NSStringFromRect(bounds)
forKey:SKNPDFAnnotationBoundsKey];
- if (contents) {
- NSRange r = [contents rangeOfString:@" "];
- if (NSMaxRange(r) < [contents length]) {
- NSFont *font = [NSFont
fontWithName:[[NSUserDefaults standardUserDefaults]
stringForKey:SKAnchoredNoteFontNameKey]
-
size:[[NSUserDefaults standardUserDefaults]
floatForKey:SKAnchoredNoteFontSizeKey]];
- NSAttributedString *attrString =
[[[NSAttributedString alloc] initWithString:[contents
substringFromIndex:NSMaxRange(r)]
-
attributes:[NSDictionary dictionaryWithObjectsAndKeys:font,
NSFontAttributeName, nil]] autorelease];
- [tmpProperties setObject:attrString
forKey:SKNPDFAnnotationTextKey];
- [tmpProperties setObject:[contents
substringToIndex:r.location] forKey:SKNPDFAnnotationContentsKey];
- }
- }
- properties = tmpProperties;
- }
+ if ([[annotation type] isEqualToString:SKNTextString])
+ properties = [SKNPDFAnnotationNote
textToNoteSkimNoteProperties:properties];
PDFAnnotation *newAnnotation = [[PDFAnnotation alloc]
initSkimNoteWithProperties:properties];
if (newAnnotation) {
[[self pdfView] removeAnnotation:annotation];
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit