Revision: 3912
http://skim-app.svn.sourceforge.net/skim-app/?rev=3912&view=rev
Author: hofman
Date: 2008-05-23 10:42:13 -0700 (Fri, 23 May 2008)
Log Message:
-----------
Consolidate some code for getting data using a template.
Modified Paths:
--------------
trunk/SKDocumentController.m
trunk/SKNotesDocument.h
trunk/SKNotesDocument.m
trunk/SKPDFDocument.h
trunk/SKPDFDocument.m
trunk/Skim.xcodeproj/project.pbxproj
Added Paths:
-----------
trunk/NSDocument_SKExtensions.h
trunk/NSDocument_SKExtensions.m
Added: trunk/NSDocument_SKExtensions.h
===================================================================
--- trunk/NSDocument_SKExtensions.h (rev 0)
+++ trunk/NSDocument_SKExtensions.h 2008-05-23 17:42:13 UTC (rev 3912)
@@ -0,0 +1,55 @@
+//
+// NSDocument_SKExtensions.h
+// Skim
+//
+// Created by Christiaan Hofman on 5/23/08.
+/*
+ This software is Copyright (c) 2008
+ Christiaan Hofman. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ - Neither the name of Christiaan Hofman nor the names of any
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import <Cocoa/Cocoa.h>
+
+extern NSString *SKDocumentErrorDomain;
+
[EMAIL PROTECTED] NSDocument (SKExtensions)
+
+- (NSString *)notesStringUsingTemplateFile:(NSString *)templateFile;
+- (NSData *)notesDataUsingTemplateFile:(NSString *)templateFile;
+- (NSFileWrapper *)notesFileWrapperUsingTemplateFile:(NSString *)templateFile;
+
+- (NSString *)notesString;
+- (NSData *)notesRTFData;
+- (NSFileWrapper *)notesRTFDFileWrapper;
+
+- (void)saveRecentDocumentInfo;
+
[EMAIL PROTECTED]
Added: trunk/NSDocument_SKExtensions.m
===================================================================
--- trunk/NSDocument_SKExtensions.m (rev 0)
+++ trunk/NSDocument_SKExtensions.m 2008-05-23 17:42:13 UTC (rev 3912)
@@ -0,0 +1,104 @@
+//
+// NSDocument_SKExtensions.m
+// Skim
+//
+// Created by Christiaan Hofman on 5/23/08.
+/*
+ This software is Copyright (c) 2008
+ Christiaan Hofman. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ - Neither the name of Christiaan Hofman nor the names of any
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "NSDocument_SKExtensions.h"
+#import "SKApplicationController.h"
+#import "SKTemplateParser.h"
+
+NSString *SKDocumentErrorDomain = @"SKDocumentErrorDomain";
+
[EMAIL PROTECTED] NSDocument (SKExtensions)
+
+- (NSString *)notesStringUsingTemplateFile:(NSString *)templateFile {
+ NSString *templatePath = [[NSApp delegate]
pathForApplicationSupportFile:[templateFile stringByDeletingPathExtension]
ofType:[templateFile pathExtension] inDirectory:@"Templates"];
+ NSError *error = nil;
+ NSString *templateString = [[NSString alloc]
initWithContentsOfFile:templatePath encoding:NSUTF8StringEncoding error:&error];
+ NSString *string = [SKTemplateParser
stringByParsingTemplate:templateString usingObject:self];
+ [templateString release];
+ return string;
+}
+
+- (NSData *)notesDataUsingTemplateFile:(NSString *)templateFile {
+ static NSSet *richTextTypes = nil;
+ if (richTextTypes == nil) {
+ if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_4)
+ richTextTypes = [[NSSet alloc] initWithObjects:@"rtf", @"doc",
@"odt", nil];
+ else
+ richTextTypes = [[NSSet alloc] initWithObjects:@"rtf", @"doc",
nil];
+ }
+ NSString *templatePath = [[NSApp delegate]
pathForApplicationSupportFile:[templateFile stringByDeletingPathExtension]
ofType:[templateFile pathExtension] inDirectory:@"Templates"];
+ NSString *fileType = [[templatePath pathExtension] lowercaseString];
+ NSData *data = nil;
+ if ([richTextTypes containsObject:fileType]) {
+ NSDictionary *docAttributes = nil;
+ NSError *error = nil;
+ NSAttributedString *templateAttrString = [[NSAttributedString alloc]
initWithPath:templatePath documentAttributes:&docAttributes];
+ NSAttributedString *attrString = [SKTemplateParser
attributedStringByParsingTemplate:templateAttrString usingObject:self];
+ data = [attrString dataFromRange:NSMakeRange(0, [attrString length])
documentAttributes:docAttributes error:&error];
+ [templateAttrString release];
+ } else if ([fileType caseInsensitiveCompare:@"rtfd"] != NSOrderedSame &&
[fileType caseInsensitiveCompare:@"odt"] != NSOrderedSame) {
+ data = [[self notesStringUsingTemplateFile:templatePath]
dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:NO];
+ }
+ return data;
+}
+
+- (NSFileWrapper *)notesFileWrapperUsingTemplateFile:(NSString *)templateFile {
+ NSString *templatePath = [[NSApp delegate]
pathForApplicationSupportFile:[templateFile stringByDeletingPathExtension]
ofType:[templateFile pathExtension] inDirectory:@"Templates"];
+ NSDictionary *docAttributes = nil;
+ NSAttributedString *templateAttrString = [[NSAttributedString alloc]
initWithPath:templatePath documentAttributes:&docAttributes];
+ NSAttributedString *attrString = [SKTemplateParser
attributedStringByParsingTemplate:templateAttrString usingObject:self];
+ NSFileWrapper *fileWrapper = [attrString
RTFDFileWrapperFromRange:NSMakeRange(0, [attrString length])
documentAttributes:docAttributes];
+ [templateAttrString release];
+ return fileWrapper;
+}
+
+- (NSString *)notesString {
+ return [self notesStringUsingTemplateFile:@"notesTemplate.txt"];
+}
+
+- (NSData *)notesRTFData {
+ return [self notesDataUsingTemplateFile:@"notesTemplate.rtf"];
+}
+
+- (NSFileWrapper *)notesRTFDFileWrapper {
+ return [self notesFileWrapperUsingTemplateFile:@"notesTemplate.rtfd"];
+}
+
+- (void)saveRecentDocumentInfo {}
+
[EMAIL PROTECTED]
Modified: trunk/SKDocumentController.m
===================================================================
--- trunk/SKDocumentController.m 2008-05-23 15:25:51 UTC (rev 3911)
+++ trunk/SKDocumentController.m 2008-05-23 17:42:13 UTC (rev 3912)
@@ -37,6 +37,7 @@
*/
#import "SKDocumentController.h"
+#import "NSDocument_SKExtensions.h"
#import "SKPDFDocument.h"
#import "SKDownloadController.h"
#import "NSString_SKExtensions.h"
@@ -365,8 +366,7 @@
- (NSArray *)customExportTemplateFiles {
if (customExportTemplateFiles == nil) {
NSFileManager *fm = [NSFileManager defaultManager];
- NSMutableSet *templateNames = [NSMutableSet
setWithObjects:@"notesTemplate.txt", @"notesTemplate.rtf",
@"notesTemplate.rtfd", nil];
- NSMutableArray *templateFiles = [NSMutableArray array];
+ NSMutableSet *templateFiles = [NSMutableSet set];
int domains[3] = {kUserDomain, kLocalDomain, kNetworkDomain};
int i;
for (i = 0; i < 3; i++) {
@@ -376,14 +376,13 @@
NSEnumerator *fileEnum = [[fm subpathsAtPath:templatesPath]
objectEnumerator];
NSString *file;
while (file = [fileEnum nextObject]) {
- if ([file hasPrefix:@"."] == NO && [templateNames
containsObject:file] == NO) {
- [templateFiles addObject:[templatesPath
stringByAppendingPathComponent:file]];
+ if ([file hasPrefix:@"."] == NO)
[templateFiles addObject:file];
- }
}
}
}
- customExportTemplateFiles = [templateFiles copy];
+ [templateFiles minusSet:[NSSet setWithObjects:@"notesTemplate.txt",
@"notesTemplate.rtf", @"notesTemplate.rtfd", nil]];
+ customExportTemplateFiles = [[[templateFiles allObjects]
sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)] copy];
}
return customExportTemplateFiles;
}
@@ -395,19 +394,15 @@
- (NSArray *)fileExtensionsFromType:(NSString *)documentTypeName {
NSArray *fileExtensions = [super fileExtensionsFromType:documentTypeName];
- if ([fileExtensions count] == 0) {
- NSArray *customTemplates = [[self customExportTemplateFiles]
valueForKey:@"lastPathComponent"];
- if ([customTemplates containsObject:documentTypeName])
- fileExtensions = [NSArray arrayWithObjects:[documentTypeName
pathExtension], nil];
- }
+ if ([fileExtensions count] == 0 && [[self customExportTemplateFiles]
containsObject:documentTypeName])
+ fileExtensions = [NSArray arrayWithObjects:[documentTypeName
pathExtension], nil];
return fileExtensions;
}
- (NSString *)displayNameForType:(NSString *)documentTypeName{
NSString *displayName = nil;
- NSArray *customTemplates = [[self customExportTemplateFiles]
valueForKey:@"lastPathComponent"];
- if ([customTemplates containsObject:documentTypeName])
- displayName = [[documentTypeName stringByDeletingPathExtension]
stringByAppendingFormat:@" (%@)", [[documentTypeName pathExtension]
uppercaseString]];
+ if ([[self customExportTemplateFiles] containsObject:documentTypeName])
+ displayName = [documentTypeName stringByDeletingPathExtension];
else
displayName = [super displayNameForType:documentTypeName];
return displayName;
Modified: trunk/SKNotesDocument.h
===================================================================
--- trunk/SKNotesDocument.h 2008-05-23 15:25:51 UTC (rev 3911)
+++ trunk/SKNotesDocument.h 2008-05-23 17:42:13 UTC (rev 3912)
@@ -56,8 +56,4 @@
- (void)insertObject:(id)obj inNotesAtIndex:(unsigned)index;
- (void)removeObjectFromNotesAtIndex:(unsigned)index;
-- (NSString *)notesString;
-- (NSData *)notesRTFData;
-- (NSData *)notesDataUsingTemplateFile:(NSString *)templatePath;
-
@end
Modified: trunk/SKNotesDocument.m
===================================================================
--- trunk/SKNotesDocument.m 2008-05-23 15:25:51 UTC (rev 3911)
+++ trunk/SKNotesDocument.m 2008-05-23 17:42:13 UTC (rev 3912)
@@ -37,7 +37,6 @@
*/
#import "SKNotesDocument.h"
-#import "SKPDFDocument.h"
#import "SKNoteOutlineView.h"
#import "BDAlias.h"
#import "SKDocumentController.h"
@@ -52,6 +51,7 @@
#import "SKFDFParser.h"
#import "SKStatusBar.h"
#import "NSWindowController_SKExtensions.h"
+#import "NSDocument_SKExtensions.h"
static NSString *SKNotesDocumentWindowFrameAutosaveName =
@"SKNotesDocumentWindow";
@@ -106,7 +106,7 @@
NSString *file;
while (file = [fileEnum nextObject]) {
if ([[file pathExtension] caseInsensitiveCompare:@"rtfd"] !=
NSOrderedSame)
- [writableTypes addObject:[file lastPathComponent]];
+ [writableTypes addObject:file];
}
}
return writableTypes;
@@ -116,9 +116,7 @@
// this will never be called on 10.4, so we can safely call super
NSString *fileExtension = [super fileNameExtensionForType:typeName
saveOperation:saveOperation];
if (fileExtension == nil) {
- [[NSDocumentController sharedDocumentController]
resetCustomExportTemplateFiles];
- NSArray *customTemplates = [[[NSDocumentController
sharedDocumentController] customExportTemplateFiles]
valueForKey:@"lastPathComponent"];
- if ([customTemplates containsObject:typeName])
+ if ([[[NSDocumentController sharedDocumentController]
customExportTemplateFiles] containsObject:typeName])
fileExtension = [typeName pathExtension];
}
return fileExtension;
@@ -144,10 +142,7 @@
} else if (SKIsNotesTextDocumentType(typeName)) {
data = [[self notesString] dataUsingEncoding:NSUTF8StringEncoding];
} else {
- NSArray *customTemplates = [[NSDocumentController
sharedDocumentController] customExportTemplateFiles];
- unsigned int idx = [[customTemplates valueForKey:@"lastPathComponent"]
indexOfObject:typeName];
- if (idx != NSNotFound)
- data = [self notesDataUsingTemplateFile:[customTemplates
objectAtIndex:idx]];
+ data = [self notesDataUsingTemplateFile:typeName];
}
if (data == nil && outError != NULL)
@@ -220,49 +215,6 @@
return dict;
}
-- (NSString *)notesString {
- NSString *templatePath = [[NSApp delegate]
pathForApplicationSupportFile:@"notesTemplate" ofType:@"txt"
inDirectory:@"Templates"];
- NSString *templateString = [[NSString alloc]
initWithContentsOfFile:templatePath encoding:NSUTF8StringEncoding error:NULL];
- NSString *string = [SKTemplateParser
stringByParsingTemplate:templateString usingObject:self];
- return string;
-}
-
-- (NSData *)notesRTFData {
- NSString *templatePath = [[NSApp delegate]
pathForApplicationSupportFile:@"notesTemplate" ofType:@"rtf"
inDirectory:@"Templates"];
- NSDictionary *docAttributes = nil;
- NSAttributedString *templateAttrString = [[NSAttributedString alloc]
initWithPath:templatePath documentAttributes:&docAttributes];
- NSAttributedString *attrString = [SKTemplateParser
attributedStringByParsingTemplate:templateAttrString usingObject:self];
- NSData *data = [attrString RTFFromRange:NSMakeRange(0, [attrString
length]) documentAttributes:docAttributes];
- [templateAttrString release];
- return data;
-}
-
-- (NSData *)notesDataUsingTemplateFile:(NSString *)templatePath {
- static NSSet *richTextTypes = nil;
- if (richTextTypes == nil) {
- if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_4)
- richTextTypes = [[NSSet alloc] initWithObjects:@"rtf", @"doc",
@"odt", nil];
- else
- richTextTypes = [[NSSet alloc] initWithObjects:@"rtf", @"doc",
nil];
- }
- NSString *fileType = [[templatePath pathExtension] lowercaseString];
- NSData *data = nil;
- if ([richTextTypes containsObject:fileType]) {
- NSDictionary *docAttributes = nil;
- NSError *error = nil;
- NSAttributedString *templateAttrString = [[NSAttributedString alloc]
initWithPath:templatePath documentAttributes:&docAttributes];
- NSAttributedString *attrString = [SKTemplateParser
attributedStringByParsingTemplate:templateAttrString usingObject:self];
- data = [attrString dataFromRange:NSMakeRange(0, [attrString length])
documentAttributes:docAttributes error:&error];
- [templateAttrString release];
- } else if ([fileType caseInsensitiveCompare:@"rtfd"] != NSOrderedSame) {
- NSError *error = nil;
- NSString *templateString = [[NSString alloc]
initWithContentsOfFile:templatePath encoding:NSUTF8StringEncoding error:&error];
- NSString *string = [SKTemplateParser
stringByParsingTemplate:templateString usingObject:self];
- data = [string dataUsingEncoding:NSUTF8StringEncoding
allowLossyConversion:NO];
- }
- return data;
-}
-
// these are necessary for the app controller, we may change it there
- (NSDictionary *)currentDocumentSetup {
NSMutableDictionary *setup = [NSMutableDictionary dictionary];
Modified: trunk/SKPDFDocument.h
===================================================================
--- trunk/SKPDFDocument.h 2008-05-23 15:25:51 UTC (rev 3911)
+++ trunk/SKPDFDocument.h 2008-05-23 17:42:13 UTC (rev 3912)
@@ -38,8 +38,6 @@
#import <Cocoa/Cocoa.h>
-extern NSString *SKDocumentErrorDomain;
-
extern NSString *SKPDFDocumentWillSaveNotification;
extern NSString *SKSkimFileDidSaveNotification;
@@ -108,15 +106,9 @@
- (SKPDFView *)pdfView;
- (NSData *)notesData;
-- (NSString *)notesString;
-- (NSData *)notesRTFData;
-- (NSFileWrapper *)notesRTFDFileWrapper;
- (NSString *)notesFDFString;
- (NSString *)notesFDFStringForFile:(NSString *)filename;
-- (NSData *)notesDataUsingTemplateFile:(NSString *)templatePath;
-- (NSFileWrapper *)notesFileWrapperUsingTemplateFile:(NSString *)templatePath;
-
- (NSArray *)fileIDStrings;
- (void)savePasswordInKeychain:(NSString *)password;
@@ -151,11 +143,6 @@
@end
[EMAIL PROTECTED] NSDocument (SKExtensions)
-- (void)saveRecentDocumentInfo;
[EMAIL PROTECTED]
-
-
@interface NSWindow (SKScriptingExtensions)
- (id)handleRevertScriptCommand:(NSScriptCommand *)command;
@end
Modified: trunk/SKPDFDocument.m
===================================================================
--- trunk/SKPDFDocument.m 2008-05-23 15:25:51 UTC (rev 3911)
+++ trunk/SKPDFDocument.m 2008-05-23 17:42:13 UTC (rev 3912)
@@ -70,11 +70,10 @@
#import "PDFPage_SKExtensions.h"
#import "NSGeometry_SKExtensions.h"
#import "SKSnapshotWindowController.h"
+#import "NSDocument_SKExtensions.h"
#define BUNDLE_DATA_FILENAME @"data"
-NSString *SKDocumentErrorDomain = @"SKDocumentErrorDomain";
-
NSString *SKPDFDocumentWillSaveNotification =
@"SKPDFDocumentWillSaveNotification";
NSString *SKSkimFileDidSaveNotification = @"SKSkimFileDidSaveNotification";
@@ -222,8 +221,7 @@
NSMutableArray *writableTypes = [[[super
writableTypesForSaveOperation:saveOperation] mutableCopy] autorelease];
if (saveOperation == NSSaveToOperation) {
[[NSDocumentController sharedDocumentController]
resetCustomExportTemplateFiles];
- NSArray *customTemplates = [[NSDocumentController
sharedDocumentController] customExportTemplateFiles];
- [writableTypes addObjectsFromArray:[customTemplates
valueForKey:@"lastPathComponent"]];
+ [writableTypes addObjectsFromArray:[[NSDocumentController
sharedDocumentController] customExportTemplateFiles]];
}
return writableTypes;
}
@@ -232,8 +230,7 @@
// this will never be called on 10.4, so we can safely call super
NSString *fileExtension = [super fileNameExtensionForType:typeName
saveOperation:saveOperation];
if (fileExtension == nil) {
- NSArray *customTemplates = [[[NSDocumentController
sharedDocumentController] customExportTemplateFiles]
valueForKey:@"lastPathComponent"];
- if ([customTemplates containsObject:typeName])
+ if ([[[NSDocumentController sharedDocumentController]
customExportTemplateFiles] containsObject:typeName])
fileExtension = [typeName pathExtension];
}
return fileExtension;
@@ -480,24 +477,18 @@
didWrite = [string writeToURL:absoluteURL atomically:YES
encoding:NSISOLatin1StringEncoding error:&error];
else
error = [NSError errorWithDomain:SKDocumentErrorDomain code:1
userInfo:[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Unable
to write notes as FDF", @"Error description"), NSLocalizedDescriptionKey, nil]];
+ } else if ([[typeName pathExtension] caseInsensitiveCompare:@"rtfd"]) {
+ NSFileWrapper *fileWrapper = [self
notesFileWrapperUsingTemplateFile:typeName];
+ if (fileWrapper)
+ didWrite = [fileWrapper writeToFile:[absoluteURL path]
atomically:NO updateFilenames:NO];
+ else
+ error = [NSError errorWithDomain:SKDocumentErrorDomain code:1
userInfo:[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Unable
to write notes using template", @"Error description"),
NSLocalizedDescriptionKey, nil]];
} else {
- NSArray *customTemplates = [[NSDocumentController
sharedDocumentController] customExportTemplateFiles];
- unsigned int idx = [[customTemplates valueForKey:@"lastPathComponent"]
indexOfObject:typeName];
- if (idx != NSNotFound) {
- if ([[typeName pathExtension] caseInsensitiveCompare:@"rtfd"]) {
- NSFileWrapper *fileWrapper = [self
notesFileWrapperUsingTemplateFile:[customTemplates objectAtIndex:idx]];
- if (fileWrapper)
- didWrite = [fileWrapper writeToFile:[absoluteURL path]
atomically:NO updateFilenames:NO];
- else
- error = [NSError errorWithDomain:SKDocumentErrorDomain
code:1 userInfo:[NSDictionary
dictionaryWithObjectsAndKeys:NSLocalizedString(@"Unable to write notes using
template", @"Error description"), NSLocalizedDescriptionKey, nil]];
- } else {
- NSData *data = [self
notesDataUsingTemplateFile:[customTemplates objectAtIndex:idx]];
- if (data)
- didWrite = [data writeToURL:absoluteURL options:0
error:&error];
- else
- error = [NSError errorWithDomain:SKDocumentErrorDomain
code:1 userInfo:[NSDictionary
dictionaryWithObjectsAndKeys:NSLocalizedString(@"Unable to write notes using
template", @"Error description"), NSLocalizedDescriptionKey, nil]];
- }
- }
+ NSData *data = [self notesDataUsingTemplateFile:typeName];
+ if (data)
+ didWrite = [data writeToURL:absoluteURL options:0 error:&error];
+ else
+ error = [NSError errorWithDomain:SKDocumentErrorDomain code:1
userInfo:[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Unable
to write notes using template", @"Error description"),
NSLocalizedDescriptionKey, nil]];
}
if (didWrite == NO && outError != NULL)
@@ -780,6 +771,56 @@
return success;
}
+#pragma mark Notes
+
+- (NSData *)notesData {
+ NSArray *array = [[self notes] valueForKey:@"properties"];
+ return array ? [NSKeyedArchiver archivedDataWithRootObject:array] : nil;
+}
+
+- (NSString *)notesFDFString {
+ NSString *filePath = [[self fileURL] path];
+ NSString *filename = [filePath lastPathComponent];
+ if (filename && SKIsPDFBundleDocumentType([self fileType])) {
+ NSString *pdfFile = [[NSFileManager defaultManager]
subfileWithExtension:@"pdf" inPDFBundleAtPath:filePath];
+ filename = pdfFile ? [filename stringByAppendingPathComponent:pdfFile]
: nil;
+ }
+ return [self notesFDFStringForFile:filename];
+}
+
+- (NSString *)notesFDFStringForFile:(NSString *)filename {
+ NSArray *fileIDStrings = [self fileIDStrings];
+ int i, count = [[self notes] count];
+ NSMutableString *string = [NSMutableString
stringWithFormat:@"%%FDF-1.2\n%%%C%C%C%C\n", 0xe2, 0xe3, 0xcf, 0xd3];
+ NSMutableString *annots = [NSMutableString string];
+ for (i = 0; i < count; i++) {
+ [string appendFormat:@"%i 0 obj<<%@>>\nendobj\n", i + 1, [[[self
notes] objectAtIndex:i] fdfString]];
+ [annots appendFormat:@"%i 0 R ", i + 1];
+ }
+ [string appendFormat:@"%i 0 obj<<", i + 1];
+ [string appendFDFName:SKFDFFDFKey];
+ [string appendString:@"<<"];
+ [string appendFDFName:SKFDFAnnotationsKey];
+ [string appendFormat:@"[EMAIL PROTECTED]", annots];
+ [string appendFDFName:SKFDFFileKey];
+ [string appendString:@"("];
+ if (filename)
+ [string appendString:[[filename lossyISOLatin1String]
stringByEscapingParenthesis]];
+ [string appendString:@")"];
+ if ([fileIDStrings count] == 2) {
+ [string appendFDFName:SKFDFFileIDKey];
+ [string appendFormat:@"[<%@><%@>]", [fileIDStrings objectAtIndex:0],
[fileIDStrings objectAtIndex:1]];
+ }
+ [string appendString:@">>"];
+ [string appendString:@">>\nendobj\n"];
+ [string appendString:@"trailer\n<<"];
+ [string appendFDFName:SKFDFRootKey];
+ [string appendFormat:@" %i 0 R", i + 1];
+ [string appendString:@">>\n"];
+ [string appendString:@"%%EOF\n"];
+ return string;
+}
+
#pragma mark Actions
- (IBAction)printDocument:(id)sender{
@@ -1516,76 +1557,6 @@
return [[self mainWindowController] pdfView];
}
-- (NSData *)notesData {
- NSArray *array = [[self notes] valueForKey:@"properties"];
- return array ? [NSKeyedArchiver archivedDataWithRootObject:array] : nil;
-}
-
-- (NSString *)notesString {
- NSString *templatePath = [[NSApp delegate]
pathForApplicationSupportFile:@"notesTemplate" ofType:@"txt"
inDirectory:@"Templates"];
- NSStringEncoding encoding = NSUTF8StringEncoding;
- NSError *error = nil;
- NSString *templateString = [[NSString alloc]
initWithContentsOfFile:templatePath encoding:encoding error:&error];
- NSString *string = [SKTemplateParser
stringByParsingTemplate:templateString usingObject:self];
- [templateString release];
- return string;
-}
-
-- (NSData *)notesRTFData {
- NSString *templatePath = [[NSApp delegate]
pathForApplicationSupportFile:@"notesTemplate" ofType:@"rtf"
inDirectory:@"Templates"];
- NSDictionary *docAttributes = nil;
- NSAttributedString *templateAttrString = [[NSAttributedString alloc]
initWithPath:templatePath documentAttributes:&docAttributes];
- NSAttributedString *attrString = [SKTemplateParser
attributedStringByParsingTemplate:templateAttrString usingObject:self];
- NSData *data = [attrString RTFFromRange:NSMakeRange(0, [attrString
length]) documentAttributes:docAttributes];
- [templateAttrString release];
- return data;
-}
-
-- (NSFileWrapper *)notesRTFDFileWrapper {
- NSString *templatePath = [[NSApp delegate]
pathForApplicationSupportFile:@"notesTemplate" ofType:@"rtfd"
inDirectory:@"Templates"];
- NSDictionary *docAttributes = nil;
- NSAttributedString *templateAttrString = [[NSAttributedString alloc]
initWithPath:templatePath documentAttributes:&docAttributes];
- NSAttributedString *attrString = [SKTemplateParser
attributedStringByParsingTemplate:templateAttrString usingObject:self];
- NSFileWrapper *fileWrapper = [attrString
RTFDFileWrapperFromRange:NSMakeRange(0, [attrString length])
documentAttributes:docAttributes];
- [templateAttrString release];
- return fileWrapper;
-}
-
-- (NSData *)notesDataUsingTemplateFile:(NSString *)templatePath {
- static NSSet *richTextTypes = nil;
- if (richTextTypes == nil) {
- if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_4)
- richTextTypes = [[NSSet alloc] initWithObjects:@"rtf", @"doc",
@"odt", nil];
- else
- richTextTypes = [[NSSet alloc] initWithObjects:@"rtf", @"doc",
nil];
- }
- NSString *fileType = [[templatePath pathExtension] lowercaseString];
- NSData *data = nil;
- if ([richTextTypes containsObject:fileType]) {
- NSDictionary *docAttributes = nil;
- NSError *error = nil;
- NSAttributedString *templateAttrString = [[NSAttributedString alloc]
initWithPath:templatePath documentAttributes:&docAttributes];
- NSAttributedString *attrString = [SKTemplateParser
attributedStringByParsingTemplate:templateAttrString usingObject:self];
- data = [attrString dataFromRange:NSMakeRange(0, [attrString length])
documentAttributes:docAttributes error:&error];
- [templateAttrString release];
- } else if ([fileType caseInsensitiveCompare:@"rtfd"] != NSOrderedSame) {
- NSError *error = nil;
- NSString *templateString = [[NSString alloc]
initWithContentsOfFile:templatePath encoding:NSUTF8StringEncoding error:&error];
- NSString *string = [SKTemplateParser
stringByParsingTemplate:templateString usingObject:self];
- data = [string dataUsingEncoding:NSUTF8StringEncoding
allowLossyConversion:NO];
- }
- return data;
-}
-
-- (NSFileWrapper *)notesFileWrapperUsingTemplateFile:(NSString *)templatePath {
- NSDictionary *docAttributes = nil;
- NSAttributedString *templateAttrString = [[NSAttributedString alloc]
initWithPath:templatePath documentAttributes:&docAttributes];
- NSAttributedString *attrString = [SKTemplateParser
attributedStringByParsingTemplate:templateAttrString usingObject:self];
- NSFileWrapper *fileWrapper = [attrString
RTFDFileWrapperFromRange:NSMakeRange(0, [attrString length])
documentAttributes:docAttributes];
- [templateAttrString release];
- return fileWrapper;
-}
-
- (NSArray *)fileIDStrings {
if (pdfData == nil)
return nil;
@@ -1659,49 +1630,6 @@
return nil;
}
-- (NSString *)notesFDFString {
- NSString *filePath = [[self fileURL] path];
- NSString *filename = [filePath lastPathComponent];
- if (filename && SKIsPDFBundleDocumentType([self fileType])) {
- NSString *pdfFile = [[NSFileManager defaultManager]
subfileWithExtension:@"pdf" inPDFBundleAtPath:filePath];
- filename = pdfFile ? [filename stringByAppendingPathComponent:pdfFile]
: nil;
- }
- return [self notesFDFStringForFile:filename];
-}
-
-- (NSString *)notesFDFStringForFile:(NSString *)filename {
- NSArray *fileIDStrings = [self fileIDStrings];
- int i, count = [[self notes] count];
- NSMutableString *string = [NSMutableString
stringWithFormat:@"%%FDF-1.2\n%%%C%C%C%C\n", 0xe2, 0xe3, 0xcf, 0xd3];
- NSMutableString *annots = [NSMutableString string];
- for (i = 0; i < count; i++) {
- [string appendFormat:@"%i 0 obj<<%@>>\nendobj\n", i + 1, [[[self
notes] objectAtIndex:i] fdfString]];
- [annots appendFormat:@"%i 0 R ", i + 1];
- }
- [string appendFormat:@"%i 0 obj<<", i + 1];
- [string appendFDFName:SKFDFFDFKey];
- [string appendString:@"<<"];
- [string appendFDFName:SKFDFAnnotationsKey];
- [string appendFormat:@"[EMAIL PROTECTED]", annots];
- [string appendFDFName:SKFDFFileKey];
- [string appendString:@"("];
- if (filename)
- [string appendString:[[filename lossyISOLatin1String]
stringByEscapingParenthesis]];
- [string appendString:@")"];
- if ([fileIDStrings count] == 2) {
- [string appendFDFName:SKFDFFileIDKey];
- [string appendFormat:@"[<%@><%@>]", [fileIDStrings objectAtIndex:0],
[fileIDStrings objectAtIndex:1]];
- }
- [string appendString:@">>"];
- [string appendString:@">>\nendobj\n"];
- [string appendString:@"trailer\n<<"];
- [string appendFDFName:SKFDFRootKey];
- [string appendFormat:@" %i 0 R", i + 1];
- [string appendString:@">>\n"];
- [string appendString:@"%%EOF\n"];
- return string;
-}
-
- (void)setPrintInfo:(NSPrintInfo *)printInfo {
if (autoRotateButton) {
BOOL autoRotate = [autoRotateButton state] == NSOnState;
@@ -2162,11 +2090,6 @@
@end
[EMAIL PROTECTED] NSDocument (SKExtensions)
-- (void)saveRecentDocumentInfo {}
[EMAIL PROTECTED]
-
-
@implementation NSFileManager (SKPDFDocumentExtensions)
- (NSString *)subfileWithExtension:(NSString *)extension
inPDFBundleAtPath:(NSString *)path {
Modified: trunk/Skim.xcodeproj/project.pbxproj
===================================================================
--- trunk/Skim.xcodeproj/project.pbxproj 2008-05-23 15:25:51 UTC (rev
3911)
+++ trunk/Skim.xcodeproj/project.pbxproj 2008-05-23 17:42:13 UTC (rev
3912)
@@ -50,6 +50,7 @@
CE0EB4D60DD054DC0034DF92 /* NSInvocation_SKExtensions.m in
Sources */ = {isa = PBXBuildFile; fileRef = CE0EB4D50DD054DC0034DF92 /*
NSInvocation_SKExtensions.m */; };
CE0ECCD90DE71868006EEDDB /* Templates in Resources */ = {isa =
PBXBuildFile; fileRef = CE0ECCD40DE71868006EEDDB /* Templates */; };
CE0ECCDA0DE7188C006EEDDB /* Templates in CopyFiles */ = {isa =
PBXBuildFile; fileRef = CE0ECCD40DE71868006EEDDB /* Templates */; };
+ CE0ECD1C0DE73604006EEDDB /* NSDocument_SKExtensions.m in
Sources */ = {isa = PBXBuildFile; fileRef = CE0ECD1B0DE73604006EEDDB /*
NSDocument_SKExtensions.m */; };
CE199DFD0D957A16009B2055 /* SKAnnotationTypeImageCell.m in
Sources */ = {isa = PBXBuildFile; fileRef = CE199DFC0D957A16009B2055 /*
SKAnnotationTypeImageCell.m */; };
CE1ADB280C4BC6DE00071840 /* OpenGL.framework in Frameworks */ =
{isa = PBXBuildFile; fileRef = CE1ADB170C4BC6DE00071840 /* OpenGL.framework */;
};
CE1ADEBF0C4C341100071840 /* SKTransitionController.m in Sources
*/ = {isa = PBXBuildFile; fileRef = CE1ADEBE0C4C341100071840 /*
SKTransitionController.m */; };
@@ -419,6 +420,8 @@
CE0EB4D40DD054DC0034DF92 /* NSInvocation_SKExtensions.h */ =
{isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h;
path = NSInvocation_SKExtensions.h; sourceTree = "<group>"; };
CE0EB4D50DD054DC0034DF92 /* NSInvocation_SKExtensions.m */ =
{isa = PBXFileReference; fileEncoding = 4; lastKnownFileType =
sourcecode.c.objc; path = NSInvocation_SKExtensions.m; sourceTree = "<group>";
};
CE0ECCD40DE71868006EEDDB /* Templates */ = {isa =
PBXFileReference; lastKnownFileType = folder; path = Templates; sourceTree =
"<group>"; };
+ CE0ECD1A0DE73604006EEDDB /* NSDocument_SKExtensions.h */ = {isa
= PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path
= NSDocument_SKExtensions.h; sourceTree = "<group>"; };
+ CE0ECD1B0DE73604006EEDDB /* NSDocument_SKExtensions.m */ = {isa
= PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc;
path = NSDocument_SKExtensions.m; sourceTree = "<group>"; };
CE199DFB0D957A16009B2055 /* SKAnnotationTypeImageCell.h */ =
{isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h;
path = SKAnnotationTypeImageCell.h; sourceTree = "<group>"; };
CE199DFC0D957A16009B2055 /* SKAnnotationTypeImageCell.m */ =
{isa = PBXFileReference; fileEncoding = 4; lastKnownFileType =
sourcecode.c.objc; path = SKAnnotationTypeImageCell.m; sourceTree = "<group>";
};
CE1ADB170C4BC6DE00071840 /* OpenGL.framework */ = {isa =
PBXFileReference; lastKnownFileType = wrapper.framework; name =
OpenGL.framework; path = /System/Library/Frameworks/OpenGL.framework;
sourceTree = "<absolute>"; };
@@ -1469,6 +1472,8 @@
CE7C204E0C259A5D0059E08C /*
NSColor_SKExtensions.m */,
CE2DE4EC0B85DB6300D0DA12 /*
NSCursor_SKExtensions.h */,
CE2DE4ED0B85DB6300D0DA12 /*
NSCursor_SKExtensions.m */,
+ CE0ECD1A0DE73604006EEDDB /*
NSDocument_SKExtensions.h */,
+ CE0ECD1B0DE73604006EEDDB /*
NSDocument_SKExtensions.m */,
CECDC4FC0C5966A80026AAEC /*
NSImage_SKExtensions.h */,
CECDC4FD0C5966A80026AAEC /*
NSImage_SKExtensions.m */,
CE070EA00B89039700733CC8 /*
NSScrollView_SKExtensions.h */,
@@ -2005,6 +2010,7 @@
CEEC0A0A0DCB2594003DD9B6 /*
SKMainWindowController_UI.m in Sources */,
CE0EB4D60DD054DC0034DF92 /*
NSInvocation_SKExtensions.m in Sources */,
CE7F43910DE1F1980061A839 /*
NSUserDefaults_SKExtensions.m in Sources */,
+ CE0ECD1C0DE73604006EEDDB /*
NSDocument_SKExtensions.m in Sources */,
);
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: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit