Revision: 3124
          http://skim-app.svn.sourceforge.net/skim-app/?rev=3124&view=rev
Author:   hofman
Date:     2007-11-01 10:24:59 -0700 (Thu, 01 Nov 2007)

Log Message:
-----------
Add methods to convert embedded PDF annotations to Skim notes.

Modified Paths:
--------------
    trunk/English.lproj/MainMenu.nib/classes.nib
    trunk/English.lproj/MainMenu.nib/keyedobjects.nib
    trunk/SKDocument.h
    trunk/SKDocument.m
    trunk/SKPDFAnnotationNote.h
    trunk/SKPDFAnnotationNote.m

Modified: trunk/English.lproj/MainMenu.nib/classes.nib
===================================================================
--- trunk/English.lproj/MainMenu.nib/classes.nib        2007-11-01 16:12:40 UTC 
(rev 3123)
+++ trunk/English.lproj/MainMenu.nib/classes.nib        2007-11-01 17:24:59 UTC 
(rev 3124)
@@ -12,6 +12,7 @@
                 changeRightSidePaneState = id; 
                 changeToolMode = id; 
                 chooseTransition = id; 
+                convertNotes = id; 
                 createNewNote = id; 
                 crop = id; 
                 cropAll = id; 

Modified: trunk/English.lproj/MainMenu.nib/keyedobjects.nib
===================================================================
(Binary files differ)

Modified: trunk/SKDocument.h
===================================================================
--- trunk/SKDocument.h  2007-11-01 16:12:40 UTC (rev 3123)
+++ trunk/SKDocument.h  2007-11-01 17:24:59 UTC (rev 3124)
@@ -88,6 +88,7 @@
 }
 
 - (IBAction)readNotes:(id)sender;
+- (IBAction)convertNotes:(id)sender;
 - (IBAction)saveArchive:(id)sender;
 - (IBAction)saveDiskImage:(id)sender;
 

Modified: trunk/SKDocument.m
===================================================================
--- trunk/SKDocument.m  2007-11-01 16:12:40 UTC (rev 3123)
+++ trunk/SKDocument.m  2007-11-01 17:24:59 UTC (rev 3124)
@@ -482,6 +482,11 @@
     return dict;
 }
 
+- (void)setPDFDataUndoable:(NSData *)data {
+    [[[self undoManager] prepareWithInvocationTarget:self] 
setPDFDataUndoable:pdfData];
+    [self setPDFData:data];
+}
+
 - (void)setPDFData:(NSData *)data {
     if (pdfData != data) {
         [pdfData release];
@@ -743,6 +748,69 @@
                        contextInfo:NULL];              
 }
 
+- (void)convertNotesSheetDidEnd:(NSAlert *)alert returnCode:(int)returnCode 
contextInfo:(void *)contextInfo {
+    if (returnCode == NSAlertAlternateReturn)
+        return;
+    
+    [[[self windowForSheet] attachedSheet] orderOut:self];
+        
+    [[self progressController] setMessage:[NSLocalizedString(@"Converting 
notes", @"Message for progress sheet") stringByAppendingEllipsis]];
+    [[self progressController] setIndeterminate:YES];
+    [[self progressController] beginSheetModalForWindow:[self windowForSheet]];
+    
+    PDFDocument *pdfDoc = [self pdfDocument];
+    int i, count = [pdfDoc pageCount];
+    BOOL didConvert = NO;
+    
+    for (i = 0; i < count; i++) {
+        PDFPage *page = [pdfDoc pageAtIndex:i];
+        NSEnumerator *annEnum = [[page annotations] objectEnumerator];
+        PDFAnnotation *annotation;
+        
+        while (annotation = [annEnum nextObject]) {
+            if ([annotation isNoteAnnotation] == NO && [annotation 
isConvertibleAnnotation]) {
+                PDFAnnotation *newAnnotation = [annotation copyNoteAnnotation];
+                [[self pdfView] removeAnnotation:annotation];
+                [[self pdfView] addAnnotation:newAnnotation toPage:page];
+                [newAnnotation release];
+                didConvert = YES;
+            }
+        }
+    }
+    
+    if (didConvert) {
+        pdfDoc = [[PDFDocument alloc] initWithData:pdfData];
+        count = [pdfDoc pageCount];
+        for (i = 0; i < count; i++) {
+            PDFPage *page = [pdfDoc pageAtIndex:i];
+            NSEnumerator *annEnum = [[page annotations] objectEnumerator];
+            PDFAnnotation *annotation;
+            
+            while (annotation = [annEnum nextObject]) {
+                if ([annotation isNoteAnnotation] == NO && [annotation 
isConvertibleAnnotation])
+                    [page removeAnnotation:annotation];
+            }
+        }
+        
+        [self setPDFDataUndoable:[pdfDoc dataRepresentation]];
+        [pdfDoc release];
+    }
+    
+    [[self progressController] endSheet];
+}
+
+- (IBAction)convertNotes:(id)sender {
+    NSString *message = NSLocalizedString(@"This will convert PDF annotations 
to Skim notes. Do you want to proceed?", @"Informative text in alert dialog");
+    if (floor(NSAppKitVersionNumber) <= NSAppKitVersionNumber10_4)
+        message = NSLocalizedString(@"This will convert PDF annotations to 
Skim notes. This will loose the Table of Contents. Do you want to proceed?", 
@"Informative text in alert dialog");
+    NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Convert 
Notes", @"Alert text when trying to convert notes")
+                                     defaultButton:NSLocalizedString(@"OK", 
@"Button title")
+                                   
alternateButton:NSLocalizedString(@"Cancel", @"Button title")
+                                       otherButton:nil
+                         informativeTextWithFormat:message];
+    [alert beginSheetModalForWindow:[self windowForSheet] modalDelegate:self 
didEndSelector:@selector(convertNotesSheetDidEnd:returnCode:contextInfo:) 
contextInfo:NULL];
+}
+
 - (void)archiveSavePanelDidEnd:(NSSavePanel *)sheet returnCode:(int)returnCode 
 contextInfo:(void  *)contextInfo {
     
     if (NSOKButton == returnCode && [self fileURL]) {

Modified: trunk/SKPDFAnnotationNote.h
===================================================================
--- trunk/SKPDFAnnotationNote.h 2007-11-01 16:12:40 UTC (rev 3123)
+++ trunk/SKPDFAnnotationNote.h 2007-11-01 17:24:59 UTC (rev 3124)
@@ -77,6 +77,9 @@
 - (BOOL)isMovable;
 - (BOOL)isEditable;
 
+- (BOOL)isConvertibleAnnotation;
+- (id)copyNoteAnnotation;
+
 - (NSUndoManager *)undoManager;
 
 - (BOOL)hitTest:(NSPoint)point;

Modified: trunk/SKPDFAnnotationNote.m
===================================================================
--- trunk/SKPDFAnnotationNote.m 2007-11-01 16:12:40 UTC (rev 3123)
+++ trunk/SKPDFAnnotationNote.m 2007-11-01 17:24:59 UTC (rev 3124)
@@ -411,6 +411,10 @@
 
 - (BOOL)isEditable { return NO; }
 
+- (BOOL)isConvertibleAnnotation { return NO; }
+
+- (id)copyNoteAnnotation { return nil; }
+
 - (BOOL)hitTest:(NSPoint)point {
     return [self shouldDisplay] ? NSPointInRect(point, [self bounds]) : NO;
 }
@@ -690,6 +694,26 @@
 
 #pragma mark -
 
[EMAIL PROTECTED] PDFAnnotationCircle (SKExtensions)
[EMAIL PROTECTED]
+
[EMAIL PROTECTED] PDFAnnotationCircle (SKExtensions)
+
+- (BOOL)isConvertibleAnnotation { return YES; }
+
+- (id)copyNoteAnnotation {
+    SKPDFAnnotationCircle *annotation = [[SKPDFAnnotationCircle alloc] 
initWithBounds:[self bounds]];
+    [annotation setString:[self string]];
+    [annotation setColor:[self color]];
+    [annotation setBorder:[self border]];
+    [annotation setInteriorColor:[self interiorColor]];
+    return annotation;
+}
+
[EMAIL PROTECTED]
+
+#pragma mark -
+
 @implementation SKPDFAnnotationSquare
 
 - (id)initWithBounds:(NSRect)bounds {
@@ -765,6 +789,26 @@
 
 #pragma mark -
 
[EMAIL PROTECTED] PDFAnnotationSquare (SKExtensions)
[EMAIL PROTECTED]
+
[EMAIL PROTECTED] PDFAnnotationSquare (SKExtensions)
+
+- (BOOL)isConvertibleAnnotation { return YES; }
+
+- (id)copyNoteAnnotation {
+    SKPDFAnnotationSquare *annotation = [[SKPDFAnnotationSquare alloc] 
initWithBounds:[self bounds]];
+    [annotation setString:[self string]];
+    [annotation setColor:[self color]];
+    [annotation setBorder:[self border]];
+    [annotation setInteriorColor:[self interiorColor]];
+    return annotation;
+}
+
[EMAIL PROTECTED]
+
+#pragma mark -
+
 @implementation SKPDFAnnotationMarkup
 
 static NSArray *createStringsFromPoints(NSArray *points)
@@ -1080,6 +1124,27 @@
 
 #pragma mark -
 
[EMAIL PROTECTED] PDFAnnotationMarkup (SKExtensions)
[EMAIL PROTECTED]
+
[EMAIL PROTECTED] PDFAnnotationMarkup (SKExtensions)
+
+- (BOOL)isConvertibleAnnotation { return YES; }
+
+- (id)copyNoteAnnotation {
+    NSArray *quadPoints = createStringsFromPoints([self quadrilateralPoints]);
+    SKPDFAnnotationMarkup *annotation = [[SKPDFAnnotationMarkup alloc] 
initWithBounds:[self bounds] markupType:[self markupType] 
quadrilateralPointsAsStrings:quadPoints];
+    [quadPoints release];
+    [annotation setString:[self string]];
+    [annotation setColor:[self color]];
+    [annotation setBorder:[self border]];
+    return annotation;
+}
+
[EMAIL PROTECTED]
+
+#pragma mark -
+
 @implementation SKPDFAnnotationFreeText
 
 - (id)initWithBounds:(NSRect)bounds {
@@ -1189,6 +1254,28 @@
 
 #pragma mark -
 
[EMAIL PROTECTED] PDFAnnotationFreeText (SKExtensions)
[EMAIL PROTECTED]
+
[EMAIL PROTECTED] PDFAnnotationFreeText (SKExtensions)
+
+- (BOOL)isConvertibleAnnotation { return YES; }
+
+- (id)copyNoteAnnotation {
+    SKPDFAnnotationFreeText *annotation = [[SKPDFAnnotationFreeText alloc] 
initWithBounds:[self bounds]];
+    [annotation setString:[self string]];
+    [annotation setColor:[self color]];
+    [annotation setBorder:[self border]];
+    [annotation setFont:[self font]];
+    if ([self respondsToSelector:@selector(rotation)] && [annotation 
respondsToSelector:@selector(setRotation:)])
+        [annotation setRotation:[self rotation]];
+    return annotation;
+}
+
[EMAIL PROTECTED]
+
+#pragma mark -
+
 @implementation SKPDFAnnotationNote
 
 - (id)initWithBounds:(NSRect)bounds {
@@ -1433,6 +1520,26 @@
 
 #pragma mark -
 
[EMAIL PROTECTED] PDFAnnotationText (SKExtensions)
[EMAIL PROTECTED]
+
[EMAIL PROTECTED] PDFAnnotationText (SKExtensions)
+
+- (BOOL)isConvertibleAnnotation { return YES; }
+
+- (id)copyNoteAnnotation {
+    SKPDFAnnotationNote *annotation = [[SKPDFAnnotationNote alloc] 
initWithBounds:[self bounds]];
+    [annotation setString:[self string]];
+    [annotation setColor:[self color]];
+    [annotation setBorder:[self border]];
+    [annotation setIconType:[self iconType]];
+    return annotation;
+}
+
[EMAIL PROTECTED]
+
+#pragma mark -
+
 @implementation SKPDFAnnotationLine
 
 - (id)initWithBounds:(NSRect)bounds {
@@ -1741,6 +1848,29 @@
 
 #pragma mark -
 
[EMAIL PROTECTED] PDFAnnotationLine (SKExtensions)
[EMAIL PROTECTED]
+
[EMAIL PROTECTED] PDFAnnotationLine (SKExtensions)
+
+- (BOOL)isConvertibleAnnotation { return YES; }
+
+- (id)copyNoteAnnotation {
+    SKPDFAnnotationLine *annotation = [[SKPDFAnnotationLine alloc] 
initWithBounds:[self bounds]];
+    [annotation setString:[self string]];
+    [annotation setColor:[self color]];
+    [annotation setBorder:[self border]];
+    [annotation setStartPoint:[self startPoint]];
+    [annotation setEndPoint:[self endPoint]];
+    [annotation setStartLineStyle:[self startLineStyle]];
+    [annotation setEndLineStyle:[self endLineStyle]];
+    return annotation;
+}
+
[EMAIL PROTECTED]
+
+#pragma mark -
+
 // useful for highlighting things; isTemporaryAnnotation is so we know to 
remove it
 @implementation SKPDFAnnotationTemporary
 


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: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to