Revision: 7765
          http://skim-app.svn.sourceforge.net/skim-app/?rev=7765&view=rev
Author:   hofman
Date:     2012-11-01 17:39:12 +0000 (Thu, 01 Nov 2012)
Log Message:
-----------
Replace more path based code by URL based code

Modified Paths:
--------------
    trunk/NSDocument_SKExtensions.m
    trunk/NSFileManager_SKExtensions.h
    trunk/NSFileManager_SKExtensions.m
    trunk/SKApplicationController.m
    trunk/SKMainDocument.m
    trunk/SKScriptMenu.m
    trunk/SKTemplateManager.h
    trunk/SKTemplateManager.m

Modified: trunk/NSDocument_SKExtensions.m
===================================================================
--- trunk/NSDocument_SKExtensions.m     2012-11-01 16:59:00 UTC (rev 7764)
+++ trunk/NSDocument_SKExtensions.m     2012-11-01 17:39:12 UTC (rev 7765)
@@ -143,9 +143,9 @@
 - (NSString *)notesStringForTemplateType:(NSString *)typeName {
     NSString *string = nil;
     if ([[SKTemplateManager sharedManager] isRichTextTemplateType:typeName] == 
NO) {
-        NSString *templatePath = [[SKTemplateManager sharedManager] 
pathForTemplateType:typeName];
+        NSURL *templateURL = [[SKTemplateManager sharedManager] 
URLForTemplateType:typeName];
         NSError *error = nil;
-        NSString *templateString = [[NSString alloc] 
initWithContentsOfFile:templatePath encoding:NSUTF8StringEncoding error:&error];
+        NSString *templateString = [[NSString alloc] 
initWithContentsOfURL:templateURL encoding:NSUTF8StringEncoding error:&error];
         string = [SKTemplateParser 
stringByParsingTemplateString:templateString usingObject:self];
         [templateString release];
     }
@@ -155,10 +155,10 @@
 - (NSData *)notesDataForTemplateType:(NSString *)typeName {
     NSData *data = nil;
     if ([[SKTemplateManager sharedManager] isRichTextTemplateType:typeName]) {
-        NSString *templatePath = [[SKTemplateManager sharedManager] 
pathForTemplateType:typeName];
+        NSURL *templateURL = [[SKTemplateManager sharedManager] 
URLForTemplateType:typeName];
         NSDictionary *docAttributes = nil;
         NSError *error = nil;
-        NSAttributedString *templateAttrString = [[NSAttributedString alloc] 
initWithPath:templatePath documentAttributes:&docAttributes];
+        NSAttributedString *templateAttrString = [[NSAttributedString alloc] 
initWithURL:templateURL documentAttributes:&docAttributes];
         NSAttributedString *attrString = [SKTemplateParser 
attributedStringByParsingTemplateAttributedString:templateAttrString 
usingObject:self];
         if ([[NSUserDefaults standardUserDefaults] 
boolForKey:SKDisableExportAttributesKey] == NO) {
             NSMutableDictionary *mutableAttributes = [[docAttributes 
mutableCopy] autorelease];
@@ -176,9 +176,9 @@
 - (NSFileWrapper *)notesFileWrapperForTemplateType:(NSString *)typeName {
     NSFileWrapper *fileWrapper = nil;
     if ([[SKTemplateManager sharedManager] 
isRichTextBundleTemplateType:typeName]) {
-        NSString *templatePath = [[SKTemplateManager sharedManager] 
pathForTemplateType:typeName];
+        NSURL *templateURL = [[SKTemplateManager sharedManager] 
URLForTemplateType:typeName];
         NSDictionary *docAttributes = nil;
-        NSAttributedString *templateAttrString = [[NSAttributedString alloc] 
initWithPath:templatePath documentAttributes:&docAttributes];
+        NSAttributedString *templateAttrString = [[NSAttributedString alloc] 
initWithURL:templateURL documentAttributes:&docAttributes];
         NSAttributedString *attrString = [SKTemplateParser 
attributedStringByParsingTemplateAttributedString:templateAttrString 
usingObject:self];
         if ([[NSUserDefaults standardUserDefaults] 
boolForKey:SKDisableExportAttributesKey] == NO) {
             NSMutableDictionary *mutableAttributes = [[docAttributes 
mutableCopy] autorelease];

Modified: trunk/NSFileManager_SKExtensions.h
===================================================================
--- trunk/NSFileManager_SKExtensions.h  2012-11-01 16:59:00 UTC (rev 7764)
+++ trunk/NSFileManager_SKExtensions.h  2012-11-01 17:39:12 UTC (rev 7765)
@@ -43,7 +43,7 @@
 
 - (BOOL)isTrashedFileAtURL:(NSURL *)aURL;
 
-- (NSArray *)applicationSupportDirectories;
+- (NSArray *)applicationSupportDirectoryURLs;
 
 @end
 

Modified: trunk/NSFileManager_SKExtensions.m
===================================================================
--- trunk/NSFileManager_SKExtensions.m  2012-11-01 16:59:00 UTC (rev 7764)
+++ trunk/NSFileManager_SKExtensions.m  2012-11-01 17:39:12 UTC (rev 7765)
@@ -53,16 +53,16 @@
     return result;
 }
 
-- (NSArray *)applicationSupportDirectories {
-    static NSArray *applicationSupportDirectories = nil;
-    if (applicationSupportDirectories == nil) {
-        NSMutableArray *pathArray = [NSMutableArray array];
+- (NSArray *)applicationSupportDirectoryURLs {
+    static NSArray *applicationSupportDirectoryURLs = nil;
+    if (applicationSupportDirectoryURLs == nil) {
+        NSMutableArray *urlArray = [NSMutableArray array];
         NSString *appName = [[NSBundle mainBundle] 
objectForInfoDictionaryKey:(NSString *)kCFBundleNameKey];
-        for (NSString *path in 
NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, 
NSAllDomainsMask, YES))
-            [pathArray addObject:[path 
stringByAppendingPathComponent:appName]];
-        applicationSupportDirectories = [pathArray copy];
+        for (NSURL *url in [[NSFileManager defaultManager] 
URLsForDirectory:NSApplicationSupportDirectory inDomains:NSAllDomainsMask])
+            [urlArray addObject:[url URLByAppendingPathComponent:appName]];
+        applicationSupportDirectoryURLs = [urlArray copy];
     }
-    return applicationSupportDirectories;
+    return applicationSupportDirectoryURLs;
 }
 
 @end

Modified: trunk/SKApplicationController.m
===================================================================
--- trunk/SKApplicationController.m     2012-11-01 16:59:00 UTC (rev 7764)
+++ trunk/SKApplicationController.m     2012-11-01 17:39:12 UTC (rev 7765)
@@ -120,9 +120,9 @@
     // set them in the standard user defaults
     [[NSUserDefaults standardUserDefaults] registerDefaults:initialValuesDict];
     
-    NSArray *downloadDirs = 
NSSearchPathForDirectoriesInDomains(NSDownloadsDirectory, NSUserDomainMask, 
YES);
-    if ([downloadDirs count] > 0)
-        [[NSUserDefaults standardUserDefaults] registerDefaults:[NSDictionary 
dictionaryWithObject:[[downloadDirs objectAtIndex:0] 
stringByAbbreviatingWithTildeInPath] forKey:SKDownloadsDirectoryKey]];
+    NSURL *downloadsURL = [[NSFileManager defaultManager] 
URLForDirectory:NSDownloadsDirectory inDomain:NSUserDomainMask 
appropriateForURL:nil create:YES error:NULL];
+    if (downloadsURL)
+        [[NSUserDefaults standardUserDefaults] registerDefaults:[NSDictionary 
dictionaryWithObject:[[downloadsURL path] stringByAbbreviatingWithTildeInPath] 
forKey:SKDownloadsDirectoryKey]];
     
     // if your application supports resetting a subset of the defaults to 
     // factory values, you should set those values 

Modified: trunk/SKMainDocument.m
===================================================================
--- trunk/SKMainDocument.m      2012-11-01 16:59:00 UTC (rev 7764)
+++ trunk/SKMainDocument.m      2012-11-01 17:39:12 UTC (rev 7765)
@@ -1449,7 +1449,7 @@
                     [searchPaths insertObject:[appBundle sharedSupportPath] 
atIndex:0];
                 }
             } else {
-                [searchPaths addObjectsFromArray:[[NSFileManager 
defaultManager] applicationSupportDirectories]];
+                [searchPaths addObjectsFromArray:[[[NSFileManager 
defaultManager] applicationSupportDirectoryURLs] valueForKey:@"path"]];
             }
             
             for (path in searchPaths) {

Modified: trunk/SKScriptMenu.m
===================================================================
--- trunk/SKScriptMenu.m        2012-11-01 16:59:00 UTC (rev 7764)
+++ trunk/SKScriptMenu.m        2012-11-01 17:39:12 UTC (rev 7765)
@@ -59,7 +59,7 @@
 + (id)sharedController;
 
 - (void)handleApplicationWillTerminateNotification:(NSNotification 
*)notification;
-- (NSArray *)directoryContentsAtPath:(NSString *)path 
recursionDepth:(NSInteger)depth;
+- (NSArray *)directoryContentsAtURL:(NSURL *)url 
recursionDepth:(NSInteger)depth;
 - (void)executeScript:(id)sender;
 
 @end
@@ -90,10 +90,10 @@
         NSMutableArray *folders = [NSMutableArray array];
         BOOL isDir;
         
-        for (NSString *folder in [fm applicationSupportDirectories]) {
-            folder = [folder 
stringByAppendingPathComponent:SCRIPTS_FOLDER_NAME];
-            if ([fm fileExistsAtPath:folder isDirectory:&isDir] && isDir)
-                [folders addObject:folder];
+        for (NSURL *folderURL in [fm applicationSupportDirectoryURLs]) {
+            folderURL = [folderURL 
URLByAppendingPathComponent:SCRIPTS_FOLDER_NAME];
+            if ([fm fileExistsAtPath:[folderURL path] isDirectory:&isDir] && 
isDir)
+                [folders addObject:folderURL];
         }
         
         if (itemIndex > 0 && [folders count]) {
@@ -111,7 +111,7 @@
             streamRef = FSEventStreamCreate(kCFAllocatorDefault,
                                             
(FSEventStreamCallback)&fsevents_callback, // callback
                                             NULL, // context
-                                            (CFArrayRef)scriptFolders, // 
pathsToWatch
+                                            (CFArrayRef)[scriptFolders 
valueForKey:@"path"], // pathsToWatch
                                             kFSEventStreamEventIdSinceNow, // 
sinceWhen
                                             1.0, // latency
                                             
kFSEventStreamCreateFlagWatchRoot); // flags
@@ -161,8 +161,8 @@
 - (void)menuNeedsUpdate:(NSMenu *)menu {
     if (menuNeedsUpdate) {
         NSMutableArray *scripts = [NSMutableArray array];
-        for (NSString *folder in scriptFolders)
-            [scripts addObjectsFromArray:[self directoryContentsAtPath:folder 
recursionDepth:0]];
+        for (NSURL *folderURL in scriptFolders)
+            [scripts addObjectsFromArray:[self 
directoryContentsAtURL:folderURL recursionDepth:0]];
         [scripts sortUsingDescriptors:sortDescriptors];
         
         [self updateSubmenu:menu withScripts:scripts];
@@ -200,22 +200,23 @@
     return [[NSWorkspace sharedWorkspace] type:theUTI 
conformsToType:(id)kUTTypeFolder];
 }
 
-- (NSArray *)directoryContentsAtPath:(NSString *)path 
recursionDepth:(NSInteger)depth {
+- (NSArray *)directoryContentsAtURL:(NSURL *)url 
recursionDepth:(NSInteger)depth {
     NSMutableArray *files = [NSMutableArray array];
     NSFileManager *fm = [NSFileManager defaultManager];
     NSWorkspace *ws = [NSWorkspace sharedWorkspace];
+    NSArray *keys = [NSArray arrayWithObjects:NSURLIsDirectoryKey, nil];
     
-    for (NSString *file in [fm contentsOfDirectoryAtPath:path error:NULL]) {
-        if ([file hasPrefix:@"."]) continue;
-        
-        NSString *filePath = [path stringByAppendingPathComponent:file];
-        NSDictionary *fileAttributes = [fm attributesOfItemAtPath:filePath 
error:NULL];
-        NSString *fileType = [fileAttributes valueForKey:NSFileType];
-        BOOL isDir = [fileType isEqualToString:NSFileTypeDirectory];
-        NSString *theUTI = [ws typeOfFile:[[filePath 
stringByStandardizingPath] stringByResolvingSymlinksInPath] error:NULL];
+    for (NSURL *fileURL in [fm contentsOfDirectoryAtURL:url 
includingPropertiesForKeys:keys options:NSDirectoryEnumerationSkipsHiddenFiles 
error:NULL]) {
+        NSNumber *isDirNumber = nil;
+        BOOL isDir;
+        NSString *theUTI = [ws typeOfFile:[[[fileURL URLByStandardizingPath] 
URLByResolvingSymlinksInPath] path] error:NULL];
+        NSString *filePath = [fileURL path];
         NSString *title = [[NSFileManager defaultManager] 
displayNameAtPath:filePath];
         NSDictionary *dict = nil;
         
+        [fileURL getResourceValue:&isDirNumber forKey:NSURLIsDirectoryKey 
error:NULL];
+        isDir = [isDirNumber boolValue];
+        
         NSScanner *scanner = [NSScanner scannerWithString:title];
         [scanner setCharactersToBeSkipped:nil];
         if ([scanner scanCharactersFromSet:[NSCharacterSet 
decimalDigitCharacterSet] intoString:NULL] && [scanner scanString:@"-" 
intoString:NULL])
@@ -231,7 +232,7 @@
                 title = [title stringByDeletingPathExtension];
             dict = [[NSDictionary alloc] initWithObjectsAndKeys:filePath, 
FILENAME_KEY, title, TITLE_KEY, nil];
         } else if (isDir && isFolderUTI(theUTI) && depth < 3) {
-            NSArray *content = [self directoryContentsAtPath:filePath 
recursionDepth:depth + 1];
+            NSArray *content = [self directoryContentsAtURL:fileURL 
recursionDepth:depth + 1];
             if ([content count] > 0)
                 dict = [[NSDictionary alloc] initWithObjectsAndKeys:filePath, 
FILENAME_KEY, title, TITLE_KEY, content, CONTENT_KEY, nil];
         }

Modified: trunk/SKTemplateManager.h
===================================================================
--- trunk/SKTemplateManager.h   2012-11-01 16:59:00 UTC (rev 7764)
+++ trunk/SKTemplateManager.h   2012-11-01 17:39:12 UTC (rev 7765)
@@ -48,7 +48,7 @@
 - (NSArray *)customTemplateTypes;
 - (void)resetCustomTemplateTypes;
 
-- (NSString *)pathForTemplateType:(NSString *)typeName;
+- (NSURL *)URLForTemplateType:(NSString *)typeName;
 
 - (NSString *)fileNameExtensionForTemplateType:(NSString *)typeName;
 - (NSString *)displayNameForTemplateType:(NSString *)typeName;

Modified: trunk/SKTemplateManager.m
===================================================================
--- trunk/SKTemplateManager.m   2012-11-01 16:59:00 UTC (rev 7764)
+++ trunk/SKTemplateManager.m   2012-11-01 17:39:12 UTC (rev 7765)
@@ -62,13 +62,13 @@
         NSFileManager *fm = [NSFileManager defaultManager];
         NSMutableArray *templates = [NSMutableArray array];
         
-        for (NSString *appSupportPath in [[NSFileManager defaultManager] 
applicationSupportDirectories]) {
-            NSString *templatesPath = [appSupportPath 
stringByAppendingPathComponent:TEMPLATES_DIRECTORY];
+        for (NSURL *appSupportURL in [[NSFileManager defaultManager] 
applicationSupportDirectoryURLs]) {
+            NSURL *templatesURL = [appSupportURL 
URLByAppendingPathComponent:TEMPLATES_DIRECTORY];
             BOOL isDir;
-            if ([fm fileExistsAtPath:templatesPath isDirectory:&isDir] && 
isDir) {
-                for (NSString *file in [fm 
contentsOfDirectoryAtPath:templatesPath error:NULL]) {
-                    if ([file hasPrefix:@"."] == NO &&
-                        [[file stringByDeletingPathExtension] 
isEqualToString:@"notesTemplate"] == NO &&
+            if ([fm fileExistsAtPath:[templatesURL path] isDirectory:&isDir] 
&& isDir) {
+                for (NSURL *url in [fm contentsOfDirectoryAtURL:templatesURL 
includingPropertiesForKeys:nil options:NSDirectoryEnumerationSkipsHiddenFiles 
error:NULL]) {
+                    NSString *file = [url lastPathComponent];
+                    if ([[file stringByDeletingPathExtension] 
isEqualToString:@"notesTemplate"] == NO &&
                         [templates containsObject:file] == NO)
                         [templates addObject:file];
                 }
@@ -84,18 +84,18 @@
     SKDESTROY(customTemplateTypes);
 }
 
-- (NSString *)pathForTemplateType:(NSString *)typeName {
+- (NSURL *)URLForTemplateType:(NSString *)typeName {
     NSFileManager *fm = [NSFileManager defaultManager];
-    NSString *fullPath = nil;
+    NSURL *url = nil;
     
-    for (NSString *appSupportPath in [[fm applicationSupportDirectories] 
arrayByAddingObject:[[NSBundle mainBundle] sharedSupportPath]]) {
-        fullPath = [[appSupportPath 
stringByAppendingPathComponent:TEMPLATES_DIRECTORY] 
stringByAppendingPathComponent:typeName];
-        if ([fm fileExistsAtPath:fullPath] == NO)
-            fullPath = nil;
+    for (NSURL *appSupportURL in [[fm applicationSupportDirectoryURLs] 
arrayByAddingObject:[[NSBundle mainBundle] sharedSupportPath]]) {
+        url = [[appSupportURL URLByAppendingPathComponent:TEMPLATES_DIRECTORY] 
URLByAppendingPathComponent:typeName];
+        if ([fm fileExistsAtPath:[url path]] == NO)
+            url = nil;
         else break;
     }
     
-    return fullPath;
+    return url;
 }
 
 - (NSString *)fileNameExtensionForTemplateType:(NSString *)typeName {

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_sfd2d_oct
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to