Revision: 7435
http://skim-app.svn.sourceforge.net/skim-app/?rev=7435&view=rev
Author: hofman
Date: 2011-08-19 17:54:14 +0000 (Fri, 19 Aug 2011)
Log Message:
-----------
move some template file methods to document controller class
Modified Paths:
--------------
trunk/NSDocument_SKExtensions.h
trunk/NSDocument_SKExtensions.m
trunk/SKDocumentController.h
trunk/SKDocumentController.m
trunk/SKFormatCommand.m
Modified: trunk/NSDocument_SKExtensions.h
===================================================================
--- trunk/NSDocument_SKExtensions.h 2011-08-19 10:10:53 UTC (rev 7434)
+++ trunk/NSDocument_SKExtensions.h 2011-08-19 17:54:14 UTC (rev 7435)
@@ -84,9 +84,6 @@
- (NSData *)notesFDFDataForFile:(NSString *)filename fileIDStrings:(NSArray
*)fileIDStrings;
-+ (BOOL)isRichTextTemplate:(NSString *)templateFile;
-+ (NSString *)pathForTemplateFile:(NSString *)filename;
-
#pragma mark Scripting
- (NSArray *)pages;
Modified: trunk/NSDocument_SKExtensions.m
===================================================================
--- trunk/NSDocument_SKExtensions.m 2011-08-19 10:10:53 UTC (rev 7434)
+++ trunk/NSDocument_SKExtensions.m 2011-08-19 17:54:14 UTC (rev 7435)
@@ -136,27 +136,6 @@
- (NSArray *)notes { return nil; }
-+ (BOOL)isRichTextTemplate:(NSString *)templateFile {
- static NSSet *types = nil;
- if (types == nil)
- types = [[NSSet alloc] initWithObjects:@"rtf", @"doc", @"docx",
@"odt", @"webarchive", @"rtfd", nil];
- 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;
@@ -164,8 +143,8 @@
- (NSString *)notesStringUsingTemplateFile:(NSString *)templateFile {
NSString *string = nil;
- if ([[self class] isRichTextTemplate:templateFile] == NO) {
- NSString *templatePath = [[self class]
pathForTemplateFile:templateFile];
+ if ([[NSDocumentController sharedDocumentController]
isRichTextTemplateFile:templateFile] == NO) {
+ NSString *templatePath = [[NSDocumentController
sharedDocumentController] pathForTemplateFile:templateFile];
NSError *error = nil;
NSString *templateString = [[NSString alloc]
initWithContentsOfFile:templatePath encoding:NSUTF8StringEncoding error:&error];
string = [SKTemplateParser
stringByParsingTemplateString:templateString usingObject:self];
@@ -176,8 +155,8 @@
- (NSData *)notesDataUsingTemplateFile:(NSString *)templateFile {
NSData *data = nil;
- if ([[self class] isRichTextTemplate:templateFile]) {
- NSString *templatePath = [[self class]
pathForTemplateFile:templateFile];
+ if ([[NSDocumentController sharedDocumentController]
isRichTextTemplateFile:templateFile]) {
+ NSString *templatePath = [[NSDocumentController
sharedDocumentController] pathForTemplateFile:templateFile];
NSDictionary *docAttributes = nil;
NSError *error = nil;
NSAttributedString *templateAttrString = [[NSAttributedString alloc]
initWithPath:templatePath documentAttributes:&docAttributes];
@@ -198,7 +177,7 @@
- (NSFileWrapper *)notesFileWrapperUsingTemplateFile:(NSString *)templateFile {
NSFileWrapper *fileWrapper = nil;
if ([[templateFile pathExtension] isCaseInsensitiveEqual:@"rtfd"]) {
- NSString *templatePath = [[self class]
pathForTemplateFile:templateFile];
+ NSString *templatePath = [[NSDocumentController
sharedDocumentController] pathForTemplateFile:templateFile];
NSDictionary *docAttributes = nil;
NSAttributedString *templateAttrString = [[NSAttributedString alloc]
initWithPath:templatePath documentAttributes:&docAttributes];
NSAttributedString *attrString = [SKTemplateParser
attributedStringByParsingTemplateAttributedString:templateAttrString
usingObject:self];
Modified: trunk/SKDocumentController.h
===================================================================
--- trunk/SKDocumentController.h 2011-08-19 10:10:53 UTC (rev 7434)
+++ trunk/SKDocumentController.h 2011-08-19 17:54:14 UTC (rev 7435)
@@ -81,4 +81,7 @@
- (NSArray *)customExportTemplateFiles;
- (NSArray *)customExportTemplateFilesResetting;
+- (BOOL)isRichTextTemplateFile:(NSString *)templateFile;
+- (NSString *)pathForTemplateFile:(NSString *)filename;
+
@end
Modified: trunk/SKDocumentController.m
===================================================================
--- trunk/SKDocumentController.m 2011-08-19 10:10:53 UTC (rev 7434)
+++ trunk/SKDocumentController.m 2011-08-19 17:54:14 UTC (rev 7435)
@@ -54,6 +54,8 @@
#define SKIM_NOTES_KEY @"net_sourceforge_skim-app_notes"
+#define TEMPLATES_DIRECTORY @"Templates"
+
// See CFBundleTypeName in Info.plist
NSString *SKPDFDocumentType = nil;
NSString *SKPDFBundleDocumentType = @"PDF Bundle";
@@ -424,7 +426,7 @@
NSMutableArray *templateFiles = [NSMutableArray array];
for (NSString *appSupportPath in [[NSFileManager defaultManager]
applicationSupportDirectories]) {
- NSString *templatesPath = [appSupportPath
stringByAppendingPathComponent:@"Templates"];
+ NSString *templatesPath = [appSupportPath
stringByAppendingPathComponent:TEMPLATES_DIRECTORY];
BOOL isDir;
if ([fm fileExistsAtPath:templatesPath isDirectory:&isDir] &&
isDir) {
for (NSString *file in [fm subpathsAtPath:templatesPath]) {
@@ -444,6 +446,27 @@
return [self customExportTemplateFiles];
}
+- (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_DIRECTORY]
stringByAppendingPathComponent:filename];
+ if ([fm fileExistsAtPath:fullPath] == NO)
+ fullPath = nil;
+ else break;
+ }
+
+ return fullPath;
+}
+
+- (BOOL)isRichTextTemplateFile:(NSString *)templateFile {
+ static NSSet *types = nil;
+ if (types == nil)
+ types = [[NSSet alloc] initWithObjects:@"rtf", @"doc", @"docx",
@"odt", @"webarchive", @"rtfd", nil];
+ return [types containsObject:[[templateFile pathExtension]
lowercaseString]];
+}
+
- (NSArray *)fileExtensionsFromType:(NSString *)documentTypeName {
NSArray *fileExtensions = [super fileExtensionsFromType:documentTypeName];
if ([fileExtensions count] == 0 && [[self customExportTemplateFiles]
containsObject:documentTypeName])
Modified: trunk/SKFormatCommand.m
===================================================================
--- trunk/SKFormatCommand.m 2011-08-19 10:10:53 UTC (rev 7434)
+++ trunk/SKFormatCommand.m 2011-08-19 17:54:14 UTC (rev 7435)
@@ -39,7 +39,7 @@
#import "SKFormatCommand.h"
#import "SKTemplateParser.h"
#import "SKRichTextFormat.h"
-#import "NSDocument_SKExtensions.h"
+#import "SKDocumentController.h"
@implementation SKFormatCommand
@@ -62,7 +62,7 @@
attrString = template;
else if ([template isKindOfClass:[NSURL class]] == NO)
[self setScriptErrorNumber:NSArgumentsWrongScriptError];
- else if ([NSDocument isRichTextTemplate:[template path]])
+ else if ([[NSDocumentController sharedDocumentController]
isRichTextTemplateFile:[template path]])
attrString = [[[NSAttributedString alloc] initWithURL:template
documentAttributes:&docAttrs] autorelease];
else
string = [NSString stringWithContentsOfURL:template
encoding:NSUTF8StringEncoding error:NULL];
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