Revision: 7763
          http://skim-app.svn.sourceforge.net/skim-app/?rev=7763&view=rev
Author:   hofman
Date:     2012-11-01 16:06:57 +0000 (Thu, 01 Nov 2012)
Log Message:
-----------
Replace more path based code by URL based code, in particular in document 
related classes

Modified Paths:
--------------
    trunk/NSURL_SKExtensions.h
    trunk/NSURL_SKExtensions.m
    trunk/SKBookmarkController.h
    trunk/SKBookmarkController.m
    trunk/SKConversionProgressController.h
    trunk/SKConversionProgressController.m
    trunk/SKDocumentController.m
    trunk/SKMainDocument.m
    trunk/SKMainWindowController.m
    trunk/SKNotesDocument.m

Modified: trunk/NSURL_SKExtensions.h
===================================================================
--- trunk/NSURL_SKExtensions.h  2012-11-01 13:09:50 UTC (rev 7762)
+++ trunk/NSURL_SKExtensions.h  2012-11-01 16:06:57 UTC (rev 7763)
@@ -46,7 +46,7 @@
 + (BOOL)canReadFileURLFromPasteboard:(NSPasteboard *)pboard;
 + (NSArray *)readFileURLsFromPasteboard:(NSPasteboard *)pboard;
 
-- (NSString *)pathReplacingPathExtension:(NSString *)ext;
+- (NSURL *)URLReplacingPathExtension:(NSString *)ext;
 
 - (NSAttributedString *)icon;
 - (NSAttributedString *)smallIcon;

Modified: trunk/NSURL_SKExtensions.m
===================================================================
--- trunk/NSURL_SKExtensions.m  2012-11-01 13:09:50 UTC (rev 7762)
+++ trunk/NSURL_SKExtensions.m  2012-11-01 16:06:57 UTC (rev 7763)
@@ -109,8 +109,8 @@
     return fileURLs;
 }
 
-- (NSString *)pathReplacingPathExtension:(NSString *)ext {
-    return [[[self path] stringByDeletingPathExtension] 
stringByAppendingPathExtension:ext];
+- (NSURL *)URLReplacingPathExtension:(NSString *)ext {
+    return [[self URLByDeletingPathExtension] URLByAppendingPathExtension:ext];
 }
 
 - (NSAttributedString *)icon {

Modified: trunk/SKBookmarkController.h
===================================================================
--- trunk/SKBookmarkController.h        2012-11-01 13:09:50 UTC (rev 7762)
+++ trunk/SKBookmarkController.h        2012-11-01 16:06:57 UTC (rev 7763)
@@ -69,8 +69,8 @@
 - (IBAction)deleteBookmark:(id)sender;
 - (IBAction)toggleStatusBar:(id)sender;
 
-- (void)addRecentDocumentForPath:(NSString *)path 
pageIndex:(NSUInteger)pageIndex snapshots:(NSArray *)setups;
-- (NSUInteger)pageIndexForRecentDocumentAtPath:(NSString *)path;
-- (NSArray *)snapshotsForRecentDocumentAtPath:(NSString *)path;
+- (void)addRecentDocumentForURL:(NSURL *)fileURL 
pageIndex:(NSUInteger)pageIndex snapshots:(NSArray *)setups;
+- (NSUInteger)pageIndexForRecentDocumentAtURL:(NSURL *)fileURL;
+- (NSArray *)snapshotsForRecentDocumentAtURL:(NSURL *)fileURL;
 
 @end

Modified: trunk/SKBookmarkController.m
===================================================================
--- trunk/SKBookmarkController.m        2012-11-01 13:09:50 UTC (rev 7762)
+++ trunk/SKBookmarkController.m        2012-11-01 16:06:57 UTC (rev 7763)
@@ -48,6 +48,7 @@
 #import "SKSeparatorCell.h"
 #import "NSMenu_SKExtensions.h"
 #import "NSURL_SKExtensions.h"
+#import "NSString_SKExtensions.h"
 
 #define SKPasteboardTypeBookmarkRows 
@"net.sourceforge.skim-app.pasteboard.bookmarkrows"
 
@@ -218,28 +219,29 @@
 
 #pragma mark Recent Documents
 
-- (NSDictionary *)recentDocumentInfoAtPath:(NSString *)path {
+- (NSDictionary *)recentDocumentInfoAtURL:(NSURL *)fileURL {
+    NSString *path = [fileURL path];
     for (NSMutableDictionary *info in recentDocuments) {
         BDAlias *alias = [info valueForKey:ALIAS_KEY];
         if (alias == nil) {
             alias = [BDAlias aliasWithData:[info valueForKey:ALIASDATA_KEY]];
             [info setValue:alias forKey:ALIAS_KEY];
         }
-        if ([[alias fullPathNoUI] isEqualToString:path])
+        if ([[alias fullPathNoUI] isCaseInsensitiveEqual:path])
             return info;
     }
     return nil;
 }
 
-- (void)addRecentDocumentForPath:(NSString *)path 
pageIndex:(NSUInteger)pageIndex snapshots:(NSArray *)setups {
-    if (path == nil)
+- (void)addRecentDocumentForURL:(NSURL *)fileURL 
pageIndex:(NSUInteger)pageIndex snapshots:(NSArray *)setups {
+    if (fileURL == nil)
         return;
     
-    NSDictionary *info = [self recentDocumentInfoAtPath:path];
+    NSDictionary *info = [self recentDocumentInfoAtURL:fileURL];
     if (info)
         [recentDocuments removeObjectIdenticalTo:info];
     
-    BDAlias *alias = [BDAlias aliasWithPath:path];
+    BDAlias *alias = [BDAlias aliasWithURL:fileURL];
     if (alias) {
         NSMutableDictionary *bm = [NSMutableDictionary 
dictionaryWithObjectsAndKeys:[NSNumber numberWithUnsignedInteger:pageIndex], 
PAGEINDEX_KEY, [alias aliasData], ALIASDATA_KEY, alias, ALIAS_KEY, [setups 
count] ? setups : nil, SNAPSHOTS_KEY, nil];
         [recentDocuments insertObject:bm atIndex:0];
@@ -248,17 +250,17 @@
     }
 }
 
-- (NSUInteger)pageIndexForRecentDocumentAtPath:(NSString *)path {
-    if (path == nil)
+- (NSUInteger)pageIndexForRecentDocumentAtURL:(NSURL *)fileURL {
+    if (fileURL == nil)
         return NSNotFound;
-    NSDictionary *info = [self recentDocumentInfoAtPath:path];
-    return info == nil ? NSNotFound : [[info objectForKey:PAGEINDEX_KEY] 
unsignedIntegerValue];
+    NSNumber *pageIndex = [[self recentDocumentInfoAtURL:fileURL] 
objectForKey:PAGEINDEX_KEY];
+    return pageIndex == nil ? NSNotFound : [pageIndex unsignedIntegerValue];
 }
 
-- (NSArray *)snapshotsForRecentDocumentAtPath:(NSString *)path {
-    if (path == nil)
+- (NSArray *)snapshotsForRecentDocumentAtURL:(NSURL *)fileURL {
+    if (fileURL == nil)
         return nil;
-    NSArray *setups = [[self recentDocumentInfoAtPath:path] 
objectForKey:SNAPSHOTS_KEY];
+    NSArray *setups = [[self recentDocumentInfoAtURL:fileURL] 
objectForKey:SNAPSHOTS_KEY];
     return [setups count] ? setups : nil;
 }
 

Modified: trunk/SKConversionProgressController.h
===================================================================
--- trunk/SKConversionProgressController.h      2012-11-01 13:09:50 UTC (rev 
7762)
+++ trunk/SKConversionProgressController.h      2012-11-01 16:06:57 UTC (rev 
7763)
@@ -54,8 +54,8 @@
 @property (nonatomic, retain) IBOutlet NSTextField *textField;
 
 + (NSData *)newPDFDataWithPostScriptData:(NSData *)psData error:(NSError 
**)outError;
-+ (NSData *)newPDFDataWithDVIFile:(NSString *)dviFile error:(NSError 
**)outError;
-+ (NSData *)newPDFDataWithXDVFile:(NSString *)xdvFile error:(NSError 
**)outError;
++ (NSData *)newPDFDataWithDVIAtURL:(NSURL *)dviURL error:(NSError **)outError;
++ (NSData *)newPDFDataWithXDVAtURL:(NSURL *)xdvURL error:(NSError **)outError;
 
 - (IBAction)cancel:(id)sender;
 - (IBAction)close:(id)sender;

Modified: trunk/SKConversionProgressController.m
===================================================================
--- trunk/SKConversionProgressController.m      2012-11-01 13:09:50 UTC (rev 
7762)
+++ trunk/SKConversionProgressController.m      2012-11-01 16:06:57 UTC (rev 
7763)
@@ -68,7 +68,7 @@
 + (NSString *)dviToolPath;
 + (NSString *)xdvToolPath;
 - (NSData *)newPDFDataWithPostScriptData:(NSData *)psData error:(NSError 
**)outError;
-- (NSData *)newPDFDataWithDVIFile:(NSString *)dviFile toolPath:(NSString 
*)toolPath fileType:(NSString *)aFileType error:(NSError **)outError;
+- (NSData *)newPDFDataWithDVIAtURL:(NSURL *)dviURL toolPath:(NSString 
*)toolPath fileType:(NSString *)aFileType error:(NSError **)outError;
 - (void)conversionCompleted;
 - (void)conversionStarted;
 - (void)converterWasStopped;
@@ -112,19 +112,19 @@
     return [[[[self alloc] init] autorelease] 
newPDFDataWithPostScriptData:psData error:outError];
 }
 
-+ (NSData *)newPDFDataWithDVIFile:(NSString *)dviFile error:(NSError 
**)outError {
++ (NSData *)newPDFDataWithDVIAtURL:(NSURL *)dviURL error:(NSError **)outError {
     NSString *dviToolPath = [self dviToolPath];
     if (dviToolPath)
-        return [[[[self alloc] init] autorelease] 
newPDFDataWithDVIFile:dviFile toolPath:dviToolPath fileType:SKDVIDocumentType 
error:outError];
+        return [[[[self alloc] init] autorelease] 
newPDFDataWithDVIAtURL:dviURL toolPath:dviToolPath fileType:SKDVIDocumentType 
error:outError];
     else
         NSBeep();
     return nil;
 }
 
-+ (NSData *)newPDFDataWithXDVFile:(NSString *)xdvFile error:(NSError 
**)outError {
++ (NSData *)newPDFDataWithXDVAtURL:(NSURL *)xdvURL error:(NSError **)outError {
     NSString *xdvToolPath = [self xdvToolPath];
     if (xdvToolPath)
-        return [[[[self alloc] init] autorelease] 
newPDFDataWithDVIFile:xdvFile toolPath:xdvToolPath fileType:SKXDVDocumentType 
error:outError];
+        return [[[[self alloc] init] autorelease] 
newPDFDataWithDVIAtURL:xdvURL toolPath:xdvToolPath fileType:SKXDVDocumentType 
error:outError];
     else
         NSBeep();
     return nil;
@@ -378,7 +378,7 @@
     [pool release];
 }
 
-- (NSData *)newPDFDataWithDVIFile:(NSString *)dviFile toolPath:(NSString 
*)toolPath fileType:(NSString *)aFileType error:(NSError **)outError {
+- (NSData *)newPDFDataWithDVIAtURL:(NSURL *)dviURL toolPath:(NSString 
*)toolPath fileType:(NSString *)aFileType error:(NSError **)outError {
     NSAssert(NULL == converter, @"attempted to reenter 
SKConversionProgressController, but this is not supported");
     
     NSMutableData *pdfData = nil;
@@ -394,7 +394,7 @@
         NSAssert(converter != NULL, @"unable to create PS converter");
     }
     
-    NSDictionary *dictionary = [NSDictionary 
dictionaryWithObjectsAndKeys:dviFile, INPUTFILE_KEY, pdfData, PDFDATA_KEY, 
toolPath, TOOLPATH_KEY, nil];
+    NSDictionary *dictionary = [NSDictionary 
dictionaryWithObjectsAndKeys:[dviURL path], INPUTFILE_KEY, pdfData, 
PDFDATA_KEY, toolPath, TOOLPATH_KEY, nil];
     
     NSInteger rv = [self runModalSelector:@selector(doDVIConversionWithInfo:) 
withObject:dictionary];
     

Modified: trunk/SKDocumentController.m
===================================================================
--- trunk/SKDocumentController.m        2012-11-01 13:09:50 UTC (rev 7762)
+++ trunk/SKDocumentController.m        2012-11-01 16:06:57 UTC (rev 7763)
@@ -143,7 +143,7 @@
     if ([ws type:type conformsToType:SKFolderDocumentType] == NO && [self 
documentClassForType:type] == NULL) {
         // "open -f" creates a temporary file with a .txt extension, we want 
to be able to open these file as it can be very handy to e.g. display man pages 
and pretty printed text file from the command line
         if ([inAbsoluteURL isFileURL]) {
-            NSData *leadingData = [[NSFileHandle 
fileHandleForReadingAtPath:[inAbsoluteURL path]] readDataOfLength:20];
+            NSData *leadingData = [[NSFileHandle 
fileHandleForReadingFromURL:inAbsoluteURL error:NULL] readDataOfLength:20];
             if (isPDFData(leadingData))
                 type = SKPDFDocumentType;
             else if (isPostScriptData(leadingData))
@@ -153,8 +153,7 @@
             *outError = error;
     } else if ([ws type:type conformsToType:SKNotesFDFDocumentType]) {
         // Springer sometimes sends PDF files with an .fdf extension for 
review, huh?
-        NSString *fileName = [inAbsoluteURL path];
-        NSFileHandle *fh = [NSFileHandle fileHandleForReadingAtPath:fileName];
+        NSFileHandle *fh = [NSFileHandle 
fileHandleForReadingFromURL:inAbsoluteURL error:NULL];
         NSData *leadingData = [fh readDataOfLength:5];
         if (isPDFData(leadingData))
             type = SKPDFDocumentType;
@@ -344,10 +343,10 @@
     if ([ws type:type conformsToType:SKNotesDocumentType]) {
         NSAppleEventDescriptor *event = [[NSAppleEventManager 
sharedAppleEventManager] currentAppleEvent];
         if ([event eventID] == kAEOpenDocuments && [event 
descriptorForKeyword:keyAESearchText]) {
-            NSString *pdfFile = [absoluteURL 
pathReplacingPathExtension:@"pdf"];
+            NSURL *pdfURL = [absoluteURL URLReplacingPathExtension:@"pdf"];
             BOOL isDir;
-            if ([[NSFileManager defaultManager] fileExistsAtPath:pdfFile 
isDirectory:&isDir] && isDir == NO)
-                absoluteURL = [NSURL fileURLWithPath:pdfFile];
+            if ([[NSFileManager defaultManager] fileExistsAtPath:[pdfURL path] 
isDirectory:&isDir] && isDir == NO)
+                absoluteURL = pdfURL;
         }
     } else if ([ws type:type conformsToType:SKFolderDocumentType]) {
         NSDocument *doc = nil;

Modified: trunk/SKMainDocument.m
===================================================================
--- trunk/SKMainDocument.m      2012-11-01 13:09:50 UTC (rev 7762)
+++ trunk/SKMainDocument.m      2012-11-01 16:06:57 UTC (rev 7763)
@@ -104,7 +104,7 @@
 #define TYPE_KEY            @"type"
 #define SAVEOPERATION_KEY   @"saveOperation"
 #define CALLBACK_KEY        @"callback"
-#define TMPPATH_KEY         @"tmpPath"
+#define TMPURL_KEY          @"tmpURL"
 
 #define SOURCEPATH_KEY  @"sourcePath"
 #define TARGETPATH_KEY  @"targetPath"
@@ -286,10 +286,10 @@
 }
 
 - (void)saveRecentDocumentInfo {
-    NSString *path = [[self fileURL] path];
+    NSURL *fileURL = [self fileURL];
     NSUInteger pageIndex = [[[self pdfView] currentPage] pageIndex];
-    if (path && pageIndex != NSNotFound && [self mainWindowController])
-        [[SKBookmarkController sharedBookmarkController] 
addRecentDocumentForPath:path pageIndex:pageIndex snapshots:[[[self 
mainWindowController] snapshots] valueForKey:SKSnapshotCurrentSetupKey]];
+    if (fileURL && pageIndex != NSNotFound && [self mainWindowController])
+        [[SKBookmarkController sharedBookmarkController] 
addRecentDocumentForURL:fileURL pageIndex:pageIndex snapshots:[[[self 
mainWindowController] snapshots] valueForKey:SKSnapshotCurrentSetupKey]];
 }
 
 - (void)undoableActionIsDiscardableDeferred:(NSNumber *)anUndoState {
@@ -424,15 +424,15 @@
     BOOL saveNotesOK = NO;
     
     if ([[NSUserDefaults standardUserDefaults] 
boolForKey:SKAutoSaveSkimNotesKey]) {
-        NSString *notesPath = [absoluteURL pathReplacingPathExtension:@"skim"];
-        BOOL fileExists = [fm fileExistsAtPath:notesPath];
+        NSURL *notesURL = [absoluteURL URLReplacingPathExtension:@"skim"];
+        BOOL fileExists = [fm fileExistsAtPath:[notesURL path]];
         
         if (fileExists && (saveOperation == NSSaveAsOperation || saveOperation 
== NSSaveToOperation)) {
-            NSAlert *alert = [NSAlert alertWithMessageText:[NSString 
stringWithFormat:NSLocalizedString(@"\"%@\" already exists. Do you want to 
replace it?", @"Message in alert dialog"), [notesPath lastPathComponent]]
+            NSAlert *alert = [NSAlert alertWithMessageText:[NSString 
stringWithFormat:NSLocalizedString(@"\"%@\" already exists. Do you want to 
replace it?", @"Message in alert dialog"), [notesURL lastPathComponent]]
                                              
defaultButton:NSLocalizedString(@"Save", @"Button title")
                                            
alternateButton:NSLocalizedString(@"Cancel", @"Button title")
                                                otherButton:nil
-                                 
informativeTextWithFormat:NSLocalizedString(@"A file or folder with the same 
name already exists in %@. Replacing it will overwrite its current contents.", 
@"Informative text in alert dialog"), [[notesPath 
stringByDeletingLastPathComponent] lastPathComponent]];
+                                 
informativeTextWithFormat:NSLocalizedString(@"A file or folder with the same 
name already exists in %@. Replacing it will overwrite its current contents.", 
@"Informative text in alert dialog"), [[notesURL 
URLByDeletingLastPathComponent] lastPathComponent]];
             
             saveNotesOK = NSAlertDefaultReturn == [alert runModal];
         } else {
@@ -441,9 +441,9 @@
         
         if (saveNotesOK) {
             if ([[self notes] count] > 0)
-                saveNotesOK = [self writeSafelyToURL:[NSURL 
fileURLWithPath:notesPath] ofType:SKNotesDocumentType 
forSaveOperation:NSSaveToOperation error:NULL];
+                saveNotesOK = [self writeSafelyToURL:notesURL 
ofType:SKNotesDocumentType forSaveOperation:NSSaveToOperation error:NULL];
             else if (fileExists)
-                saveNotesOK = [fm removeItemAtPath:notesPath error:NULL];
+                saveNotesOK = [fm removeItemAtURL:notesURL error:NULL];
         }
     }
     
@@ -474,7 +474,7 @@
                                          
defaultButton:NSLocalizedString(@"OK", @"Button title")
                                        alternateButton:nil
                                            otherButton:nil
-                             informativeTextWithFormat:message, [[absoluteURL 
path] lastPathComponent]];
+                             informativeTextWithFormat:message, [absoluteURL 
lastPathComponent]];
         [alert runModal];
     }
     
@@ -490,7 +490,7 @@
 - (void)document:(NSDocument *)doc didSave:(BOOL)didSave contextInfo:(void 
*)contextInfo {
     NSDictionary *info = [(id)contextInfo autorelease];
     NSSaveOperationType saveOperation = [[info objectForKey:SAVEOPERATION_KEY] 
unsignedIntegerValue];
-    NSString *tmpPath = [info objectForKey:TMPPATH_KEY];
+    NSURL *tmpURL = [info objectForKey:TMPURL_KEY];
     
     if (didSave) {
         NSURL *absoluteURL = [info objectForKey:URL_KEY];
@@ -499,12 +499,11 @@
         if ([self canAttachNotesForType:typeName] && exportOption == 
SKExportOptionDefault) {
             // we check for notes and may save a .skim as well:
             [self saveNotesToURL:absoluteURL forSaveOperation:saveOperation];
-        } else if ([[NSWorkspace sharedWorkspace] type:typeName 
conformsToType:SKPDFBundleDocumentType] && tmpPath) {
+        } else if ([[NSWorkspace sharedWorkspace] type:typeName 
conformsToType:SKPDFBundleDocumentType] && tmpURL) {
             // move extra package content like version info to the new location
             NSFileManager *fm = [NSFileManager defaultManager];
-            NSString *path = [absoluteURL path];
-            for (NSString *file in [fm contentsOfDirectoryAtPath:tmpPath 
error:NULL])
-                [fm moveItemAtPath:[tmpPath 
stringByAppendingPathComponent:file] toPath:[path 
stringByAppendingPathComponent:file] error:NULL];
+            for (NSURL *url in [fm contentsOfDirectoryAtURL:tmpURL 
includingPropertiesForKeys:nil options:0 error:NULL])
+                [fm moveItemAtURL:url toURL:[absoluteURL 
URLByAppendingPathComponent:[url lastPathComponent]] error:NULL];
         }
     
         if (saveOperation == NSSaveOperation || saveOperation == 
NSSaveAsOperation) {
@@ -517,8 +516,8 @@
             [[NSDistributedNotificationCenter defaultCenter] 
postNotificationName:SKSkimFileDidSaveNotification object:[absoluteURL path]];
     }
     
-    if (tmpPath)
-        [[NSFileManager defaultManager] removeItemAtPath:tmpPath error:NULL];
+    if (tmpURL)
+        [[NSFileManager defaultManager] removeItemAtURL:tmpURL error:NULL];
     
     if (saveOperation == NSSaveOperation || saveOperation == 
NSSaveAsOperation) {
         [fileUpdateChecker checkFileUpdatesIfNeeded];
@@ -562,19 +561,19 @@
     
     if ([ws type:typeName conformsToType:SKPDFBundleDocumentType] && [ws 
type:[self fileType] conformsToType:SKPDFBundleDocumentType] && [self fileURL] 
&& saveOperation != NSSaveToOperation) {
         NSFileManager *fm = [NSFileManager defaultManager];
-        NSString *path = [[self fileURL] path];
-        NSString *tmpPath = nil;
+        NSURL *fileURL = [self fileURL];
+        NSURL *tmpURL = nil;
         // we move everything that's not ours out of the way, so we can 
preserve version control info
         NSSet *ourExtensions = [NSSet setWithObjects:@"pdf", @"skim", @"fdf", 
@"txt", @"text", @"rtf", @"plist", nil];
-        for (NSString *file in [fm contentsOfDirectoryAtPath:path error:NULL]) 
{
-            if ([ourExtensions containsObject:[[file pathExtension] 
lowercaseString]] == NO) {
-                if (tmpPath == nil)
-                    tmpPath = SKUniqueTemporaryDirectory();
-                [fm copyItemAtPath:[path stringByAppendingPathComponent:file] 
toPath:[tmpPath stringByAppendingPathComponent:file] error:NULL];
+        for (NSURL *url in [fm contentsOfDirectoryAtURL:fileURL 
includingPropertiesForKeys:nil options:0 error:NULL]) {
+            if ([ourExtensions containsObject:[[url pathExtension] 
lowercaseString]] == NO) {
+                if (tmpURL == nil)
+                    tmpURL = [NSURL 
fileURLWithPath:SKUniqueTemporaryDirectory()];
+                [fm copyItemAtURL:url toURL:[tmpURL 
URLByAppendingPathComponent:[url lastPathComponent]] error:NULL];
             }
         }
-        if (tmpPath)
-            [info setObject:tmpPath forKey:TMPPATH_KEY];
+        if (tmpURL)
+            [info setObject:tmpURL forKey:TMPURL_KEY];
     }
     
     [super saveToURL:absoluteURL ofType:typeName 
forSaveOperation:saveOperation delegate:self 
didSaveSelector:@selector(document:didSave:contextInfo:) contextInfo:info];
@@ -624,9 +623,9 @@
         if ([ws type:[self fileType] conformsToType:typeName])
             didWrite = [originalData writeToURL:absoluteURL options:0 
error:&error];
     } else if ([ws type:SKPDFBundleDocumentType conformsToType:typeName]) {
-        NSFileWrapper *fileWrapper = [self 
PDFBundleFileWrapperForName:[[[absoluteURL path] lastPathComponent] 
stringByDeletingPathExtension]];
+        NSFileWrapper *fileWrapper = [self 
PDFBundleFileWrapperForName:[[absoluteURL lastPathComponent] 
stringByDeletingPathExtension]];
         if (fileWrapper)
-            didWrite = [fileWrapper writeToFile:[absoluteURL path] 
atomically:NO updateFilenames:NO];
+            didWrite = [fileWrapper writeToURL:absoluteURL options:0 
originalContentsURL:nil error:&error];
         else
             error = [NSError 
writeFileErrorWithLocalizedDescription:NSLocalizedString(@"Unable to write 
file", @"Error description")];
     } else if ([ws type:SKNotesDocumentType conformsToType:typeName]) {
@@ -640,7 +639,7 @@
     } else if ([ws type:SKNotesRTFDDocumentType conformsToType:typeName]) {
         NSFileWrapper *fileWrapper = [self notesRTFDFileWrapper];
         if (fileWrapper)
-            didWrite = [fileWrapper writeToFile:[absoluteURL path] 
atomically:NO updateFilenames:NO];
+            didWrite = [fileWrapper writeToURL:absoluteURL options:0 
originalContentsURL:nil error:&error];
         else
             error = [NSError 
writeFileErrorWithLocalizedDescription:NSLocalizedString(@"Unable to write 
notes as RTFD", @"Error description")];
     } else if ([ws type:SKNotesTextDocumentType conformsToType:typeName]) {
@@ -662,7 +661,7 @@
     } else if ([[SKTemplateManager sharedManager] 
isRichTextBundleTemplateType:typeName]) {
         NSFileWrapper *fileWrapper = [self 
notesFileWrapperForTemplateType:typeName];
         if (fileWrapper)
-            didWrite = [fileWrapper writeToFile:[absoluteURL path] 
atomically:NO updateFilenames:NO];
+            didWrite = [fileWrapper writeToURL:absoluteURL options:0 
originalContentsURL:nil error:&error];
         else
             error = [NSError 
writeFileErrorWithLocalizedDescription:NSLocalizedString(@"Unable to write 
notes using template", @"Error description")];
     } else {
@@ -688,18 +687,17 @@
         ([[self class] isNativeType:typeName] || [typeName 
isEqualToString:SKNotesDocumentType]))
         [dict setObject:[NSNumber numberWithUnsignedInt:'SKim'] 
forKey:NSFileHFSCreatorCode];
     
-    if ([[[absoluteURL path] pathExtension] isEqualToString:@"pdf"] || 
-        [ws type:typeName conformsToType:SKPDFDocumentType])
+    if ([ws type:typeName conformsToType:SKPDFDocumentType])
         [dict setObject:[NSNumber numberWithUnsignedInt:'PDF '] 
forKey:NSFileHFSTypeCode];
-    else if ([[[absoluteURL path] pathExtension] isEqualToString:@"pdfd"] || 
[ws type:typeName conformsToType:SKPDFBundleDocumentType])
+    else if ([ws type:typeName conformsToType:SKPDFBundleDocumentType])
         [dict setObject:[NSNumber numberWithUnsignedInt:'PDFD'] 
forKey:NSFileHFSTypeCode];
-    else if ([[[absoluteURL path] pathExtension] isEqualToString:@"skim"] || 
[ws type:typeName conformsToType:SKNotesDocumentType])
+    else if ([ws type:typeName conformsToType:SKNotesDocumentType])
         [dict setObject:[NSNumber numberWithUnsignedInt:'SKNT'] 
forKey:NSFileHFSTypeCode];
-    else if ([[[absoluteURL path] pathExtension] isEqualToString:@"fdf"] || 
[ws type:typeName conformsToType:SKNotesFDFDocumentType])
+    else if ([ws type:typeName conformsToType:SKNotesFDFDocumentType])
         [dict setObject:[NSNumber numberWithUnsignedInt:'FDF '] 
forKey:NSFileHFSTypeCode];
-    else if ([[[absoluteURL path] pathExtension] isEqualToString:@"rtf"] || 
[ws type:typeName conformsToType:SKNotesRTFDocumentType])
+    else if ([[absoluteURL pathExtension] isEqualToString:@"rtf"] || [ws 
type:typeName conformsToType:SKNotesRTFDocumentType])
         [dict setObject:[NSNumber numberWithUnsignedInt:'RTF '] 
forKey:NSFileHFSTypeCode];
-    else if ([[[absoluteURL path] pathExtension] isEqualToString:@"txt"] || 
[ws type:typeName conformsToType:SKNotesTextDocumentType])
+    else if ([[absoluteURL pathExtension] isEqualToString:@"txt"] || [ws 
type:typeName conformsToType:SKNotesTextDocumentType])
         [dict setObject:[NSNumber numberWithUnsignedInt:'TEXT'] 
forKey:NSFileHFSTypeCode];
     
     return dict;
@@ -806,9 +804,9 @@
                 if ([ws type:docType conformsToType:SKPostScriptDocumentType])
                     data = [SKConversionProgressController 
newPDFDataWithPostScriptData:fileData error:&error];
                 else if ([ws type:docType conformsToType:SKDVIDocumentType])
-                    data = [SKConversionProgressController 
newPDFDataWithDVIFile:[absoluteURL path] error:&error];
+                    data = [SKConversionProgressController 
newPDFDataWithDVIAtURL:absoluteURL error:&error];
                 else if ([ws type:docType conformsToType:SKXDVDocumentType])
-                    data = [SKConversionProgressController 
newPDFDataWithXDVFile:[absoluteURL path] error:&error];
+                    data = [SKConversionProgressController 
newPDFDataWithXDVAtURL:absoluteURL error:&error];
                 if (data)
                     pdfDoc = [[SKPDFDocument alloc] initWithData:data];
             }
@@ -833,8 +831,8 @@
                     }
                 }
                 if (pdfDoc) {
-                    NSString *path = [absoluteURL 
pathReplacingPathExtension:@"skim"];
-                    if ([[NSFileManager defaultManager] 
fileExistsAtPath:path]) {
+                    NSURL *url = [absoluteURL 
URLReplacingPathExtension:@"skim"];
+                    if ([[NSFileManager defaultManager] fileExistsAtPath:[url 
path]]) {
                         NSInteger readOption = [[NSUserDefaults 
standardUserDefaults] integerForKey:SKReadMissingNotesFromSkimFileOptionKey];
                         if (readOption == NSAlertOtherReturn) {
                             NSAlert *alert = [NSAlert 
alertWithMessageText:NSLocalizedString(@"Found Separate Notes", @"Message in 
alert dialog") 
@@ -845,7 +843,7 @@
                             readOption = [alert runModal];
                         }
                         if (readOption == NSAlertDefaultReturn) {
-                            array = [[NSFileManager defaultManager] 
readSkimNotesFromSkimFileAtURL:[NSURL fileURLWithPath:path] error:NULL];
+                            array = [[NSFileManager defaultManager] 
readSkimNotesFromSkimFileAtURL:url error:NULL];
                             if ([array count]) {
                                 [tmpData setNoteDicts:array];
                                 [self updateChangeCount:NSChangeDone];
@@ -870,7 +868,7 @@
             NSArray *array = nil;
             NSNumber *number = nil;
             if ([docType isEqualToString:SKPDFBundleDocumentType]) {
-                NSData *infoData = [NSData 
dataWithContentsOfFile:[[[absoluteURL path] 
stringByAppendingPathComponent:BUNDLE_DATA_FILENAME] 
stringByAppendingPathExtension:@"plist"]];
+                NSData *infoData = [NSData dataWithContentsOfURL:[[absoluteURL 
URLByAppendingPathComponent:BUNDLE_DATA_FILENAME] 
URLByAppendingPathExtension:@"plist"]];
                 if (infoData) {
                     NSDictionary *info = [NSPropertyListSerialization 
propertyListWithData:infoData options:NSPropertyListImmutable format:NULL 
error:NULL];
                     if ([info isKindOfClass:[NSDictionary class]]) {
@@ -962,7 +960,7 @@
 #pragma mark Actions
 
 - (void)readNotesFromURL:(NSURL *)notesURL replace:(BOOL)replace 
{log_method();return;
-    NSString *extension = [[notesURL path] pathExtension];
+    NSString *extension = [notesURL pathExtension];
     NSArray *array = nil;
     
     if ([extension isCaseInsensitiveEqual:@"skim"]) {
@@ -1135,7 +1133,7 @@
 
 - (BOOL)saveArchiveToFile:(NSString *)fileName {
     return [NSTask runTaskWithLaunchPath:@"/usr/bin/tar"
-                               arguments:[NSArray arrayWithObjects:@"-czf", 
fileName, [[[self fileURL] path] lastPathComponent], nil]
+                               arguments:[NSArray arrayWithObjects:@"-czf", 
fileName, [[self fileURL] lastPathComponent], nil]
                     currentDirectoryPath:[[[self fileURL] path] 
stringByDeletingLastPathComponent]];
 }
 
@@ -1324,7 +1322,7 @@
              [super revertDocumentToSaved:sender];      
          } else if ([fileUpdateChecker fileChangedOnDisk] || 
                     NSOrderedAscending == [[self fileModificationDate] 
compare:[[[NSFileManager defaultManager] attributesOfItemAtPath:[[self fileURL] 
path] error:NULL] fileModificationDate]]) {
-             NSAlert *alert = [NSAlert alertWithMessageText:[NSString 
stringWithFormat:NSLocalizedString(@"Do you want to revert to the version of 
the document \"%@\" on disk?", @"Message in alert dialog"), [[[self fileURL] 
path] lastPathComponent]]       
+             NSAlert *alert = [NSAlert alertWithMessageText:[NSString 
stringWithFormat:NSLocalizedString(@"Do you want to revert to the version of 
the document \"%@\" on disk?", @"Message in alert dialog"), [[self fileURL] 
lastPathComponent]]      
                                               
defaultButton:NSLocalizedString(@"Revert", @"Button title")       
                                             
alternateButton:NSLocalizedString(@"Cancel", @"Button title")       
                                                 otherButton:nil         
@@ -1991,7 +1989,7 @@
             source = [NSURL fileURLWithPath:source];
         if ([source isKindOfClass:[NSURL class]] == NO)
             source = [self fileURL];
-        [[self synchronizer] findPageAndLocationForLine:[location index] 
inFile:[source pathReplacingPathExtension:@"tex"] options:options];
+        [[self synchronizer] findPageAndLocationForLine:[location index] 
inFile:[[source URLReplacingPathExtension:@"tex"] path] options:options];
     } else {
         PDFSelection *selection = [PDFSelection 
selectionWithSpecifier:[[command arguments] objectForKey:@"To"]];
         if ([selection hasCharacters]) {

Modified: trunk/SKMainWindowController.m
===================================================================
--- trunk/SKMainWindowController.m      2012-11-01 13:09:50 UTC (rev 7762)
+++ trunk/SKMainWindowController.m      2012-11-01 16:06:57 UTC (rev 7763)
@@ -442,7 +442,7 @@
     if (hasWindowSetup)
         pageIndex = [[savedNormalSetup objectForKey:PAGEINDEX_KEY] 
unsignedIntegerValue];
     else if ([sud boolForKey:SKRememberLastPageViewedKey])
-        pageIndex = [[SKBookmarkController sharedBookmarkController] 
pageIndexForRecentDocumentAtPath:[[[self document] fileURL] path]];
+        pageIndex = [[SKBookmarkController sharedBookmarkController] 
pageIndexForRecentDocumentAtURL:[[self document] fileURL]];
     if (pageIndex != NSNotFound && [[pdfView document] pageCount] > pageIndex) 
{
         if ([[pdfView document] isLocked]) {
             [savedNormalSetup setObject:[NSNumber 
numberWithUnsignedInteger:pageIndex] forKey:PAGEINDEX_KEY];
@@ -461,7 +461,7 @@
     if (hasWindowSetup)
         snapshotSetups = [savedNormalSetup objectForKey:SNAPSHOTS_KEY];
     else if ([sud boolForKey:SKRememberSnapshotsKey])
-        snapshotSetups = [[SKBookmarkController sharedBookmarkController] 
snapshotsForRecentDocumentAtPath:[[[self document] fileURL] path]];
+        snapshotSetups = [[SKBookmarkController sharedBookmarkController] 
snapshotsForRecentDocumentAtURL:[[self document] fileURL]];
     if ([snapshotSetups count]) {
         if ([[pdfView document] isLocked])
             [savedNormalSetup setObject:snapshotSetups forKey:SNAPSHOTS_KEY];

Modified: trunk/SKNotesDocument.m
===================================================================
--- trunk/SKNotesDocument.m     2012-11-01 13:09:50 UTC (rev 7762)
+++ trunk/SKNotesDocument.m     2012-11-01 16:06:57 UTC (rev 7763)
@@ -282,11 +282,10 @@
     } else if ([ws type:SKNotesRTFDocumentType conformsToType:typeName]) {
         data = [self notesRTFData];
     } else if ([ws type:SKNotesFDFDocumentType conformsToType:typeName]) {
-        NSString *filename = [[self fileURL] 
pathReplacingPathExtension:@"pdf"];
-        if ([[NSFileManager defaultManager] fileExistsAtPath:filename])
-            filename = [filename lastPathComponent];
-        else
-            filename = nil;
+        NSString *filename = nil;
+        NSURL *pdfURL = [[self fileURL] URLReplacingPathExtension:@"pdf"];
+        if ([[NSFileManager defaultManager] fileExistsAtPath:[pdfURL path]])
+            filename = [pdfURL lastPathComponent];
         data = [self notesFDFDataForFile:filename fileIDStrings:nil];
     } else {
         data = [self notesDataForTemplateType:typeName];
@@ -356,11 +355,11 @@
     if ([[NSUserDefaults standardUserDefaults] 
boolForKey:SKShouldSetCreatorCodeKey] && [ws type:typeName 
conformsToType:SKNotesDocumentType])
         [dict setObject:[NSNumber numberWithUnsignedInt:'SKim'] 
forKey:NSFileHFSCreatorCode];
     
-    if ([[[absoluteURL path] pathExtension] isEqualToString:@"skim"] || [ws 
type:typeName conformsToType:SKNotesDocumentType])
+    if ([ws type:typeName conformsToType:SKNotesDocumentType])
         [dict setObject:[NSNumber numberWithUnsignedInt:'SKNT'] 
forKey:NSFileHFSTypeCode];
-    else if ([[[absoluteURL path] pathExtension] isEqualToString:@"rtf"] || 
[ws type:typeName conformsToType:SKNotesRTFDocumentType])
+    else if ([[absoluteURL pathExtension] isEqualToString:@"rtf"] || [ws 
type:typeName conformsToType:SKNotesRTFDocumentType])
         [dict setObject:[NSNumber numberWithUnsignedInt:'RTF '] 
forKey:NSFileHFSTypeCode];
-    else if ([[[absoluteURL path] pathExtension] isEqualToString:@"txt"] || 
[ws type:typeName conformsToType:SKNotesTextDocumentType])
+    else if ([[absoluteURL pathExtension] isEqualToString:@"txt"] || [ws 
type:typeName conformsToType:SKNotesTextDocumentType])
         [dict setObject:[NSNumber numberWithUnsignedInt:'TEXT'] 
forKey:NSFileHFSTypeCode];
     
     return dict;
@@ -400,7 +399,7 @@
 
 - (NSString *)displayName {
     if (sourceFileURL)
-        return [[[sourceFileURL path] lastPathComponent] 
stringByDeletingPathExtension];
+        return [[sourceFileURL lastPathComponent] 
stringByDeletingPathExtension];
     return [super displayName];
 }
 
@@ -439,21 +438,18 @@
 #pragma mark Actions
 
 - (IBAction)openPDF:(id)sender {
-    NSString *path = [sourceFileURL path] ?: [[self fileURL] 
pathReplacingPathExtension:@"pdf"];
+    NSURL *url = sourceFileURL ?: [[self fileURL] 
URLReplacingPathExtension:@"pdf"];
     NSError *error = nil;
-    if ([[NSFileManager defaultManager] fileExistsAtPath:path]) {
+    if ([[NSFileManager defaultManager] fileExistsAtPath:[url path]]) {
         // resolve symlinks and aliases
-        NSURL *url = nil;
         FSRef fileRef;
         Boolean isFolder, isAlias;
-        if (noErr == FSPathMakeRef((const unsigned char *)[[path 
stringByResolvingSymlinksInPath] fileSystemRepresentation], &fileRef, NULL)) {
+        if (noErr == FSPathMakeRef((const unsigned char *)[[[url 
URLByResolvingSymlinksInPath] path] fileSystemRepresentation], &fileRef, NULL)) 
{
             CFStringRef theUTI = NULL;
             if (noErr == LSCopyItemAttribute(&fileRef, kLSRolesAll, 
kLSItemContentType, (CFTypeRef *)&theUTI) && theUTI && UTTypeConformsTo(theUTI, 
kUTTypeResolvable))
                 FSResolveAliasFileWithMountFlags(&fileRef, TRUE, &isFolder, 
&isAlias, kResolveAliasFileNoUI);
-           url = [(NSURL *)CFURLCreateFromFSRef(NULL, &fileRef) autorelease];
+           url = [(NSURL *)CFURLCreateFromFSRef(NULL, &fileRef) autorelease] 
?: url;
         }
-        if (url == nil)
-            url = [NSURL fileURLWithPath:path];
         if (nil == [[NSDocumentController sharedDocumentController] 
openDocumentWithContentsOfURL:url display:YES error:&error] && [error 
isUserCancelledError] == NO)
             [NSApp presentError:error];
     } else NSBeep();
@@ -835,7 +831,7 @@
     if ([[[[[self windowControllers] objectAtIndex:0] window] toolbar] 
customizationPaletteIsRunning])
         return NO;
     else if ([[toolbarItem itemIdentifier] 
isEqualToString:SKNotesDocumentOpenPDFToolbarItemIdentifier])
-        return [[NSFileManager defaultManager] fileExistsAtPath:[sourceFileURL 
path] ?: [[self fileURL] pathReplacingPathExtension:@"pdf"]];
+        return [[NSFileManager defaultManager] 
fileExistsAtPath:[(sourceFileURL ?: [[self fileURL] 
URLReplacingPathExtension:@"pdf"]) path]];
     return YES;
 }
 

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