Revision: 6687
          http://skim-app.svn.sourceforge.net/skim-app/?rev=6687&view=rev
Author:   hofman
Date:     2010-08-10 17:03:49 +0000 (Tue, 10 Aug 2010)

Log Message:
-----------
add script command to read notes from a separate file

Modified Paths:
--------------
    trunk/SKMainDocument.h
    trunk/SKMainDocument.m
    trunk/Skim.sdef

Modified: trunk/SKMainDocument.h
===================================================================
--- trunk/SKMainDocument.h      2010-08-10 13:19:27 UTC (rev 6686)
+++ trunk/SKMainDocument.h      2010-08-10 17:03:49 UTC (rev 6687)
@@ -139,6 +139,7 @@
 - (id)handleFindScriptCommand:(NSScriptCommand *)command;
 - (void)handleShowTeXScriptCommand:(NSScriptCommand *)command;
 - (void)handleConvertNotesScriptCommand:(NSScriptCommand *)command;
+- (void)handleReadNotesScriptCommand:(NSScriptCommand *)command;
 
 @end
 

Modified: trunk/SKMainDocument.m
===================================================================
--- trunk/SKMainDocument.m      2010-08-10 13:19:27 UTC (rev 6686)
+++ trunk/SKMainDocument.m      2010-08-10 17:03:49 UTC (rev 6687)
@@ -855,27 +855,30 @@
     [[self pdfView] printWithInfo:[self printInfo] autoRotate:autoRotate];
 }
 
-- (void)openPanelDidEnd:(NSOpenPanel *)oPanel returnCode:(NSInteger)returnCode 
 contextInfo:(void  *)contextInfo{
+- (void)readNotesFromURL:(NSURL *)notesURL replace:(BOOL)replace {
+    NSString *extension = [[notesURL path] pathExtension];
+    NSArray *array = nil;
+    
+    if ([extension caseInsensitiveCompare:@"skim"] == NSOrderedSame) {
+        array = [NSKeyedUnarchiver unarchiveObjectWithFile:[notesURL path]];
+    } else {
+        NSData *fdfData = [NSData dataWithContentsOfURL:notesURL];
+        if (fdfData)
+            array = [SKFDFParser noteDictionariesFromFDFData:fdfData];
+    }
+    
+    if (array) {
+        [[self mainWindowController] addAnnotationsFromDictionaries:array 
replace:replace];
+        [[self undoManager] setActionName:replace ? 
NSLocalizedString(@"Replace Notes", @"Undo action name") : 
NSLocalizedString(@"Add Notes", @"Undo action name")];
+    } else
+        NSBeep();
+}
+
+- (void)openPanelDidEnd:(NSOpenPanel *)oPanel returnCode:(NSInteger)returnCode 
contextInfo:(void *)contextInfo {
     if (returnCode == NSOKButton) {
         NSURL *notesURL = [[oPanel URLs] objectAtIndex:0];
-        NSString *extension = [[notesURL path] pathExtension];
-        NSArray *array = nil;
-        
-        if ([extension caseInsensitiveCompare:@"skim"] == NSOrderedSame) {
-            array = [NSKeyedUnarchiver unarchiveObjectWithFile:[notesURL 
path]];
-        } else {
-            NSData *fdfData = [NSData dataWithContentsOfURL:notesURL];
-            if (fdfData)
-                array = [SKFDFParser noteDictionariesFromFDFData:fdfData];
-        }
-        
-        if (array) {
-            BOOL replace = ([[oPanel accessoryView] 
isEqual:readNotesAccessoryView] && [replaceNotesCheckButton state] == 
NSOnState);
-            [[self mainWindowController] addAnnotationsFromDictionaries:array 
replace:replace];
-            [[self undoManager] setActionName:replace ? 
NSLocalizedString(@"Replace Notes", @"Undo action name") : 
NSLocalizedString(@"Add Notes", @"Undo action name")];
-        } else
-            NSBeep();
-        
+        BOOL replace = ([[oPanel accessoryView] 
isEqual:readNotesAccessoryView] && [replaceNotesCheckButton state] == 
NSOnState);
+        [self readNotesFromURL:notesURL replace:replace];
     }
 }
 
@@ -2124,8 +2127,25 @@
 - (void)handleConvertNotesScriptCommand:(NSScriptCommand *)command {
     if (SKIsPDFDocumentType([self fileType]) || 
SKIsPDFBundleDocumentType([self fileType]))
         [self convertNotesSheetDidEnd:nil returnCode:NSAlertDefaultReturn 
contextInfo:NULL];
+    else
+        [command setScriptErrorNumber:NSArgumentsWrongScriptError];
 }
 
+- (void)handleReadNotesScriptCommand:(NSScriptCommand *)command {
+    NSDictionary *args = [command evaluatedArguments];
+    NSURL *notesURL = [args objectForKey:@"File"];
+    if (notesURL == nil) {
+        [command setScriptErrorNumber:NSRequiredArgumentsMissingScriptError];
+    } else {
+        NSNumber *replaceNumber = [args objectForKey:@"Replace"];
+        NSString *fileType = [[NSDocumentController sharedDocumentController] 
typeForContentsOfURL:notesURL error:NULL];
+        if (SKIsNotesDocumentType(fileType) || 
SKIsNotesFDFDocumentType(fileType))
+            [self readNotesFromURL:notesURL replace:(replaceNumber ? 
[replaceNumber boolValue] : YES)];
+        else
+            [command setScriptErrorNumber:NSArgumentsWrongScriptError];
+    }
+}
+
 @end
 
 

Modified: trunk/Skim.sdef
===================================================================
--- trunk/Skim.sdef     2010-08-10 13:19:27 UTC (rev 6686)
+++ trunk/Skim.sdef     2010-08-10 17:03:49 UTC (rev 6687)
@@ -558,6 +558,20 @@
                 description="The document(s) for which to convert notes."/>
         </command>
 
+        <command name="read notes" code="SKIMRNot"
+            description="Convert in a document PDF annotations to Skim notes.">
+            <direct-parameter type="document"
+                description="The document(s) for which to convert notes."/>
+                       <parameter name="from" code="from" type="file" 
+                               description="The file from which to read the 
notes."> 
+                               <cocoa key="File"/> 
+                       </parameter>
+                       <parameter name="replacing" code="Repl" type="boolean" 
optional="yes" 
+                               description="Whether to replace the currently 
existing notes. Default is true."> 
+                               <cocoa key="Replace"/> 
+                       </parameter>
+        </command>
+
         <command name="find" code="SKIMFind"
             description="Find text in a document.">
             <direct-parameter type="document"
@@ -893,6 +907,9 @@
             <responds-to name="convert notes">
                 <cocoa method="handleConvertNotesScriptCommand:"/>
             </responds-to>
+            <responds-to name="read notes">
+                <cocoa method="handleReadNotesScriptCommand:"/>
+            </responds-to>
             <responds-to name="find">
                 <cocoa method="handleFindScriptCommand:"/>
             </responds-to>


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 

Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev 
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to