Revision: 6908
http://skim-app.svn.sourceforge.net/skim-app/?rev=6908&view=rev
Author: hofman
Date: 2010-11-28 13:27:58 +0000 (Sun, 28 Nov 2010)
Log Message:
-----------
separate method for PDF bundle file wrapper
Modified Paths:
--------------
trunk/SKMainDocument.m
Modified: trunk/SKMainDocument.m
===================================================================
--- trunk/SKMainDocument.m 2010-11-28 13:17:18 UTC (rev 6907)
+++ trunk/SKMainDocument.m 2010-11-28 13:27:58 UTC (rev 6908)
@@ -496,6 +496,35 @@
[super saveToURL:absoluteURL ofType:typeName
forSaveOperation:saveOperation delegate:self
didSaveSelector:@selector(document:didSave:contextInfo:) contextInfo:info];
}
+- (NSFileWrapper *)PDFBundleFileWrapperForName:(NSString *)name {
+ if ([name caseInsensitiveCompare:BUNDLE_DATA_FILENAME] == NSOrderedSame)
+ name = [name stringByAppendingString:@"1"];
+ NSData *data;
+ NSFileWrapper *fileWrapper = [[NSFileWrapper alloc]
initDirectoryWithFileWrappers:[NSDictionary dictionary]];
+ NSDictionary *info = [[SKInfoWindowController sharedInstance]
infoForDocument:self];
+ NSDictionary *options = [[self mainWindowController] presentationOptions];
+ if (options) {
+ info = [[info mutableCopy] autorelease];
+ [(NSMutableDictionary *)info setObject:options
forKey:SKPresentationOptionsKey];
+ }
+ [fileWrapper addRegularFileWithContents:pdfData preferredFilename:[name
stringByAppendingPathExtension:@"pdf"]];
+ if (data = [[[self pdfDocument] string]
dataUsingEncoding:NSUTF8StringEncoding])
+ [fileWrapper addRegularFileWithContents:data
preferredFilename:[BUNDLE_DATA_FILENAME stringByAppendingPathExtension:@"txt"]];
+ if (data = [NSPropertyListSerialization dataFromPropertyList:info
format:NSPropertyListXMLFormat_v1_0 errorDescription:NULL])
+ [fileWrapper addRegularFileWithContents:data
preferredFilename:[BUNDLE_DATA_FILENAME
stringByAppendingPathExtension:@"plist"]];
+ if ([[self notes] count] > 0) {
+ if (data = [self notesData])
+ [fileWrapper addRegularFileWithContents:data
preferredFilename:[name stringByAppendingPathExtension:@"skim"]];
+ if (data = [[self notesString] dataUsingEncoding:NSUTF8StringEncoding])
+ [fileWrapper addRegularFileWithContents:data
preferredFilename:[name stringByAppendingPathExtension:@"txt"]];
+ if (data = [self notesRTFData])
+ [fileWrapper addRegularFileWithContents:data
preferredFilename:[name stringByAppendingPathExtension:@"rtf"]];
+ if (data = [self notesFDFDataForFile:[name
stringByAppendingPathExtension:@"pdf"] fileIDStrings:[self fileIDStrings]])
+ [fileWrapper addRegularFileWithContents:data
preferredFilename:[name stringByAppendingPathExtension:@"fdf"]];
+ }
+ return [fileWrapper autorelease];
+}
+
- (BOOL)writeToURL:(NSURL *)absoluteURL ofType:(NSString *)typeName
error:(NSError **)outError{
BOOL didWrite = NO;
NSError *error = nil;
@@ -515,34 +544,11 @@
if ([[self fileType] isEqualToString:SKXDVDocumentType])
didWrite = [psOrDviData writeToURL:absoluteURL options:0
error:&error];
} else if ([typeName isEqualToString:SKPDFBundleDocumentType]) {
- NSString *name = [[[absoluteURL path] lastPathComponent]
stringByDeletingPathExtension];
- if ([name caseInsensitiveCompare:BUNDLE_DATA_FILENAME] ==
NSOrderedSame)
- name = [name stringByAppendingString:@"1"];
- NSData *data;
- NSFileWrapper *fileWrapper = [[NSFileWrapper alloc]
initDirectoryWithFileWrappers:[NSDictionary dictionary]];
- NSDictionary *info = [[SKInfoWindowController sharedInstance]
infoForDocument:self];
- NSDictionary *options = [[self mainWindowController]
presentationOptions];
- if (options) {
- info = [[info mutableCopy] autorelease];
- [(NSMutableDictionary *)info setObject:options
forKey:SKPresentationOptionsKey];
- }
- [fileWrapper addRegularFileWithContents:pdfData
preferredFilename:[name stringByAppendingPathExtension:@"pdf"]];
- if (data = [[[self pdfDocument] string]
dataUsingEncoding:NSUTF8StringEncoding])
- [fileWrapper addRegularFileWithContents:data
preferredFilename:[BUNDLE_DATA_FILENAME stringByAppendingPathExtension:@"txt"]];
- if (data = [NSPropertyListSerialization dataFromPropertyList:info
format:NSPropertyListXMLFormat_v1_0 errorDescription:NULL])
- [fileWrapper addRegularFileWithContents:data
preferredFilename:[BUNDLE_DATA_FILENAME
stringByAppendingPathExtension:@"plist"]];
- if ([[self notes] count] > 0) {
- if (data = [self notesData])
- [fileWrapper addRegularFileWithContents:data
preferredFilename:[name stringByAppendingPathExtension:@"skim"]];
- if (data = [[self notesString]
dataUsingEncoding:NSUTF8StringEncoding])
- [fileWrapper addRegularFileWithContents:data
preferredFilename:[name stringByAppendingPathExtension:@"txt"]];
- if (data = [self notesRTFData])
- [fileWrapper addRegularFileWithContents:data
preferredFilename:[name stringByAppendingPathExtension:@"rtf"]];
- if (data = [self notesFDFDataForFile:[name
stringByAppendingPathExtension:@"pdf"] fileIDStrings:[self fileIDStrings]])
- [fileWrapper addRegularFileWithContents:data
preferredFilename:[name stringByAppendingPathExtension:@"fdf"]];
- }
- didWrite = [fileWrapper writeToFile:[absoluteURL path] atomically:NO
updateFilenames:NO];
- [fileWrapper release];
+ NSFileWrapper *fileWrapper = [self
PDFBundleFileWrapperForName:[[[absoluteURL path] lastPathComponent]
stringByDeletingPathExtension]];
+ if (fileWrapper)
+ didWrite = [fileWrapper writeToFile:[absoluteURL path]
atomically:NO updateFilenames:NO];
+ else
+ error = [NSError errorWithDomain:SKDocumentErrorDomain
code:SKWriteFileError userInfo:[NSDictionary
dictionaryWithObjectsAndKeys:NSLocalizedString(@"Unable to write file", @"Error
description"), NSLocalizedDescriptionKey, nil]];
} else if ([typeName isEqualToString:SKNotesDocumentType]) {
didWrite = [[NSFileManager defaultManager] writeSkimNotes:[[self
notes] valueForKey:@"SkimNoteProperties"] toSkimFileAtURL:absoluteURL
error:&error];
} else if ([typeName isEqualToString:SKNotesRTFDocumentType]) {
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Increase Visibility of Your 3D Game App & Earn a Chance To Win $500!
Tap into the largest installed PC base & get more eyes on your game by
optimizing for Intel(R) Graphics Technology. Get started today with the
Intel(R) Software Partner Program. Five $500 cash prizes are up for grabs.
http://p.sf.net/sfu/intelisp-dev2dev
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit