Revision: 2740
          http://skim-app.svn.sourceforge.net/skim-app/?rev=2740&view=rev
Author:   hofman
Date:     2007-08-28 04:43:08 -0700 (Tue, 28 Aug 2007)

Log Message:
-----------
Add a document type for a package containing the pdf and the notes. File 
extension is pdfd. Saved and read as a fileWrapper.

Modified Paths:
--------------
    trunk/Dutch.lproj/InfoPlist.strings
    trunk/English.lproj/InfoPlist.strings
    trunk/French.lproj/InfoPlist.strings
    trunk/Info.plist
    trunk/Italian.lproj/InfoPlist.strings
    trunk/SKDocument.h
    trunk/SKDocument.m
    trunk/SKDocumentController.h
    trunk/SKDocumentController.m
    trunk/Skim.xcodeproj/project.pbxproj

Added Paths:
-----------
    trunk/Images/PDFDDocument.icns

Modified: trunk/Dutch.lproj/InfoPlist.strings
===================================================================
(Binary files differ)

Modified: trunk/English.lproj/InfoPlist.strings
===================================================================
(Binary files differ)

Modified: trunk/French.lproj/InfoPlist.strings
===================================================================
(Binary files differ)

Added: trunk/Images/PDFDDocument.icns
===================================================================
(Binary files differ)


Property changes on: trunk/Images/PDFDDocument.icns
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Modified: trunk/Info.plist
===================================================================
--- trunk/Info.plist    2007-08-28 09:24:37 UTC (rev 2739)
+++ trunk/Info.plist    2007-08-28 11:43:08 UTC (rev 2740)
@@ -37,6 +37,7 @@
                        <key>NSExportableAs</key>
                        <array>
                                <string>NSPDFPboardType</string>
+                               <string>PDF Package</string>
                                <string>PDF With Embedded Notes</string>
                                <string>PDF Without Notes</string>
                                <string>Skim Notes</string>
@@ -47,6 +48,43 @@
                <dict>
                        <key>CFBundleTypeExtensions</key>
                        <array>
+                               <string>pdfd</string>
+                       </array>
+                       <key>CFBundleTypeIconFile</key>
+                       <string>PDFDDocument</string>
+                       <key>CFBundleTypeName</key>
+                       <string>PDF Bundle</string>
+                       <key>CFBundleTypeOSTypes</key>
+                       <array>
+                               <string>PDFD</string>
+                       </array>
+                       <key>CFBundleTypeRole</key>
+                       <string>Editor</string>
+                       <key>LSIsAppleDefaultForType</key>
+                       <true/>
+                       <key>LSItemContentTypes</key>
+                       <array>
+                               <string>net.sourceforge.skim-app.pdfd</string>
+                       </array>
+                       <key>LSTypeIsPackage</key>
+                       <true/>
+                       <key>NSDocumentClass</key>
+                       <string>SKDocument</string>
+                       <key>NSExportableAs</key>
+                       <array>
+                               <string>NSPDFPboardType</string>
+                               <string>PDF With Embedded Notes</string>
+                               <string>PDF Without Notes</string>
+                               <string>Skim Notes</string>
+                               <string>Notes as RTF</string>
+                               <string>Notes as Text</string>
+                       </array>
+                       <key>NSPersistentStoreTypeKey</key>
+                       <string>Binary</string>
+               </dict>
+               <dict>
+                       <key>CFBundleTypeExtensions</key>
+                       <array>
                                <string>skim</string>
                        </array>
                        <key>CFBundleTypeIconFile</key>
@@ -55,6 +93,8 @@
                        <string>Skim Notes</string>
                        <key>CFBundleTypeRole</key>
                        <string>Editor</string>
+                       <key>LSIsAppleDefaultForType</key>
+                       <true/>
                        <key>LSItemContentTypes</key>
                        <array>
                                
<string>net.sourceforge.skim-app.skimnotes</string>
@@ -325,6 +365,43 @@
        <string>MainMenu</string>
        <key>NSPrincipalClass</key>
        <string>SKApplication</string>
+       <key>NSServices</key>
+       <array>
+               <dict>
+                       <key>NSMenuItem</key>
+                       <dict>
+                               <key>default</key>
+                               <string>Skim/Open PDF at URL</string>
+                       </dict>
+                       <key>NSMessage</key>
+                       <string>openDocumentFromURLOnPboard</string>
+                       <key>NSPortName</key>
+                       <string>Skim</string>
+                       <key>NSSendTypes</key>
+                       <array>
+                               <string>NSURLPboardType</string>
+                               <string>NSStringPboardType</string>
+                               <string>CorePasteboardFlavorType 
0x75726C20</string>
+                       </array>
+               </dict>
+               <dict>
+                       <key>NSMenuItem</key>
+                       <dict>
+                               <key>default</key>
+                               <string>Skim/Open Selected PDF</string>
+                       </dict>
+                       <key>NSMessage</key>
+                       <string>openDocumentFromDataOnPboard</string>
+                       <key>NSPortName</key>
+                       <string>Skim</string>
+                       <key>NSSendTypes</key>
+                       <array>
+                               <string>NSPDFPboardType</string>
+                               <string>NSPostScriptPboardType</string>
+                               <string>NSTIFFPboardType</string>
+                       </array>
+               </dict>
+       </array>
        <key>OSAScriptingDefinition</key>
        <string>Skim.sdef</string>
        <key>SUFeedURL</key>
@@ -334,6 +411,26 @@
                <dict>
                        <key>UTTypeConformsTo</key>
                        <array>
+                               <string>com.apple.package</string>
+                               <string>public.composite-content </string>
+                       </array>
+                       <key>UTTypeDescription</key>
+                       <string>PDF Bundle</string>
+                       <key>UTTypeIconFile</key>
+                       <string>PDFDDocument</string>
+                       <key>UTTypeIdentifier</key>
+                       <string>net.sourceforge.skim-app.pdfd</string>
+                       <key>UTTypeTagSpecification</key>
+                       <dict>
+                               <key>public.filename-extension</key>
+                               <array>
+                                       <string>pdfd</string>
+                               </array>
+                       </dict>
+               </dict>
+               <dict>
+                       <key>UTTypeConformsTo</key>
+                       <array>
                                <string>public.data</string>
                        </array>
                        <key>UTTypeDescription</key>
@@ -351,43 +448,5 @@
                        </dict>
                </dict>
        </array>
-   <key>NSServices</key>
-  <array>
-     <dict>
-        <key>NSMenuItem</key>
-        <dict>
-           <key>default</key>
-           <string>Skim/Open PDF at URL</string>
-        </dict>
-        <key>NSMessage</key>
-        <string>openDocumentFromURLOnPboard</string>
-        <key>NSPortName</key>
-        <string>Skim</string>
-        <key>NSSendTypes</key>
-        <array>
-           <string>NSURLPboardType</string>
-           <string>NSStringPboardType</string>
-           <string>CorePasteboardFlavorType 0x75726C20</string>
-        </array>
-     </dict>
-     <dict>
-        <key>NSMenuItem</key>
-        <dict>
-           <key>default</key>
-           <string>Skim/Open Selected PDF</string>
-        </dict>
-        <key>NSMessage</key>
-        <string>openDocumentFromDataOnPboard</string>
-        <key>NSPortName</key>
-        <string>Skim</string>
-        <key>NSSendTypes</key>
-        <array>
-           <string>NSPDFPboardType</string>
-           <string>NSPostScriptPboardType</string>
-           <string>NSTIFFPboardType</string>
-        </array>
-     </dict>
-  </array>
-
 </dict>
 </plist>

Modified: trunk/Italian.lproj/InfoPlist.strings
===================================================================
(Binary files differ)

Modified: trunk/SKDocument.h
===================================================================
--- trunk/SKDocument.h  2007-08-28 09:24:37 UTC (rev 2739)
+++ trunk/SKDocument.h  2007-08-28 11:43:08 UTC (rev 2740)
@@ -81,6 +81,7 @@
     BOOL autoUpdate;
     BOOL isSaving;
     BOOL fileChangedOnDisk;
+    NSSaveOperationType currentSaveOperation;
     
     // only used for network filesystems; fileUpdateTimer is not retained by 
the doc
     NSDate *lastModifiedDate;

Modified: trunk/SKDocument.m
===================================================================
--- trunk/SKDocument.m  2007-08-28 09:24:37 UTC (rev 2739)
+++ trunk/SKDocument.m  2007-08-28 11:43:08 UTC (rev 2740)
@@ -62,8 +62,13 @@
 #import "Files_SKExtensions.h"
 
 // maximum length of xattr value recommended by Apple
-#define MAX_XATTR_LENGTH 2048
+#define MAX_XATTR_LENGTH        2048
 
+#define WRAPPER_PDF_FILENAME    @"data.pdf"
+#define WRAPPER_SKIM_FILENAME   @"data.skim"
+#define WRAPPER_TXT_FILENAME    @"data.txt"
+#define WRAPPER_RTF_FILENAME    @"data.rtf"
+
 NSString *SKDocumentErrorDomain = @"SKDocumentErrorDomain";
 
 NSString *SKDocumentWillSaveNotification = @"SKDocumentWillSaveNotification";
@@ -169,23 +174,31 @@
 }
 
 - (BOOL)prepareSavePanel:(NSSavePanel *)savePanel {
-    NSPopUpButton *formatPopup = popUpButtonSubview([savePanel accessoryView]);
-    NSString *lastExportedType = [[NSUserDefaults standardUserDefaults] 
stringForKey:@"SKLastExportedType"];
-    if ([[self pdfDocument] allowsPrinting] == NO) {
-        int index = [formatPopup 
indexOfItemWithRepresentedObject:SKEmbeddedPDFDocumentType];
-        if (index != -1)
-            [formatPopup removeItemAtIndex:index];
-    }
-    if (formatPopup && lastExportedType) {
-        int index = [formatPopup 
indexOfItemWithRepresentedObject:lastExportedType];
-        if (index != -1 && index != [formatPopup indexOfSelectedItem]) {
-            [formatPopup selectItemAtIndex:index];
-            [formatPopup sendAction:[formatPopup action] to:[formatPopup 
target]];
+    if (currentSaveOperation == NSSaveToOperation) {
+        NSPopUpButton *formatPopup = popUpButtonSubview([savePanel 
accessoryView]);
+        NSString *lastExportedType = [[NSUserDefaults standardUserDefaults] 
stringForKey:@"SKLastExportedType"];
+        if ([[self pdfDocument] allowsPrinting] == NO) {
+            int index = [formatPopup 
indexOfItemWithRepresentedObject:SKEmbeddedPDFDocumentType];
+            if (index != -1)
+                [formatPopup removeItemAtIndex:index];
         }
+        if (formatPopup && lastExportedType) {
+            int index = [formatPopup 
indexOfItemWithRepresentedObject:lastExportedType];
+            if (index != -1 && index != [formatPopup indexOfSelectedItem]) {
+                [formatPopup selectItemAtIndex:index];
+                [formatPopup sendAction:[formatPopup action] to:[formatPopup 
target]];
+            }
+        }
     }
     return YES;
 }
 
+- (void)runModalSavePanelForSaveOperation:(NSSaveOperationType)saveOperation 
delegate:(id)delegate didSaveSelector:(SEL)didSaveSelector contextInfo:(void 
*)contextInfo {
+    // Override so we can determine if this is a save, saveAs or export 
operation, so we can prepare the correct accessory view
+    currentSaveOperation = saveOperation;
+    [super runModalSavePanelForSaveOperation:saveOperation delegate:delegate 
didSaveSelector:didSaveSelector contextInfo:contextInfo];
+}
+
 - (BOOL)saveToURL:(NSURL *)absoluteURL ofType:(NSString *)typeName 
forSaveOperation:(NSSaveOperationType)saveOperation error:(NSError **)outError{
     if (saveOperation == NSSaveOperation || saveOperation == 
NSSaveAsOperation) {
         [self stopCheckingFileUpdates];
@@ -254,6 +267,20 @@
         // notes are only saved as a dry-run to test if we can write, they are 
not copied to the final destination. 
         didWrite = [pdfData writeToURL:absoluteURL options:NSAtomicWrite 
error:outError] &&
                    [self saveNotesToExtendedAttributesAtURL:absoluteURL 
error:outError];
+    } else if ([typeName isEqualToString:SKPDFBundleDocumentType]) {
+        NSData *notesData = [[self notes] count] ? [NSKeyedArchiver 
archivedDataWithRootObject:[[self notes] valueForKey:@"dictionaryValue"]] : nil;
+        NSData *notesTextData = [[self notesString] 
dataUsingEncoding:NSUTF8StringEncoding];
+        NSData *notesRTFData = [self notesRTFData];
+        NSFileWrapper *fileWrapper = [[NSFileWrapper alloc] 
initDirectoryWithFileWrappers:[NSDictionary dictionary]];
+        [fileWrapper addRegularFileWithContents:pdfData 
preferredFilename:WRAPPER_PDF_FILENAME];
+        if (notesData)
+            [fileWrapper addRegularFileWithContents:notesData 
preferredFilename:WRAPPER_SKIM_FILENAME];
+        if (notesTextData)
+            [fileWrapper addRegularFileWithContents:notesTextData 
preferredFilename:WRAPPER_TXT_FILENAME];
+        if (notesRTFData)
+            [fileWrapper addRegularFileWithContents:notesRTFData 
preferredFilename:WRAPPER_RTF_FILENAME];
+        didWrite = [fileWrapper writeToFile:[absoluteURL path] atomically:YES 
updateFilenames:NO];
+        [fileWrapper release];
     } else if ([typeName isEqualToString:SKEmbeddedPDFDocumentType]) {
         [[self mainWindowController] removeTemporaryAnnotations];
         didWrite = [[[self mainWindowController] pdfDocument] 
writeToURL:absoluteURL];
@@ -305,7 +332,7 @@
     NSMutableDictionary *dict = [[[super 
fileAttributesToWriteToURL:absoluteURL ofType:typeName 
forSaveOperation:saveOperation originalContentsURL:absoluteOriginalContentsURL 
error:outError] mutableCopy] autorelease];
     
     // only set the creator code for our native types
-    if ([typeName isEqualToString:SKPDFDocumentType] || [typeName 
isEqualToString:SKEmbeddedPDFDocumentType] || [typeName 
isEqualToString:SKBarePDFDocumentType] || [typeName 
isEqualToString:SKNotesDocumentType])
+    if ([typeName isEqualToString:SKPDFDocumentType] || [typeName 
isEqualToString:SKPDFBundleDocumentType] || [typeName 
isEqualToString:SKEmbeddedPDFDocumentType] || [typeName 
isEqualToString:SKBarePDFDocumentType] || [typeName 
isEqualToString:SKNotesDocumentType])
         [dict setObject:[NSNumber numberWithUnsignedLong:'SKIM'] 
forKey:NSFileHFSCreatorCode];
     
     if ([[[absoluteURL path] pathExtension] isEqualToString:@"pdf"] || 
([typeName isEqualToString:SKPDFDocumentType] || [typeName 
isEqualToString:SKEmbeddedPDFDocumentType] || [typeName 
isEqualToString:SKBarePDFDocumentType]))
@@ -411,6 +438,29 @@
                 }
             }
         }
+    } else if ([docType isEqualToString:SKPDFBundleDocumentType]) {
+        NSFileWrapper *fileWrapper = [[NSFileWrapper alloc] 
initWithPath:[absoluteURL path]];
+        NSDictionary *fileWrappers = [fileWrapper fileWrappers];
+        NSData *notesData = nil;
+        NSEnumerator *nameEnum = [fileWrappers keyEnumerator];
+        NSString *name;
+        
+        while (name = [nameEnum nextObject]) {
+            NSFileWrapper *fw = [fileWrappers objectForKey:name];
+            if ([fw isRegularFile] == NO)
+                continue;
+            NSString *extension = [[fw filename] pathExtension];
+            if ([name caseInsensitiveCompare:WRAPPER_PDF_FILENAME] == 
NSOrderedSame || (data == nil && [extension caseInsensitiveCompare:@"pdf"] == 
NSOrderedSame)) {
+                if (data = [[fw regularFileContents] retain])
+                    pdfDoc = [[PDFDocument alloc] initWithData:data];
+            } else if ([name caseInsensitiveCompare:WRAPPER_SKIM_FILENAME] == 
NSOrderedSame || (notesData == nil && [extension 
caseInsensitiveCompare:@"skim"] == NSOrderedSame)) {
+                notesData = [fw regularFileContents];
+                NSArray *array = [NSKeyedUnarchiver 
unarchiveObjectWithData:notesData];
+                if (array)
+                    [self setNoteDicts:array];
+            }
+        }
+        [fileWrapper release];
     } else if ([docType isEqualToString:SKPostScriptDocumentType]) {
         if (data = [NSData dataWithContentsOfURL:absoluteURL options:0 
error:&error]) {
             SKPSProgressController *progressController = 
[[SKPSProgressController alloc] init];

Modified: trunk/SKDocumentController.h
===================================================================
--- trunk/SKDocumentController.h        2007-08-28 09:24:37 UTC (rev 2739)
+++ trunk/SKDocumentController.h        2007-08-28 11:43:08 UTC (rev 2740)
@@ -39,6 +39,7 @@
 #import <Cocoa/Cocoa.h>
 
 extern NSString *SKPDFDocumentType;
+extern NSString *SKPDFBundleDocumentType;
 extern NSString *SKEmbeddedPDFDocumentType;
 extern NSString *SKBarePDFDocumentType;
 extern NSString *SKNotesDocumentType;

Modified: trunk/SKDocumentController.m
===================================================================
--- trunk/SKDocumentController.m        2007-08-28 09:24:37 UTC (rev 2739)
+++ trunk/SKDocumentController.m        2007-08-28 11:43:08 UTC (rev 2740)
@@ -45,6 +45,7 @@
 
 // See CFBundleTypeName in Info.plist
 NSString *SKPDFDocumentType = nil; /* set to NSPDFPboardType, not 
@"NSPDFPboardType" */
+NSString *SKPDFBundleDocumentType = @"PDF Bundle";
 NSString *SKEmbeddedPDFDocumentType = @"PDF With Embedded Notes";
 NSString *SKBarePDFDocumentType = @"PDF Without Notes";
 NSString *SKNotesDocumentType = @"Skim Notes";

Modified: trunk/Skim.xcodeproj/project.pbxproj
===================================================================
--- trunk/Skim.xcodeproj/project.pbxproj        2007-08-28 09:24:37 UTC (rev 
2739)
+++ trunk/Skim.xcodeproj/project.pbxproj        2007-08-28 11:43:08 UTC (rev 
2740)
@@ -140,6 +140,7 @@
                CE7469180B7F40B700CBF969 /* Skim.icns in Resources */ = {isa = 
PBXBuildFile; fileRef = CE7469170B7F40B600CBF969 /* Skim.icns */; };
                CE7C20500C259A5D0059E08C /* NSColor_SKExtensions.m in Sources 
*/ = {isa = PBXBuildFile; fileRef = CE7C204E0C259A5D0059E08C /* 
NSColor_SKExtensions.m */; };
                CE7C5D190BD8086C0011315D /* ToolbarLineNote.tiff in Resources 
*/ = {isa = PBXBuildFile; fileRef = CE7C5D180BD8086C0011315D /* 
ToolbarLineNote.tiff */; };
+               CE898F060C843A8B008A0856 /* PDFDDocument.icns in Resources */ = 
{isa = PBXBuildFile; fileRef = CE898F050C843A8B008A0856 /* PDFDDocument.icns 
*/; };
                CE8B46E90C29CA00005CE7F1 /* SKLineInspector.m in Sources */ = 
{isa = PBXBuildFile; fileRef = CE8B46E70C29CA00005CE7F1 /* SKLineInspector.m 
*/; };
                CE8B46F00C29CA3D005CE7F1 /* LineInspector.nib in Resources */ = 
{isa = PBXBuildFile; fileRef = CE8B46EA0C29CA3D005CE7F1 /* LineInspector.nib 
*/; };
                CE9A87930C0C9E9A004F1F97 /* ProgressSheet.nib in Resources */ = 
{isa = PBXBuildFile; fileRef = CE9A878D0C0C9E9A004F1F97 /* ProgressSheet.nib 
*/; };
@@ -507,6 +508,7 @@
                CE7C204E0C259A5D0059E08C /* NSColor_SKExtensions.m */ = {isa = 
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path 
= NSColor_SKExtensions.m; sourceTree = "<group>"; };
                CE7C5D180BD8086C0011315D /* ToolbarLineNote.tiff */ = {isa = 
PBXFileReference; lastKnownFileType = image.tiff; name = ToolbarLineNote.tiff; 
path = Images/ToolbarLineNote.tiff; sourceTree = "<group>"; };
                CE87EF690BA9FF5A0027BBDD /* skimhelp.css */ = {isa = 
PBXFileReference; explicitFileType = text; fileEncoding = 30; name = 
skimhelp.css; path = "English.lproj/Skim Help/sty/skimhelp.css"; sourceTree = 
"<group>"; };
+               CE898F050C843A8B008A0856 /* PDFDDocument.icns */ = {isa = 
PBXFileReference; lastKnownFileType = image.icns; name = PDFDDocument.icns; 
path = Images/PDFDDocument.icns; sourceTree = "<group>"; };
                CE8B46E60C29CA00005CE7F1 /* SKLineInspector.h */ = {isa = 
PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = 
SKLineInspector.h; sourceTree = "<group>"; };
                CE8B46E70C29CA00005CE7F1 /* SKLineInspector.m */ = {isa = 
PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; 
path = SKLineInspector.m; sourceTree = "<group>"; };
                CE8B46EB0C29CA3D005CE7F1 /* English */ = {isa = 
PBXFileReference; lastKnownFileType = wrapper.nib; name = English; path = 
English.lproj/LineInspector.nib; sourceTree = "<group>"; };
@@ -1013,6 +1015,7 @@
                        children = (
                                CE7469170B7F40B600CBF969 /* Skim.icns */,
                                CE07158A0B8A3D6300733CC8 /* PDFDocument.icns */,
+                               CE898F050C843A8B008A0856 /* PDFDDocument.icns 
*/,
                                CE4373B30BB5440E00A56987 /* PSDocument.icns */,
                                CE4D88D70C3AE52F002C20CB /* DVIDocument.icns */,
                                CEAA56D20C6DEE83006BD633 /* Cancel.tiff */,
@@ -1272,6 +1275,7 @@
                                CEAA56D50C6DEE83006BD633 /* Delete.tiff in 
Resources */,
                                CEAA68EB0C71242F006BD633 /* Resume.tiff in 
Resources */,
                                CEF84C630C78A89A00A3AD51 /* 
SmallPreferences.tiff in Resources */,
+                               CE898F060C843A8B008A0856 /* PDFDDocument.icns 
in Resources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };


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