Revision: 3463
          http://skim-app.svn.sourceforge.net/skim-app/?rev=3463&view=rev
Author:   hofman
Date:     2008-03-11 07:13:49 -0700 (Tue, 11 Mar 2008)

Log Message:
-----------
Use functions to handle document types, to hide and simplify 10.4/10.5 
compatibility.

Modified Paths:
--------------
    trunk/SKDocument.m
    trunk/SKDocumentController.h
    trunk/SKDocumentController.m
    trunk/SKNotesDocument.m

Modified: trunk/SKDocument.m
===================================================================
--- trunk/SKDocument.m  2008-03-11 13:14:13 UTC (rev 3462)
+++ trunk/SKDocument.m  2008-03-11 14:13:49 UTC (rev 3463)
@@ -220,7 +220,7 @@
         if (formatPopup) {
             NSString *lastExportedType = [[NSUserDefaults 
standardUserDefaults] stringForKey:SKLastExportedTypeKey];
             if ([[self pdfDocument] allowsPrinting] == NO) {
-                int idx = [formatPopup 
indexOfItemWithRepresentedObject:SKEmbeddedPDFDocumentType];
+                int idx = [formatPopup 
indexOfItemWithRepresentedObject:SKGetEmbeddedPDFDocumentType()];
                 if (idx != -1)
                     [formatPopup removeItemAtIndex:idx];
             }
@@ -261,7 +261,7 @@
     NSError *error = nil;
     
     // we check for notes and may save a .skim as well:
-    if ([typeName isEqualToString:SKPDFDocumentType] || [typeName 
isEqual:SKPDFDocumentUTI]) {
+    if (SKIsPDFDocumentType(typeName)) {
         
         NSFileManager *fm = [NSFileManager defaultManager];
         
@@ -287,7 +287,7 @@
                 
                 if (saveNotesOK) {
                     NSString *tmpPath = [NSTemporaryDirectory() 
stringByAppendingPathComponent:[[NSProcessInfo processInfo] 
globallyUniqueString]];
-                    if ([[self notes] count] == 0 || [self writeToURL:[NSURL 
fileURLWithPath:tmpPath] ofType:SKNotesDocumentType error:NULL]) {
+                    if ([[self notes] count] == 0 || [self writeToURL:[NSURL 
fileURLWithPath:tmpPath] ofType:SKGetNotesDocumentType() error:NULL]) {
                         if (fileExists)
                             saveNotesOK = [fm removeFileAtPath:notesPath 
handler:nil];
                         if ([[self notes] count]) {
@@ -317,7 +317,7 @@
                     postNotificationName:SKSkimFileDidSaveNotification 
object:[absoluteURL path]];
         }
         
-    } else if ([typeName isEqualToString:SKPDFBundleDocumentType] || [typeName 
isEqual:SKPDFBundleDocumentUTI]) {
+    } else if (SKIsPDFBundleDocumentType(typeName)) {
         
         NSFileManager *fm = [NSFileManager defaultManager];
         NSString *path = [absoluteURL path];
@@ -410,13 +410,13 @@
     [[NSNotificationCenter defaultCenter] 
postNotificationName:SKDocumentWillSaveNotification object:self];
     BOOL didWrite = NO;
     NSError *error = nil;
-    if ([typeName isEqualToString:SKPDFDocumentType] || [typeName 
isEqualToString:SKPDFDocumentUTI]) {
+    if (SKIsPDFDocumentType(typeName)) {
         didWrite = [pdfData writeToURL:absoluteURL options:0 error:&error];
         // notes are only saved as a dry-run to test if we can write, they are 
not copied to the final destination. 
         // if we automatically save a .skim backup we silently ignore this 
problem
         if (didWrite && NO == [[NSUserDefaults standardUserDefaults] 
boolForKey:SKAutoSaveSkimNotesKey])
             didWrite = [self saveNotesToExtendedAttributesAtURL:absoluteURL 
error:&error];
-    } else if ([typeName isEqualToString:SKPDFBundleDocumentType] || [typeName 
isEqualToString:SKPDFBundleDocumentUTI]) {
+    } else if (SKIsPDFBundleDocumentType(typeName)) {
         NSString *name = [[[absoluteURL path] lastPathComponent] 
stringByDeletingPathExtension];
         if ([name caseInsensitiveCompare:BUNDLE_DATA_FILENAME] == 
NSOrderedSame)
             name = [name stringByAppendingString:@"1"];
@@ -439,40 +439,40 @@
         }
         didWrite = [fileWrapper writeToFile:[absoluteURL path] atomically:NO 
updateFilenames:NO];
         [fileWrapper release];
-    } else if ([typeName isEqualToString:SKEmbeddedPDFDocumentType] || 
[typeName isEqualToString:SKEmbeddedPDFDocumentUTI]) {
+    } else if (SKIsEmbeddedPDFDocumentType(typeName)) {
         [[self mainWindowController] removeTemporaryAnnotations];
         didWrite = [[self pdfDocument] writeToURL:absoluteURL];
-    } else if ([typeName isEqualToString:SKBarePDFDocumentType] || [typeName 
isEqualToString:SKBarePDFDocumentUTI]) {
+    } else if (SKIsBarePDFDocumentType(typeName)) {
         didWrite = [pdfData writeToURL:absoluteURL options:0 error:&error];
-    } else if ([typeName isEqualToString:SKNotesDocumentType] || [typeName 
isEqualToString:SKNotesDocumentUTI]) {
+    } else if (SKIsNotesDocumentType(typeName)) {
         NSData *data = [self notesData];
         if (data)
             didWrite = [data writeToURL:absoluteURL options:0 error:&error];
         else
             error = [NSError errorWithDomain:SKDocumentErrorDomain code:1 
userInfo:[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Unable 
to write notes", @"Error description"), NSLocalizedDescriptionKey, nil]];
             
-    } else if ([typeName isEqualToString:SKNotesRTFDocumentType] || [typeName 
isEqualToString:SKPDFDocumentUTI]) {
+    } else if (SKIsNotesRTFDocumentType(typeName)) {
         NSData *data = [self notesRTFData];
         if (data)
             didWrite = [data writeToURL:absoluteURL options:0 error:&error];
         else
             error = [NSError errorWithDomain:SKDocumentErrorDomain code:1 
userInfo:[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Unable 
to write notes as RTF", @"Error description"), NSLocalizedDescriptionKey, nil]];
-    } else if ([typeName isEqualToString:SKNotesRTFDDocumentType] || [typeName 
isEqualToString:SKRTFDDocumentUTI]) {
+    } else if (SKIsNotesRTFDDocumentType(typeName)) {
         NSFileWrapper *fileWrapper = [self notesRTFDFileWrapper];
         if (fileWrapper)
             didWrite = [fileWrapper writeToFile:[absoluteURL path] 
atomically:NO updateFilenames:NO];
         else
             error = [NSError errorWithDomain:SKDocumentErrorDomain code:1 
userInfo:[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Unable 
to write notes as RTFD", @"Error description"), NSLocalizedDescriptionKey, 
nil]];
-    } else if ([typeName isEqualToString:SKNotesTextDocumentType] || [typeName 
isEqualToString:SKTextDocumentUTI]) {
+    } else if (SKIsNotesTextDocumentType(typeName)) {
         NSString *string = [self notesString];
         if (string)
             didWrite = [string writeToURL:absoluteURL atomically:YES 
encoding:NSUTF8StringEncoding error:&error];
         else
             error = [NSError errorWithDomain:SKDocumentErrorDomain code:1 
userInfo:[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Unable 
to write notes as text", @"Error description"), NSLocalizedDescriptionKey, 
nil]];
-    } else if ([typeName isEqualToString:SKNotesFDFDocumentType] || [typeName 
isEqualToString:SKFDFDocumentUTI]) {
+    } else if (SKIsNotesFDFDocumentType(typeName)) {
         NSString *filePath = [[self fileURL] path];
         NSString *filename = [filePath lastPathComponent];
-        if (filename && ([[self fileType] 
isEqualToString:SKPDFBundleDocumentType] || [[self fileType] 
isEqualToString:SKPDFBundleDocumentUTI])) {
+        if (filename && SKIsPDFBundleDocumentType([self fileType])) {
             NSString *pdfFile = [[NSFileManager defaultManager] 
subfileWithExtension:@"pdf" inPDFBundleAtPath:filePath];
             filename = pdfFile ? [filename 
stringByAppendingPathComponent:pdfFile] : nil;
         }
@@ -527,22 +527,21 @@
     NSMutableDictionary *dict = [[[super 
fileAttributesToWriteToURL:absoluteURL ofType:typeName 
forSaveOperation:saveOperation originalContentsURL:absoluteOriginalContentsURL 
error:outError] mutableCopy] autorelease];
     
     // only set the creator code for our native types
-    if ([[NSUserDefaults standardUserDefaults] 
boolForKey:SKShouldSetCreatorCodeKey] && ([typeName 
isEqualToString:SKPDFDocumentType] || [typeName 
isEqualToString:SKPDFBundleDocumentType] || [typeName 
isEqualToString:SKNotesDocumentType]))
+    if ([[NSUserDefaults standardUserDefaults] 
boolForKey:SKShouldSetCreatorCodeKey] && (SKIsPDFDocumentType(typeName) || 
SKIsPDFBundleDocumentType(typeName) || SKIsNotesDocumentType(typeName)))
         [dict setObject:[NSNumber numberWithUnsignedLong:'SKim'] 
forKey:NSFileHFSCreatorCode];
     
     if ([[[absoluteURL path] pathExtension] isEqualToString:@"pdf"] || 
-        [typeName isEqualToString:SKPDFDocumentType] || [typeName 
isEqualToString:SKEmbeddedPDFDocumentType] || [typeName 
isEqualToString:SKBarePDFDocumentType] ||
-        [typeName isEqualToString:SKPDFDocumentUTI] || [typeName 
isEqualToString:SKEmbeddedPDFDocumentUTI] || [typeName 
isEqualToString:SKBarePDFDocumentUTI])
+        SKIsPDFDocumentType(typeName) || SKIsEmbeddedPDFDocumentType(typeName) 
|| SKIsBarePDFDocumentType(typeName))
         [dict setObject:[NSNumber numberWithUnsignedLong:'PDF '] 
forKey:NSFileHFSTypeCode];
-    else if ([[[absoluteURL path] pathExtension] isEqualToString:@"pdfd"] || 
[typeName isEqualToString:SKPDFBundleDocumentType] || [typeName 
isEqualToString:SKPDFBundleDocumentUTI])
+    else if ([[[absoluteURL path] pathExtension] isEqualToString:@"pdfd"] || 
SKIsPDFBundleDocumentType(typeName))
         [dict setObject:[NSNumber numberWithUnsignedLong:'PDFD'] 
forKey:NSFileHFSTypeCode];
-    else if ([[[absoluteURL path] pathExtension] isEqualToString:@"skim"] || 
[typeName isEqualToString:SKNotesDocumentType] || [typeName 
isEqualToString:SKNotesDocumentUTI])
+    else if ([[[absoluteURL path] pathExtension] isEqualToString:@"skim"] || 
SKIsNotesDocumentType(typeName))
         [dict setObject:[NSNumber numberWithUnsignedLong:'SKNT'] 
forKey:NSFileHFSTypeCode];
-    else if ([[[absoluteURL path] pathExtension] isEqualToString:@"fdf"] || 
[typeName isEqualToString:SKNotesFDFDocumentType] || [typeName 
isEqualToString:SKFDFDocumentUTI])
+    else if ([[[absoluteURL path] pathExtension] isEqualToString:@"fdf"] || 
SKIsNotesFDFDocumentType(typeName))
         [dict setObject:[NSNumber numberWithUnsignedLong:'FDF '] 
forKey:NSFileHFSTypeCode];
-    else if ([[[absoluteURL path] pathExtension] isEqualToString:@"rtf"] || 
[typeName isEqualToString:SKNotesRTFDocumentType] || [typeName 
isEqualToString:SKRTFDocumentUTI])
+    else if ([[[absoluteURL path] pathExtension] isEqualToString:@"rtf"] || 
SKIsNotesRTFDocumentType(typeName))
         [dict setObject:[NSNumber numberWithUnsignedLong:'RTF '] 
forKey:NSFileHFSTypeCode];
-    else if ([[[absoluteURL path] pathExtension] isEqualToString:@"txt"] || 
[typeName isEqualToString:SKNotesTextDocumentType] || [typeName 
isEqualToString:SKTextDocumentUTI])
+    else if ([[[absoluteURL path] pathExtension] isEqualToString:@"txt"] || 
SKIsNotesTextDocumentType(typeName))
         [dict setObject:[NSNumber numberWithUnsignedLong:'TEXT'] 
forKey:NSFileHFSTypeCode];
     
     return dict;
@@ -591,7 +590,7 @@
     [self setPDFDoc:nil];
     [self setNoteDicts:nil];
     
-    if ([docType isEqualToString:SKPostScriptDocumentType] || [docType 
isEqualToString:SKPostScriptDocumentUTI]) {
+    if (SKIsPostScriptDocumentType(docType)) {
         SKPSProgressController *psProgressController = 
[[[SKPSProgressController alloc] init] autorelease];
         data = [psProgressController PDFDataWithPostScriptData:data];
     }
@@ -624,7 +623,7 @@
     [self setPDFDoc:nil];
     [self setNoteDicts:nil];
     
-    if ([docType isEqualToString:SKPDFDocumentType] || [docType 
isEqualToString:SKPDFDocumentUTI]) {
+    if (SKIsPDFDocumentType(docType)) {
         if ((data = [[NSData alloc] initWithContentsOfURL:absoluteURL 
options:NSUncachedRead error:&error]) &&
             (pdfDoc = [[PDFDocument alloc] initWithURL:absoluteURL])) {
             if ([self readNotesFromExtendedAttributesAtURL:absoluteURL 
error:&error] == NO) {
@@ -661,7 +660,7 @@
                 }
             }
         }
-    } else if ([docType isEqualToString:SKPDFBundleDocumentType] || [docType 
isEqualToString:SKPDFBundleDocumentUTI]) {
+    } else if (SKIsPDFBundleDocumentType(docType)) {
         NSString *path = [absoluteURL path];
         NSString *pdfFile = [[NSFileManager defaultManager] 
subfileWithExtension:@"pdf" inPDFBundleAtPath:path];
         if (pdfFile) {
@@ -676,14 +675,14 @@
                 }
             }
         }
-    } else if ([docType isEqualToString:SKPostScriptDocumentType] || [docType 
isEqualToString:SKPostScriptDocumentUTI]) {
+    } else if (SKIsPostScriptDocumentType(docType)) {
         if (data = [NSData dataWithContentsOfURL:absoluteURL 
options:NSUncachedRead error:&error]) {
             SKPSProgressController *psProgressController = 
[[SKPSProgressController alloc] init];
             if (data = [[psProgressController PDFDataWithPostScriptData:data] 
retain])
                 pdfDoc = [[PDFDocument alloc] initWithData:data];
             [psProgressController autorelease];
         }
-    } else if ([docType isEqualToString:SKDVIDocumentType] || [docType 
isEqualToString:SKDVIDocumentUTI]) {
+    } else if (SKIsDVIDocumentType(docType)) {
         if (data = [NSData dataWithContentsOfURL:absoluteURL 
options:NSUncachedRead error:&error]) {
             SKDVIProgressController *dviProgressController = 
[[SKDVIProgressController alloc] init];
             if (data = [[dviProgressController PDFDataWithDVIFile:[absoluteURL 
path]] retain])
@@ -1512,7 +1511,7 @@
 - (NSString *)notesFDFString {
     NSString *filePath = [[self fileURL] path];
     NSString *filename = [filePath lastPathComponent];
-    if (filename && ([[self fileType] isEqualToString:SKPDFBundleDocumentType] 
|| [[self fileType] isEqualToString:SKPDFBundleDocumentUTI])) {
+    if (filename && SKIsPDFBundleDocumentType([self fileType])) {
         NSString *pdfFile = [[NSFileManager defaultManager] 
subfileWithExtension:@"pdf" inPDFBundleAtPath:filePath];
         filename = pdfFile ? [filename stringByAppendingPathComponent:pdfFile] 
: nil;
     }

Modified: trunk/SKDocumentController.h
===================================================================
--- trunk/SKDocumentController.h        2008-03-11 13:14:13 UTC (rev 3462)
+++ trunk/SKDocumentController.h        2008-03-11 14:13:49 UTC (rev 3463)
@@ -38,30 +38,32 @@
 
 #import <Cocoa/Cocoa.h>
 
-extern NSString *SKPDFDocumentType;
-extern NSString *SKPDFBundleDocumentType;
-extern NSString *SKEmbeddedPDFDocumentType;
-extern NSString *SKBarePDFDocumentType;
-extern NSString *SKNotesDocumentType;
-extern NSString *SKNotesTextDocumentType;
-extern NSString *SKNotesRTFDocumentType;
-extern NSString *SKNotesRTFDDocumentType;
-extern NSString *SKNotesFDFDocumentType;
-extern NSString *SKPostScriptDocumentType;
-extern NSString *SKDVIDocumentType;
+// these functions are compatible for 10.4 and 10.5
 
-extern NSString *SKPDFDocumentUTI;
-extern NSString *SKPDFBundleDocumentUTI;
-extern NSString *SKEmbeddedPDFDocumentUTI;
-extern NSString *SKBarePDFDocumentUTI;
-extern NSString *SKNotesDocumentUTI;
-extern NSString *SKTextDocumentUTI;
-extern NSString *SKRTFDocumentUTI;
-extern NSString *SKRTFDDocumentUTI;
-extern NSString *SKFDFDocumentUTI;
-extern NSString *SKPostScriptDocumentUTI;
-extern NSString *SKDVIDocumentUTI;
+extern BOOL SKIsPDFDocumentType(NSString *docType);
+extern BOOL SKIsPDFBundleDocumentType(NSString *docType);
+extern BOOL SKIsEmbeddedPDFDocumentType(NSString *docType);
+extern BOOL SKIsBarePDFDocumentType(NSString *docType);
+extern BOOL SKIsNotesDocumentType(NSString *docType);
+extern BOOL SKIsNotesTextDocumentType(NSString *docType);
+extern BOOL SKIsNotesRTFDocumentType(NSString *docType);
+extern BOOL SKIsNotesRTFDDocumentType(NSString *docType);
+extern BOOL SKIsNotesFDFDocumentType(NSString *docType);
+extern BOOL SKIsPostScriptDocumentType(NSString *docType);
+extern BOOL SKIsDVIDocumentType(NSString *docType);
 
+extern NSString *SKGetPDFDocumentType();
+extern NSString *SKGetPDFBundleDocumentType();
+extern NSString *SKGetEmbeddedPDFDocumentType();
+extern NSString *SKGetBarePDFDocumentType();
+extern NSString *SKGetNotesDocumentType();
+extern NSString *SKGetNotesTextDocumentType();
+extern NSString *SKGetNotesRTFDocumentType();
+extern NSString *SKGetNotesRTFDDocumentType();
+extern NSString *SKGetNotesFDFDocumentType();
+extern NSString *SKGetPostScriptDocumentType();
+extern NSString *SKGetDVIDocumentType();
+
 enum {
     SKImagePboardTypesMask = 1,
     SKURLPboardTypesMask = 2

Modified: trunk/SKDocumentController.m
===================================================================
--- trunk/SKDocumentController.m        2008-03-11 13:14:13 UTC (rev 3462)
+++ trunk/SKDocumentController.m        2008-03-11 14:13:49 UTC (rev 3463)
@@ -45,30 +45,98 @@
 #import "OBUtilities.h"
 
 // See CFBundleTypeName in Info.plist
-NSString *SKPDFDocumentType = nil; /* set to NSPDFPboardType, not 
@"NSPDFPboardType" */
-NSString *SKPDFBundleDocumentType = @"PDF Bundle";
-NSString *SKEmbeddedPDFDocumentType = @"PDF With Embedded Notes";
-NSString *SKBarePDFDocumentType = @"PDF Without Notes";
-NSString *SKNotesDocumentType = @"Skim Notes";
-NSString *SKNotesTextDocumentType = @"Notes as Text";
-NSString *SKNotesRTFDocumentType = @"Notes as RTF";
-NSString *SKNotesRTFDDocumentType = @"Notes as RTFD";
-NSString *SKNotesFDFDocumentType = @"Notes as FDF";
-NSString *SKPostScriptDocumentType = @"PostScript document";
-NSString *SKDVIDocumentType = @"DVI document";
+static NSString *SKPDFDocumentType = nil; /* set to NSPDFPboardType, not 
@"NSPDFPboardType" */
+static NSString *SKPDFBundleDocumentType = @"PDF Bundle";
+static NSString *SKEmbeddedPDFDocumentType = @"PDF With Embedded Notes";
+static NSString *SKBarePDFDocumentType = @"PDF Without Notes";
+static NSString *SKNotesDocumentType = @"Skim Notes";
+static NSString *SKNotesTextDocumentType = @"Notes as Text";
+static NSString *SKNotesRTFDocumentType = @"Notes as RTF";
+static NSString *SKNotesRTFDDocumentType = @"Notes as RTFD";
+static NSString *SKNotesFDFDocumentType = @"Notes as FDF";
+static NSString *SKPostScriptDocumentType = @"PostScript document";
+static NSString *SKDVIDocumentType = @"DVI document";
 
-NSString *SKPDFDocumentUTI = @"com.adobe.pdf";
-NSString *SKPDFBundleDocumentUTI = @"net.sourceforge.skim-app.pdfd";
-NSString *SKEmbeddedPDFDocumentUTI = @"net.sourceforge.skim-app.embedded.pdf";
-NSString *SKBarePDFDocumentUTI = @"net.sourceforge.skim-app.bare.pdf";
-NSString *SKNotesDocumentUTI = @"net.sourceforge.skim-app.skimnotes";
-NSString *SKTextDocumentUTI = @"public.plain-text";
-NSString *SKRTFDocumentUTI = @"com.apple.rtf";
-NSString *SKRTFDDocumentUTI = @"com.apple.rtfd";
-NSString *SKFDFDocumentUTI = @"com.adobe.fdf"; // I don't know the UTI for 
fdf, is there one?
-NSString *SKPostScriptDocumentUTI = @"com.adobe.postscript";
-NSString *SKDVIDocumentUTI = @"net.sourceforge.skim-app.dvi"; // I don't know 
the UTI for dvi, is there one?
+static NSString *SKPDFDocumentUTI = @"com.adobe.pdf";
+static NSString *SKPDFBundleDocumentUTI = @"net.sourceforge.skim-app.pdfd";
+static NSString *SKEmbeddedPDFDocumentUTI = 
@"net.sourceforge.skim-app.embedded.pdf";
+static NSString *SKBarePDFDocumentUTI = @"net.sourceforge.skim-app.bare.pdf";
+static NSString *SKNotesDocumentUTI = @"net.sourceforge.skim-app.skimnotes";
+static NSString *SKTextDocumentUTI = @"public.plain-text";
+static NSString *SKRTFDocumentUTI = @"com.apple.rtf";
+static NSString *SKRTFDDocumentUTI = @"com.apple.rtfd";
+static NSString *SKFDFDocumentUTI = @"com.adobe.fdf"; // I don't know the UTI 
for fdf, is there one?
+static NSString *SKPostScriptDocumentUTI = @"com.adobe.postscript";
+static NSString *SKDVIDocumentUTI = @"net.sourceforge.skim-app.dvi"; // I 
don't know the UTI for dvi, is there one?
 
+BOOL SKIsPDFDocumentType(NSString *docType) {
+    return [docType isEqualToString:SKPDFDocumentType] || [docType 
isEqualToString:SKPDFDocumentUTI];
+}
+BOOL SKIsPDFBundleDocumentType(NSString *docType) {
+    return [docType isEqualToString:SKPDFBundleDocumentType] || [docType 
isEqualToString:SKPDFBundleDocumentUTI];
+}
+BOOL SKIsEmbeddedPDFDocumentType(NSString *docType) {
+    return [docType isEqualToString:SKEmbeddedPDFDocumentType] || [docType 
isEqualToString:SKEmbeddedPDFDocumentUTI];
+}
+BOOL SKIsBarePDFDocumentType(NSString *docType) {
+    return [docType isEqualToString:SKBarePDFDocumentType] || [docType 
isEqualToString:SKBarePDFDocumentUTI];
+}
+BOOL SKIsNotesDocumentType(NSString *docType) {
+    return [docType isEqualToString:SKNotesDocumentType] || [docType 
isEqualToString:SKNotesDocumentUTI];
+}
+BOOL SKIsNotesTextDocumentType(NSString *docType) {
+    return [docType isEqualToString:SKNotesTextDocumentType] || [docType 
isEqualToString:SKTextDocumentUTI];
+}
+BOOL SKIsNotesRTFDocumentType(NSString *docType) {
+    return [docType isEqualToString:SKNotesRTFDocumentType] || [docType 
isEqualToString:SKRTFDocumentUTI];
+}
+BOOL SKIsNotesRTFDDocumentType(NSString *docType) {
+    return [docType isEqualToString:SKNotesRTFDDocumentType] || [docType 
isEqualToString:SKRTFDDocumentUTI];
+}
+BOOL SKIsNotesFDFDocumentType(NSString *docType) {
+    return [docType isEqualToString:SKNotesFDFDocumentType] || [docType 
isEqualToString:SKFDFDocumentUTI];
+}
+BOOL SKIsPostScriptDocumentType(NSString *docType) {
+    return [docType isEqualToString:SKPostScriptDocumentType] || [docType 
isEqualToString:SKPostScriptDocumentUTI];
+}
+BOOL SKIsDVIDocumentType(NSString *docType) {
+    return [docType isEqualToString:SKDVIDocumentType] || [docType 
isEqualToString:SKDVIDocumentUTI];
+}
+
+NSString *SKGetPDFDocumentType(void) {
+    return floor(NSAppKitVersionNumber) <= NSAppKitVersionNumber10_4 ? 
SKPDFDocumentType : SKPDFDocumentUTI;
+}
+NSString *SKGetPDFBundleDocumentType(void) {
+    return floor(NSAppKitVersionNumber) <= NSAppKitVersionNumber10_4 ? 
SKPDFBundleDocumentType : SKPDFBundleDocumentUTI;
+}
+NSString *SKGetEmbeddedPDFDocumentType(void) {
+    return floor(NSAppKitVersionNumber) <= NSAppKitVersionNumber10_4 ? 
SKEmbeddedPDFDocumentType : SKEmbeddedPDFDocumentUTI;
+}
+NSString *SKGetBarePDFDocumentType(void) {
+    return floor(NSAppKitVersionNumber) <= NSAppKitVersionNumber10_4 ? 
SKBarePDFDocumentType : SKBarePDFDocumentUTI;
+}
+NSString *SKGetNotesDocumentType(void) {
+    return floor(NSAppKitVersionNumber) <= NSAppKitVersionNumber10_4 ? 
SKNotesDocumentType : SKNotesDocumentUTI;
+}
+NSString *SKGetNotesTextDocumentType(void) {
+    return floor(NSAppKitVersionNumber) <= NSAppKitVersionNumber10_4 ? 
SKNotesTextDocumentType : SKTextDocumentUTI;
+}
+NSString *SKGetNotesRTFDocumentType(void) {
+    return floor(NSAppKitVersionNumber) <= NSAppKitVersionNumber10_4 ? 
SKNotesRTFDocumentType : SKRTFDocumentUTI;
+}
+NSString *SKGetNotesRTFDDocumentType(void) {
+    return floor(NSAppKitVersionNumber) <= NSAppKitVersionNumber10_4 ? 
SKNotesRTFDDocumentType : SKRTFDDocumentUTI;
+}
+NSString *SKGetNotesFDFDocumentType(void) {
+    return floor(NSAppKitVersionNumber) <= NSAppKitVersionNumber10_4 ? 
SKNotesFDFDocumentType : SKFDFDocumentUTI;
+}
+NSString *SKGetPostScriptDocumentType(void) {
+    return floor(NSAppKitVersionNumber) <= NSAppKitVersionNumber10_4 ? 
SKPostScriptDocumentType : SKPostScriptDocumentUTI;
+}
+NSString *SKGetDVIDocumentType(void) {
+    return floor(NSAppKitVersionNumber) <= NSAppKitVersionNumber10_4 ? 
SKDVIDocumentType : SKDVIDocumentUTI;
+}
+
 @implementation SKDocumentController
 
 + (void)initialize {
@@ -80,22 +148,14 @@
 
 - (NSString *)typeFromFileExtension:(NSString *)fileExtensionOrHFSFileType {
        NSString *type = [super 
typeFromFileExtension:fileExtensionOrHFSFileType];
-    if ([type isEqualToString:SKEmbeddedPDFDocumentType] || [type 
isEqualToString:SKBarePDFDocumentType]) {
-        // fix of bug when reading a PDF file
+    if (SKIsEmbeddedPDFDocumentType(type) || SKIsBarePDFDocumentType(type)) {
+        // fix of bug when reading a PDF file on 10.4
         // this is interpreted as SKEmbeddedPDFDocumentType, even though we 
don't declare that as a readable type
-        type = NSPDFPboardType;
+        type = SKGetPDFDocumentType();
     }
        return type;
 }
 
-static inline NSString *SKPDFDocumentTypeOrUTI(void) {
-    return floor(NSAppKitVersionNumber) <= NSAppKitVersionNumber10_4 ? 
SKPDFDocumentType : SKPDFDocumentUTI;
-}
-
-static inline NSString *SKPostScriptDocumentTypeOrUTI(void) {
-    return floor(NSAppKitVersionNumber) <= NSAppKitVersionNumber10_4 ? 
SKPostScriptDocumentType : SKPostScriptDocumentUTI;
-}
-
 - (NSString *)typeForContentsOfURL:(NSURL *)inAbsoluteURL error:(NSError 
**)outError {
     unsigned int headerLength = 5;
     
@@ -113,15 +173,15 @@
     NSError *error = nil;
     NSString *type = [super typeForContentsOfURL:inAbsoluteURL error:&error];
     
-    if (type == nil || [type isEqualToString:SKNotesTextDocumentType] || [type 
isEqualToString:SKTextDocumentUTI]) {
+    if (type == nil || SKIsNotesTextDocumentType(type)) {
         if ([inAbsoluteURL isFileURL]) {
             NSString *fileName = [inAbsoluteURL path];
             NSFileHandle *fh = [NSFileHandle 
fileHandleForReadingAtPath:fileName];
             NSData *leadingData = [fh readDataOfLength:headerLength];
             if ([leadingData length] >= [pdfHeaderData length] && 
[pdfHeaderData isEqual:[leadingData subdataWithRange:NSMakeRange(0, 
[pdfHeaderData length])]]) {
-                type = SKPostScriptDocumentTypeOrUTI();
+                type = SKGetPostScriptDocumentType();
             } else if ([leadingData length] >= [psHeaderData length] && 
[psHeaderData isEqual:[leadingData subdataWithRange:NSMakeRange(0, 
[psHeaderData length])]]) {
-                type = SKPostScriptDocumentTypeOrUTI();
+                type = SKGetPostScriptDocumentType();
             }
         }
         if (type == nil && outError)
@@ -180,7 +240,7 @@
             pboardType = NSPDFPboardType;
         }
         
-        NSString *type = [pboardType isEqualToString:NSPostScriptPboardType] ? 
SKPostScriptDocumentTypeOrUTI() : SKPDFDocumentTypeOrUTI();
+        NSString *type = [pboardType isEqualToString:NSPostScriptPboardType] ? 
SKGetPostScriptDocumentType() : SKGetPDFDocumentType();
         NSError *error = nil;
         
         document = [self makeUntitledDocumentOfType:type error:&error];
@@ -227,7 +287,7 @@
 
 - (id)openDocumentWithContentsOfURL:(NSURL *)absoluteURL 
display:(BOOL)displayDocument error:(NSError **)outError {
     NSString *type = [self typeForContentsOfURL:absoluteURL error:NULL];
-    if ([type isEqualToString:SKNotesDocumentType] || [type 
isEqualToString:SKNotesDocumentUTI]) {
+    if (SKIsNotesTextDocumentType(type)) {
         NSAppleEventDescriptor *event = [[NSAppleEventManager 
sharedAppleEventManager] currentAppleEvent];
         if ([event eventID] == kAEOpenDocuments && [event 
descriptorForKeyword:keyAESearchText]) {
             NSString *pdfFile = [[absoluteURL path] 
stringByReplacingPathExtension:@"pdf"];

Modified: trunk/SKNotesDocument.m
===================================================================
--- trunk/SKNotesDocument.m     2008-03-11 13:14:13 UTC (rev 3462)
+++ trunk/SKNotesDocument.m     2008-03-11 14:13:49 UTC (rev 3463)
@@ -91,7 +91,7 @@
 - (NSData *)dataOfType:(NSString *)typeName error:(NSError **)outError {
     NSData *data = nil;
     
-    if ([typeName isEqualToString:SKNotesDocumentType] || [typeName 
isEqualToString:SKNotesDocumentUTI]) {
+    if (SKIsNotesDocumentType(typeName)) {
         NSMutableArray *array = [NSMutableArray arrayWithCapacity:[notes 
count]];
         NSEnumerator *noteEnum = [notes objectEnumerator];
         NSMutableDictionary *note;
@@ -103,9 +103,9 @@
             [note release];
         }
         data = [NSKeyedArchiver archivedDataWithRootObject:array];
-    } else if ([typeName isEqualToString:SKNotesRTFDocumentType] || [typeName 
isEqualToString:SKRTFDocumentUTI]) {
+    } else if (SKIsNotesRTFDocumentType(typeName)) {
         data = [self notesRTFData];
-    } else if ([typeName isEqualToString:SKNotesTextDocumentType] || [typeName 
isEqualToString:SKTextDocumentUTI]) {
+    } else if (SKIsNotesTextDocumentType(typeName)) {
         data = [[self notesString] dataUsingEncoding:NSUTF8StringEncoding];
     }
     
@@ -119,9 +119,9 @@
     BOOL didRead = NO;
     NSArray *array = nil;
     
-    if ([typeName isEqualToString:SKNotesDocumentType] || [typeName 
isEqualToString:SKNotesDocumentUTI]) {
+    if (SKIsNotesDocumentType(typeName)) {
         array = [NSKeyedUnarchiver unarchiveObjectWithData:data];
-    } else if ([typeName isEqualToString:SKNotesFDFDocumentType] || [typeName 
isEqualToString:SKFDFDocumentUTI]) {
+    } else if (SKIsNotesFDFDocumentType(typeName)) {
         array = [SKFDFParser noteDictionariesFromFDFData:data];
     }
     if (array) {
@@ -166,14 +166,14 @@
     NSMutableDictionary *dict = [[[super 
fileAttributesToWriteToURL:absoluteURL ofType:typeName 
forSaveOperation:saveOperation originalContentsURL:absoluteOriginalContentsURL 
error:outError] mutableCopy] autorelease];
     
     // only set the creator code for our native types
-    if ([[NSUserDefaults standardUserDefaults] 
boolForKey:SKShouldSetCreatorCodeKey] && ([typeName 
isEqualToString:SKNotesDocumentType] || [typeName 
isEqualToString:SKNotesDocumentUTI]))
+    if ([[NSUserDefaults standardUserDefaults] 
boolForKey:SKShouldSetCreatorCodeKey] && SKIsNotesDocumentType(typeName))
         [dict setObject:[NSNumber numberWithUnsignedLong:'SKim'] 
forKey:NSFileHFSCreatorCode];
     
-    if ([[[absoluteURL path] pathExtension] isEqualToString:@"skim"] || 
[typeName isEqualToString:SKNotesDocumentType] || [typeName 
isEqualToString:SKNotesDocumentUTI])
+    if ([[[absoluteURL path] pathExtension] isEqualToString:@"skim"] || 
SKIsNotesDocumentType(typeName))
         [dict setObject:[NSNumber numberWithUnsignedLong:'SKNT'] 
forKey:NSFileHFSTypeCode];
-    else if ([[[absoluteURL path] pathExtension] isEqualToString:@"rtf"] || 
[typeName isEqualToString:SKNotesRTFDocumentType] || [typeName 
isEqualToString:SKRTFDocumentUTI])
+    else if ([[[absoluteURL path] pathExtension] isEqualToString:@"rtf"] || 
SKIsNotesRTFDocumentType(typeName))
         [dict setObject:[NSNumber numberWithUnsignedLong:'RTF '] 
forKey:NSFileHFSTypeCode];
-    else if ([[[absoluteURL path] pathExtension] isEqualToString:@"txt"] || 
[typeName isEqualToString:SKNotesTextDocumentType] || [typeName 
isEqualToString:SKTextDocumentUTI])
+    else if ([[[absoluteURL path] pathExtension] isEqualToString:@"txt"] || 
SKIsNotesTextDocumentType(typeName))
         [dict setObject:[NSNumber numberWithUnsignedLong:'TEXT'] 
forKey:NSFileHFSTypeCode];
     
     return dict;


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

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to