Revision: 7433
http://skim-app.svn.sourceforge.net/skim-app/?rev=7433&view=rev
Author: hofman
Date: 2011-08-18 16:46:29 +0000 (Thu, 18 Aug 2011)
Log Message:
-----------
method to get template file rather than generic methods to get app support files
Modified Paths:
--------------
trunk/NSDocument_SKExtensions.m
trunk/NSFileManager_SKExtensions.h
trunk/NSFileManager_SKExtensions.m
Modified: trunk/NSDocument_SKExtensions.m
===================================================================
--- trunk/NSDocument_SKExtensions.m 2011-08-15 09:01:48 UTC (rev 7432)
+++ trunk/NSDocument_SKExtensions.m 2011-08-18 16:46:29 UTC (rev 7433)
@@ -53,8 +53,6 @@
#define SKDisableExportAttributesKey @"SKDisableExportAttributes"
-#define TEMPLATES_FOLDER_NAME @"Templates"
-
NSString *SKDocumentFileURLDidChangeNotification =
@"SKDocumentFileURLDidChangeNotification";
@implementation NSDocument (SKExtensions)
@@ -145,6 +143,20 @@
return [types containsObject:[[templateFile pathExtension]
lowercaseString]];
}
+- (NSString *)pathForTemplateFile:(NSString *)filename {
+ NSFileManager *fm = [NSFileManager defaultManager];
+ NSString *fullPath = nil;
+
+ for (NSString *appSupportPath in [[fm applicationSupportDirectories]
arrayByAddingObject:[[NSBundle mainBundle] sharedSupportPath]]) {
+ fullPath = [[appSupportPath
stringByAppendingPathComponent:@"Templates"]
stringByAppendingPathComponent:filename];
+ if ([fm fileExistsAtPath:fullPath] == NO)
+ fullPath = nil;
+ else break;
+ }
+
+ return fullPath;
+}
+
- (NSData *)notesData {
NSArray *array = [[self notes] valueForKey:@"SkimNoteProperties"];
return array ? [NSKeyedArchiver archivedDataWithRootObject:array] : nil;
@@ -153,7 +165,7 @@
- (NSString *)notesStringUsingTemplateFile:(NSString *)templateFile {
NSString *string = nil;
if (isRichTextType(templateFile) == NO) {
- NSString *templatePath = [[NSFileManager defaultManager]
pathForApplicationSupportFile:[templateFile stringByDeletingPathExtension]
ofType:[templateFile pathExtension] inDirectory:TEMPLATES_FOLDER_NAME];
+ NSString *templatePath = [self pathForTemplateFile:templateFile];
NSError *error = nil;
NSString *templateString = [[NSString alloc]
initWithContentsOfFile:templatePath encoding:NSUTF8StringEncoding error:&error];
string = [SKTemplateParser
stringByParsingTemplateString:templateString usingObject:self];
@@ -165,7 +177,7 @@
- (NSData *)notesDataUsingTemplateFile:(NSString *)templateFile {
NSData *data = nil;
if (isRichTextType(templateFile)) {
- NSString *templatePath = [[NSFileManager defaultManager]
pathForApplicationSupportFile:[templateFile stringByDeletingPathExtension]
ofType:[templateFile pathExtension] inDirectory:TEMPLATES_FOLDER_NAME];
+ NSString *templatePath = [self pathForTemplateFile:templateFile];
NSDictionary *docAttributes = nil;
NSError *error = nil;
NSAttributedString *templateAttrString = [[NSAttributedString alloc]
initWithPath:templatePath documentAttributes:&docAttributes];
@@ -186,7 +198,7 @@
- (NSFileWrapper *)notesFileWrapperUsingTemplateFile:(NSString *)templateFile {
NSFileWrapper *fileWrapper = nil;
if ([[templateFile pathExtension] isCaseInsensitiveEqual:@"rtfd"]) {
- NSString *templatePath = [[NSFileManager defaultManager]
pathForApplicationSupportFile:[templateFile stringByDeletingPathExtension]
ofType:[templateFile pathExtension] inDirectory:TEMPLATES_FOLDER_NAME];
+ NSString *templatePath = [self pathForTemplateFile:templateFile];
NSDictionary *docAttributes = nil;
NSAttributedString *templateAttrString = [[NSAttributedString alloc]
initWithPath:templatePath documentAttributes:&docAttributes];
NSAttributedString *attrString = [SKTemplateParser
attributedStringByParsingTemplateAttributedString:templateAttrString
usingObject:self];
Modified: trunk/NSFileManager_SKExtensions.h
===================================================================
--- trunk/NSFileManager_SKExtensions.h 2011-08-15 09:01:48 UTC (rev 7432)
+++ trunk/NSFileManager_SKExtensions.h 2011-08-18 16:46:29 UTC (rev 7433)
@@ -44,8 +44,6 @@
- (BOOL)isTrashedFileAtURL:(NSURL *)aURL;
- (NSArray *)applicationSupportDirectories;
-- (NSString *)pathForApplicationSupportFile:(NSString *)file ofType:(NSString
*)extension;
-- (NSString *)pathForApplicationSupportFile:(NSString *)file ofType:(NSString
*)extension inDirectory:(NSString *)subpath;
@end
Modified: trunk/NSFileManager_SKExtensions.m
===================================================================
--- trunk/NSFileManager_SKExtensions.m 2011-08-15 09:01:48 UTC (rev 7432)
+++ trunk/NSFileManager_SKExtensions.m 2011-08-18 16:46:29 UTC (rev 7433)
@@ -65,26 +65,6 @@
return applicationSupportDirectories;
}
-- (NSString *)pathForApplicationSupportFile:(NSString *)file ofType:(NSString
*)extension {
- return [self pathForApplicationSupportFile:file ofType:extension
inDirectory:nil];
-}
-
-- (NSString *)pathForApplicationSupportFile:(NSString *)file ofType:(NSString
*)extension inDirectory:(NSString *)subpath {
- NSFileManager *fm = [NSFileManager defaultManager];
- NSString *filename = [file stringByAppendingPathExtension:extension];
- NSString *fullPath = nil;
-
- for (NSString *appSupportPath in [[self applicationSupportDirectories]
arrayByAddingObject:[[NSBundle mainBundle] sharedSupportPath]]) {
- fullPath = subpath ? [appSupportPath
stringByAppendingPathComponent:subpath] : appSupportPath;
- fullPath = [fullPath stringByAppendingPathComponent:filename];
- if ([fm fileExistsAtPath:fullPath] == NO)
- fullPath = nil;
- else break;
- }
-
- return fullPath;
-}
-
@end
static NSString *SKUniqueDirectory(NSString *basePath) {
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Get a FREE DOWNLOAD! and learn more about uberSVN rich system,
user administration capabilities and model configuration. Take
the hassle out of deploying and managing Subversion and the
tools developers use with it. http://p.sf.net/sfu/wandisco-d2d-2
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit