Revision: 5946
          http://skim-app.svn.sourceforge.net/skim-app/?rev=5946&view=rev
Author:   hofman
Date:     2009-10-24 17:49:06 +0000 (Sat, 24 Oct 2009)

Log Message:
-----------
use separate static functions to cache rich text types

Modified Paths:
--------------
    trunk/NSDocument_SKExtensions.m

Modified: trunk/NSDocument_SKExtensions.m
===================================================================
--- trunk/NSDocument_SKExtensions.m     2009-10-24 12:51:41 UTC (rev 5945)
+++ trunk/NSDocument_SKExtensions.m     2009-10-24 17:49:06 UTC (rev 5946)
@@ -45,15 +45,17 @@
 
 @implementation NSDocument (SKExtensions)
 
-static NSSet *richTextTypes = nil;
-static NSSet *supportedRichTextTypes = nil;
-
-- (NSString *)notesStringUsingTemplateFile:(NSString *)templateFile {
+static NSSet *richTextTypes() {
+    static NSSet *richTextTypes = nil;
     if (richTextTypes == nil)
         richTextTypes = [[NSSet alloc] initWithObjects:@"rtf", @"doc", 
@"docx", @"odt", @"rtfd", nil];
+    return richTextTypes;
+}
+
+- (NSString *)notesStringUsingTemplateFile:(NSString *)templateFile {
     NSString *fileType = [[templateFile pathExtension] lowercaseString];
     NSString *string = nil;
-    if ([richTextTypes containsObject:fileType] == NO) {
+    if ([richTextTypes() containsObject:fileType] == NO) {
         NSString *templatePath = [[NSFileManager defaultManager] 
pathForApplicationSupportFile:[templateFile stringByDeletingPathExtension] 
ofType:[templateFile pathExtension] inDirectory:@"Templates"];
         NSError *error = nil;
         NSString *templateString = [[NSString alloc] 
initWithContentsOfFile:templatePath encoding:NSUTF8StringEncoding error:&error];
@@ -64,13 +66,9 @@
 }
 
 - (NSData *)notesDataUsingTemplateFile:(NSString *)templateFile {
-    if (richTextTypes == nil)
-        richTextTypes = [[NSSet alloc] initWithObjects:@"rtf", @"doc", 
@"docx", @"odt", @"rtfd", nil];
-    if (supportedRichTextTypes == nil)
-        supportedRichTextTypes = [[NSSet alloc] initWithObjects:@"rtf", 
@"doc", @"docx", @"odt", nil];
     NSString *fileType = [[templateFile pathExtension] lowercaseString];
     NSData *data = nil;
-    if ([supportedRichTextTypes containsObject:fileType]) {
+    if ([richTextTypes() containsObject:fileType]) {
         NSString *templatePath = [[NSFileManager defaultManager] 
pathForApplicationSupportFile:[templateFile stringByDeletingPathExtension] 
ofType:[templateFile pathExtension] inDirectory:@"Templates"];
         NSDictionary *docAttributes = nil;
         NSError *error = nil;
@@ -78,7 +76,7 @@
         NSAttributedString *attrString = [SKTemplateParser 
attributedStringByParsingTemplateAttributedString:templateAttrString 
usingObject:self];
         data = [attrString dataFromRange:NSMakeRange(0, [attrString length]) 
documentAttributes:docAttributes error:&error];
         [templateAttrString release];
-    } else if ([richTextTypes containsObject:fileType] == NO) {
+    } else {
         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.

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to