Revision: 7770
          http://skim-app.svn.sourceforge.net/skim-app/?rev=7770&view=rev
Author:   hofman
Date:     2012-11-02 10:44:23 +0000 (Fri, 02 Nov 2012)
Log Message:
-----------
create unique file URL rather than path

Modified Paths:
--------------
    trunk/NSFileManager_SKExtensions.h
    trunk/NSFileManager_SKExtensions.m
    trunk/SKDragImageView.m
    trunk/SKMainWindowController_UI.m
    trunk/SKNoteWindowController.m

Modified: trunk/NSFileManager_SKExtensions.h
===================================================================
--- trunk/NSFileManager_SKExtensions.h  2012-11-02 01:10:25 UTC (rev 7769)
+++ trunk/NSFileManager_SKExtensions.h  2012-11-02 10:44:23 UTC (rev 7770)
@@ -47,7 +47,7 @@
 
 - (NSArray *)applicationSupportDirectoryURLs;
 
-- (NSString *)uniqueFile:(NSString *)path;
+- (NSURL *)uniqueFileURL:(NSURL *)fileURL;
 
 @end
 

Modified: trunk/NSFileManager_SKExtensions.m
===================================================================
--- trunk/NSFileManager_SKExtensions.m  2012-11-02 01:10:25 UTC (rev 7769)
+++ trunk/NSFileManager_SKExtensions.m  2012-11-02 10:44:23 UTC (rev 7770)
@@ -69,14 +69,15 @@
     return applicationSupportDirectoryURLs;
 }
 
-- (NSString *)uniqueFile:(NSString *)path {
-    NSString *uniquePath = path;
-    NSString *basePath = [path stringByDeletingPathExtension];
-    NSString *extension = [path pathExtension];
+- (NSURL *)uniqueFileURL:(NSURL *)fileURL {
+    NSURL *uniqueFileURL = fileURL;
+    NSURL *baseURL = [fileURL URLByDeletingLastPathComponent];
+    NSString *baseName = [[fileURL lastPathComponent] 
stringByDeletingPathExtension];
+    NSString *extension = [fileURL pathExtension];
     NSInteger i = 0;
-    while ([self fileExistsAtPath:path])
-        uniquePath = [[basePath stringByAppendingFormat:@"-%ld", (long)++i] 
stringByAppendingPathExtension:extension];
-    return uniquePath;
+    while ([self fileExistsAtURL:uniqueFileURL])
+        uniqueFileURL = [baseURL URLByAppendingPathComponent:[[baseName 
stringByAppendingFormat:@"-%ld", (long)++i] 
stringByAppendingPathExtension:extension]];
+    return uniqueFileURL;
 }
 
 @end

Modified: trunk/SKDragImageView.m
===================================================================
--- trunk/SKDragImageView.m     2012-11-02 01:10:25 UTC (rev 7769)
+++ trunk/SKDragImageView.m     2012-11-02 10:44:23 UTC (rev 7770)
@@ -55,11 +55,11 @@
         return;
     }
     
-    NSString *path = [NSTemporaryDirectory() 
stringByAppendingPathComponent:@"SkimNote.tiff"];
+    NSURL *fileURL = [[NSURL fileURLWithPath:NSTemporaryDirectory()] 
URLByAppendingPathComponent:@"SkimNote.tiff"];
     
-    path = [[NSFileManager defaultManager] uniqueFile:path];
-    [[image TIFFRepresentation] writeToFile:path atomically:YES];
-    [[NSWorkspace sharedWorkspace] openFile:path];
+    fileURL = [[NSFileManager defaultManager] uniqueFileURL:fileURL];
+    [[image TIFFRepresentation] writeToURL:fileURL atomically:YES];
+    [[NSWorkspace sharedWorkspace] openURL:fileURL];
 }
 
 - (BOOL)validateMenuItem:(NSMenuItem *)menuItem {

Modified: trunk/SKMainWindowController_UI.m
===================================================================
--- trunk/SKMainWindowController_UI.m   2012-11-02 01:10:25 UTC (rev 7769)
+++ trunk/SKMainWindowController_UI.m   2012-11-02 10:44:23 UTC (rev 7770)
@@ -334,7 +334,7 @@
         NSUInteger idx = [rowIndexes firstIndex];
         if (idx != NSNotFound) {
             PDFPage *page = [[pdfView document] pageAtIndex:idx];
-            NSString *path = [[dropDestination path] 
stringByAppendingPathComponent:[self draggedFileNameForPage:page]];
+            NSURL *fileURL = [dropDestination 
URLByAppendingPathComponent:[self draggedFileNameForPage:page]];
             NSString *pathExt = nil;
             NSData *data = nil;
             
@@ -346,19 +346,19 @@
                 data = [page TIFFDataForRect:[page boundsForBox:[pdfView 
displayBox]]];
             }
             
-            path = [[NSFileManager defaultManager] uniqueFile:[path 
stringByAppendingPathExtension:pathExt]];
-            if ([data writeToFile:path atomically:YES])
-                return [NSArray arrayWithObjects:[path lastPathComponent], 
nil];
+            fileURL = [[NSFileManager defaultManager] uniqueFileURL:[fileURL 
URLByAppendingPathExtension:pathExt]];
+            if ([data writeToURL:fileURL atomically:YES])
+                return [NSArray arrayWithObjects:[fileURL lastPathComponent], 
nil];
         }
     } else if ([tv isEqual:rightSideController.snapshotTableView]) {
         NSUInteger idx = [rowIndexes firstIndex];
         if (idx != NSNotFound) {
             SKSnapshotWindowController *snapshot = [self 
objectInSnapshotsAtIndex:idx];
             PDFPage *page = [[pdfView document] pageAtIndex:[snapshot 
pageIndex]];
-            NSString *path = [[[dropDestination path] 
stringByAppendingPathComponent:[self draggedFileNameForPage:page]] 
stringByAppendingPathExtension:@"tiff"];
-            path = [[NSFileManager defaultManager] uniqueFile:path];
-            if ([[[snapshot thumbnailWithSize:0.0] TIFFRepresentation] 
writeToFile:path atomically:YES])
-                return [NSArray arrayWithObjects:[path lastPathComponent], 
nil];
+            NSURL *fileURL = [[dropDestination 
URLByAppendingPathComponent:[self draggedFileNameForPage:page]] 
URLByAppendingPathExtension:@"tiff"];
+            fileURL = [[NSFileManager defaultManager] uniqueFileURL:fileURL];
+            if ([[[snapshot thumbnailWithSize:0.0] TIFFRepresentation] 
writeToURL:fileURL atomically:YES])
+                return [NSArray arrayWithObjects:[fileURL lastPathComponent], 
nil];
         }
     }
     return nil;

Modified: trunk/SKNoteWindowController.m
===================================================================
--- trunk/SKNoteWindowController.m      2012-11-02 01:10:25 UTC (rev 7769)
+++ trunk/SKNoteWindowController.m      2012-11-02 10:44:23 UTC (rev 7770)
@@ -347,10 +347,10 @@
         if ([name length] == 0)
             name = @"NoteImage";
         name = [name stringByAppendingPathExtension:@"tiff"];
-        NSString *path = [[[dropDestination path] 
stringByAppendingPathComponent:name] stringByAppendingPathExtension:@"tiff"];
-        path = [[NSFileManager defaultManager] uniqueFile:path];
-        if ([[image TIFFRepresentation] writeToFile:path atomically:YES])
-            return [NSArray arrayWithObjects:[path lastPathComponent], nil];
+        NSURL *fileURL = [[dropDestination URLByAppendingPathComponent:name] 
URLByAppendingPathExtension:@"tiff"];
+        fileURL = [[NSFileManager defaultManager] uniqueFileURL:fileURL];
+        if ([[image TIFFRepresentation] writeToURL:fileURL atomically:YES])
+            return [NSArray arrayWithObjects:[fileURL lastPathComponent], nil];
     }
     return nil;
 }

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


------------------------------------------------------------------------------
LogMeIn Central: Instant, anywhere, Remote PC access and management.
Stay in control, update software, and manage PCs from one command center
Diagnose problems and improve visibility into emerging IT issues
Automate, monitor and manage. Do more in less time with Central
http://p.sf.net/sfu/logmein12331_d2d
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to