Revision: 6788
          http://skim-app.svn.sourceforge.net/skim-app/?rev=6788&view=rev
Author:   hofman
Date:     2010-09-09 10:23:16 +0000 (Thu, 09 Sep 2010)

Log Message:
-----------
convenience shortcut to get the document class for a file URL directly

Modified Paths:
--------------
    trunk/SKBookmark.m
    trunk/SKDocumentController.h
    trunk/SKDocumentController.m
    trunk/SKMainWindowController_UI.m

Modified: trunk/SKBookmark.m
===================================================================
--- trunk/SKBookmark.m  2010-09-09 10:12:21 UTC (rev 6787)
+++ trunk/SKBookmark.m  2010-09-09 10:23:16 UTC (rev 6788)
@@ -41,6 +41,7 @@
 #import "NSImage_SKExtensions.h"
 #import "SKBookmarkController.h"
 #import "NSDocument_SKExtensions.h"
+#import "SKDocumentController.h"
 
 #define BOOKMARK_STRING     @"bookmark"
 #define SESSION_STRING      @"session"
@@ -261,7 +262,6 @@
                 NSURL *aURL = [properties objectForKey:@"scriptingFile"] ?: 
contentsValue;
                 NSString *aPath = [aURL respondsToSelector:@selector(path)] ? 
[aURL path] : nil;
                 NSString *aLabel = [properties objectForKey:@"label"] ?: 
[aPath lastPathComponent] ?: @"";
-                NSDocumentController *dc = [NSDocumentController 
sharedDocumentController];
                 Class docClass;
                 if (aPath == nil) {
                     [[NSScriptCommand currentCommand] 
setScriptErrorNumber:NSRequiredArgumentsMissingScriptError];
@@ -269,7 +269,7 @@
                 } else if ([[NSFileManager defaultManager] 
fileExistsAtPath:aPath] == NO) {
                     [[NSScriptCommand currentCommand] 
setScriptErrorNumber:NSArgumentsWrongScriptError];
                     [[NSScriptCommand currentCommand] 
setScriptErrorString:@"New file bookmark requires an existing file."];
-                } else if (docClass = [dc documentClassForType:[dc 
typeForContentsOfURL:aURL error:NULL]]) {
+                } else if (docClass = [[NSDocumentController 
sharedDocumentController] documentClassForContentsOfURL:aURL]) {
                     NSUInteger aPageNumber = [[properties 
objectForKey:@"pageNumber"] unsignedIntegerValue];
                     if (aPageNumber > 0)
                         aPageNumber--;

Modified: trunk/SKDocumentController.h
===================================================================
--- trunk/SKDocumentController.h        2010-09-09 10:12:21 UTC (rev 6787)
+++ trunk/SKDocumentController.h        2010-09-09 10:23:16 UTC (rev 6788)
@@ -95,6 +95,8 @@
 - (id)openDocumentWithURLFromPasteboard:(NSPasteboard *)pboard error:(NSError 
**)outError;
 - (id)openDocumentWithSetup:(NSDictionary *)setup error:(NSError **)outError;
 
+- (Class)documentClassForContentsOfURL:(NSURL *)inAbsoluteURL;
+
 - (NSArray *)customExportTemplateFiles;
 - (NSArray *)customExportTemplateFilesResetting;
 

Modified: trunk/SKDocumentController.m
===================================================================
--- trunk/SKDocumentController.m        2010-09-09 10:12:21 UTC (rev 6787)
+++ trunk/SKDocumentController.m        2010-09-09 10:23:16 UTC (rev 6788)
@@ -178,6 +178,10 @@
     return type;
 }
 
+- (Class)documentClassForContentsOfURL:(NSURL *)inAbsoluteURL {
+    return [self documentClassForType:[self typeForContentsOfURL:inAbsoluteURL 
error:NULL]];
+}
+
 static NSData *convertTIFFDataToPDF(NSData *tiffData)
 {
     // this should accept any image data types we're likely to run across, but 
PICT returns a zero size image
@@ -326,8 +330,7 @@
         
         while (path = [dirEnum nextObject]) {
             NSURL *url = [NSURL fileURLWithPath:[basePath 
stringByAppendingPathComponent:path]];
-            NSString *aType = [self typeForContentsOfURL:url error:NULL];
-            if ([self documentClassForType:aType])
+            if ([self documentClassForContentsOfURL:url])
                 doc = [self openDocumentWithContentsOfURL:url 
display:displayDocument error:&error] ?: doc;
         }
         

Modified: trunk/SKMainWindowController_UI.m
===================================================================
--- trunk/SKMainWindowController_UI.m   2010-09-09 10:12:21 UTC (rev 6787)
+++ trunk/SKMainWindowController_UI.m   2010-09-09 10:23:16 UTC (rev 6788)
@@ -71,6 +71,7 @@
 #import "NSColor_SKExtensions.h"
 #import "SKSplitView.h"
 #import "NSEvent_SKExtensions.h"
+#import "SKDocumentController.h"
 
 #define NOTES_KEY       @"notes"
 #define SNAPSHOTS_KEY   @"snapshots"
@@ -1140,9 +1141,9 @@
 - (void)PDFViewOpenPDF:(PDFView *)sender 
forRemoteGoToAction:(PDFActionRemoteGoTo *)action {
     NSURL *fileURL = [action URL];
     NSError *error = nil;
-    NSDocumentController *sdc = [NSDocumentController 
sharedDocumentController];
+    SKDocumentController *sdc = [NSDocumentController 
sharedDocumentController];
     id document = nil;
-    if ([[sdc documentClassForType:[sdc typeForContentsOfURL:fileURL 
error:&error]] isPDFDocument]) {
+    if ([[sdc documentClassForContentsOfURL:fileURL] isPDFDocument]) {
         if (document = [sdc openDocumentWithContentsOfURL:fileURL display:YES 
error:&error]) {
             NSUInteger pageIndex = [action pageIndex];
             if (pageIndex < [[document pdfDocument] pageCount]) {


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

------------------------------------------------------------------------------
This SF.net Dev2Dev email is sponsored by:

Show off your parallel programming skills.
Enter the Intel(R) Threading Challenge 2010.
http://p.sf.net/sfu/intel-thread-sfd
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to