Revision: 5109
http://skim-app.svn.sourceforge.net/skim-app/?rev=5109&view=rev
Author: hofman
Date: 2009-01-07 13:18:10 +0000 (Wed, 07 Jan 2009)
Log Message:
-----------
check file type for plain text template string
Modified Paths:
--------------
trunk/NSDocument_SKExtensions.m
Modified: trunk/NSDocument_SKExtensions.m
===================================================================
--- trunk/NSDocument_SKExtensions.m 2009-01-06 17:20:39 UTC (rev 5108)
+++ trunk/NSDocument_SKExtensions.m 2009-01-07 13:18:10 UTC (rev 5109)
@@ -44,26 +44,36 @@
@implementation NSDocument (SKExtensions)
+static NSSet *richTextTypes = nil;
+static NSSet *supportedRichTextTypes = nil;
+
- (NSString *)notesStringUsingTemplateFile:(NSString *)templateFile {
- NSString *templatePath = [[SKApplicationController
sharedApplicationController] pathForApplicationSupportFile:[templateFile
stringByDeletingPathExtension] ofType:[templateFile pathExtension]
inDirectory:@"Templates"];
- NSError *error = nil;
- NSString *templateString = [[NSString alloc]
initWithContentsOfFile:templatePath encoding:NSUTF8StringEncoding error:&error];
- NSString *string = [SKTemplateParser
stringByParsingTemplateString:templateString usingObject:self];
- [templateString release];
+ if (richTextTypes == nil)
+ richTextTypes = [[NSSet alloc] initWithObjects:@"rtf", @"doc",
@"docx", @"odt", @"rtfd", nil];
+ NSString *fileType = [[templateFile pathExtension] lowercaseString];
+ NSString *string = nil;
+ if ([richTextTypes containsObject:fileType] == NO) {
+ NSString *templatePath = [[SKApplicationController
sharedApplicationController] pathForApplicationSupportFile:[templateFile
stringByDeletingPathExtension] ofType:[templateFile pathExtension]
inDirectory:@"Templates"];
+ NSError *error = nil;
+ NSString *templateString = [[NSString alloc]
initWithContentsOfFile:templatePath encoding:NSUTF8StringEncoding error:&error];
+ string = [SKTemplateParser
stringByParsingTemplateString:templateString usingObject:self];
+ [templateString release];
+ }
return string;
}
- (NSData *)notesDataUsingTemplateFile:(NSString *)templateFile {
- static NSSet *richTextTypes = nil;
- if (richTextTypes == nil) {
+ if (richTextTypes == nil)
+ richTextTypes = [[NSSet alloc] initWithObjects:@"rtf", @"doc",
@"docx", @"odt", @"rtfd", nil];
+ if (supportedRichTextTypes == nil) {
if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_4)
- richTextTypes = [[NSSet alloc] initWithObjects:@"rtf", @"doc",
@"docx", @"odt", nil];
+ supportedRichTextTypes = [[NSSet alloc] initWithObjects:@"rtf",
@"doc", @"docx", @"odt", nil];
else
- richTextTypes = [[NSSet alloc] initWithObjects:@"rtf", @"doc",
nil];
+ supportedRichTextTypes = [[NSSet alloc] initWithObjects:@"rtf",
@"doc", nil];
}
NSString *fileType = [[templateFile pathExtension] lowercaseString];
NSData *data = nil;
- if ([richTextTypes containsObject:fileType]) {
+ if ([supportedRichTextTypes containsObject:fileType]) {
NSString *templatePath = [[SKApplicationController
sharedApplicationController] pathForApplicationSupportFile:[templateFile
stringByDeletingPathExtension] ofType:[templateFile pathExtension]
inDirectory:@"Templates"];
NSDictionary *docAttributes = nil;
NSError *error = nil;
@@ -71,7 +81,7 @@
NSAttributedString *attrString = [SKTemplateParser
attributedStringByParsingTemplateAttributedString:templateAttrString
usingObject:self];
data = [attrString dataFromRange:NSMakeRange(0, [attrString length])
documentAttributes:docAttributes error:&error];
[templateAttrString release];
- } else if ([fileType caseInsensitiveCompare:@"rtfd"] != NSOrderedSame &&
[fileType caseInsensitiveCompare:@"docx"] != NSOrderedSame && [fileType
caseInsensitiveCompare:@"odt"] != NSOrderedSame) {
+ } else if ([richTextTypes containsObject:fileType] == NO) {
data = [[self notesStringUsingTemplateFile:templateFile]
dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:NO];
}
return data;
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It is the best place to buy or sell services for
just about anything Open Source.
http://p.sf.net/sfu/Xq1LFB
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit