Revision: 3146
          http://skim-app.svn.sourceforge.net/skim-app/?rev=3146&view=rev
Author:   hofman
Date:     2007-11-04 08:05:36 -0800 (Sun, 04 Nov 2007)

Log Message:
-----------
Check for UTIs whenever a file type is passed. For future compatibility, 
currently we don't use UTIs.

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

Modified: trunk/SKDocument.m
===================================================================
--- trunk/SKDocument.m  2007-11-04 15:13:59 UTC (rev 3145)
+++ trunk/SKDocument.m  2007-11-04 16:05:36 UTC (rev 3146)
@@ -230,7 +230,7 @@
     BOOL success = NO;
     
     // we check for notes and may save a .skim as well:
-    if ([typeName isEqualToString:SKPDFDocumentType]) {
+    if ([typeName isEqualToString:SKPDFDocumentType] || [typeName 
isEqual:SKPDFDocumentUTI]) {
         
         NSFileManager *fm = [NSFileManager defaultManager];
         
@@ -267,7 +267,7 @@
             }
         }
         
-    } else if ([typeName isEqualToString:SKPDFBundleDocumentType]) {
+    } else if ([typeName isEqualToString:SKPDFBundleDocumentType] || [typeName 
isEqual:SKPDFBundleDocumentUTI]) {
         
         NSFileManager *fm = [NSFileManager defaultManager];
         NSString *path = [absoluteURL path];
@@ -355,11 +355,11 @@
 - (BOOL)writeToURL:(NSURL *)absoluteURL ofType:(NSString *)typeName 
error:(NSError **)outError{
     [[NSNotificationCenter defaultCenter] 
postNotificationName:SKDocumentWillSaveNotification object:self];
     BOOL didWrite = NO;
-    if ([typeName isEqualToString:SKPDFDocumentType]) {
+    if ([typeName isEqualToString:SKPDFDocumentType] || [typeName 
isEqualToString:SKPDFDocumentUTI]) {
         // notes are only saved as a dry-run to test if we can write, they are 
not copied to the final destination. 
         didWrite = [pdfData writeToURL:absoluteURL options:NSAtomicWrite 
error:outError] &&
                    [self saveNotesToExtendedAttributesAtURL:absoluteURL 
error:outError];
-    } else if ([typeName isEqualToString:SKPDFBundleDocumentType]) {
+    } else if ([typeName isEqualToString:SKPDFBundleDocumentType] || [typeName 
isEqualToString:SKPDFBundleDocumentUTI]) {
         NSString *name = [[[absoluteURL path] lastPathComponent] 
stringByDeletingPathExtension];
         if ([name caseInsensitiveCompare:BUNDLE_DATA_FILENAME] == 
NSOrderedSame)
             name = [name stringByAppendingString:@"1"];
@@ -382,37 +382,37 @@
         }
         didWrite = [fileWrapper writeToFile:[absoluteURL path] atomically:NO 
updateFilenames:NO];
         [fileWrapper release];
-    } else if ([typeName isEqualToString:SKEmbeddedPDFDocumentType]) {
+    } else if ([typeName isEqualToString:SKEmbeddedPDFDocumentType] || 
[typeName isEqualToString:SKEmbeddedPDFDocumentUTI]) {
         [[self mainWindowController] removeTemporaryAnnotations];
         didWrite = [[self pdfDocument] writeToURL:absoluteURL];
-    } else if ([typeName isEqualToString:SKBarePDFDocumentType]) {
+    } else if ([typeName isEqualToString:SKBarePDFDocumentType] || [typeName 
isEqualToString:SKBarePDFDocumentUTI]) {
         didWrite = [pdfData writeToURL:absoluteURL options:NSAtomicWrite 
error:outError];
-    } else if ([typeName isEqualToString:SKNotesDocumentType]) {
+    } else if ([typeName isEqualToString:SKNotesDocumentType] || [typeName 
isEqualToString:SKNotesDocumentUTI]) {
         NSData *data = [self notesData];
         if (data)
             didWrite = [data writeToURL:absoluteURL options:NSAtomicWrite 
error:outError];
         else if (outError != NULL)
             *outError = [NSError errorWithDomain:SKDocumentErrorDomain code:1 
userInfo:[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Unable 
to write notes", @"Error description"), NSLocalizedDescriptionKey, nil]];
             
-    } else if ([typeName isEqualToString:SKNotesRTFDocumentType]) {
+    } else if ([typeName isEqualToString:SKNotesRTFDocumentType] || [typeName 
isEqualToString:SKPDFDocumentUTI]) {
         NSData *data = [self notesRTFData];
         if (data)
             didWrite = [data writeToURL:absoluteURL options:NSAtomicWrite 
error:outError];
         else if (outError != NULL)
             *outError = [NSError errorWithDomain:SKDocumentErrorDomain code:1 
userInfo:[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Unable 
to write notes as RTF", @"Error description"), NSLocalizedDescriptionKey, nil]];
-    } else if ([typeName isEqualToString:SKNotesRTFDDocumentType]) {
+    } else if ([typeName isEqualToString:SKNotesRTFDDocumentType] || [typeName 
isEqualToString:SKRTFDDocumentUTI]) {
         NSFileWrapper *fileWrapper = [self notesRTFDFileWrapper];
         if (fileWrapper)
             didWrite = [fileWrapper writeToFile:[absoluteURL path] 
atomically:NO updateFilenames:NO];
         else if (outError != NULL)
             *outError = [NSError errorWithDomain:SKDocumentErrorDomain code:1 
userInfo:[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Unable 
to write notes as RTFD", @"Error description"), NSLocalizedDescriptionKey, 
nil]];
-    } else if ([typeName isEqualToString:SKNotesTextDocumentType]) {
+    } else if ([typeName isEqualToString:SKNotesTextDocumentType] || [typeName 
isEqualToString:SKTextDocumentUTI]) {
         NSString *string = [self notesString];
         if (string)
             didWrite = [string writeToURL:absoluteURL atomically:YES 
encoding:NSUTF8StringEncoding error:outError];
         else if (outError != NULL)
             *outError = [NSError errorWithDomain:SKDocumentErrorDomain code:1 
userInfo:[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Unable 
to write notes as text", @"Error description"), NSLocalizedDescriptionKey, 
nil]];
-    } else if ([typeName isEqualToString:SKNotesFDFDocumentType]) {
+    } else if ([typeName isEqualToString:SKNotesFDFDocumentType] || [typeName 
isEqualToString:SKFDFDocumentUTI]) {
         NSString *filePath = [[self fileURL] path];
         NSString *filename = [filePath lastPathComponent];
         if (filename && [[self fileType] 
isEqualToString:SKPDFBundleDocumentType]) {
@@ -467,17 +467,19 @@
     if ([[NSUserDefaults standardUserDefaults] 
boolForKey:SKShouldSetCreatorCodeKey] && ([typeName 
isEqualToString:SKPDFDocumentType] || [typeName 
isEqualToString:SKPDFBundleDocumentType] || [typeName 
isEqualToString:SKNotesDocumentType]))
         [dict setObject:[NSNumber numberWithUnsignedLong:'SKim'] 
forKey:NSFileHFSCreatorCode];
     
-    if ([[[absoluteURL path] pathExtension] isEqualToString:@"pdf"] || 
([typeName isEqualToString:SKPDFDocumentType] || [typeName 
isEqualToString:SKEmbeddedPDFDocumentType] || [typeName 
isEqualToString:SKBarePDFDocumentType]))
+    if ([[[absoluteURL path] pathExtension] isEqualToString:@"pdf"] || 
+        [typeName isEqualToString:SKPDFDocumentType] || [typeName 
isEqualToString:SKEmbeddedPDFDocumentType] || [typeName 
isEqualToString:SKBarePDFDocumentType] ||
+        [typeName isEqualToString:SKPDFDocumentUTI] || [typeName 
isEqualToString:SKEmbeddedPDFDocumentUTI] || [typeName 
isEqualToString:SKBarePDFDocumentUTI])
         [dict setObject:[NSNumber numberWithUnsignedLong:'PDF '] 
forKey:NSFileHFSTypeCode];
-    else if ([[[absoluteURL path] pathExtension] isEqualToString:@"pdfd"] || 
[typeName isEqualToString:SKPDFBundleDocumentType])
+    else if ([[[absoluteURL path] pathExtension] isEqualToString:@"pdfd"] || 
[typeName isEqualToString:SKPDFBundleDocumentType] || [typeName 
isEqualToString:SKPDFBundleDocumentUTI])
         [dict setObject:[NSNumber numberWithUnsignedLong:'PDFD'] 
forKey:NSFileHFSTypeCode];
-    else if ([[[absoluteURL path] pathExtension] isEqualToString:@"skim"] || 
[typeName isEqualToString:SKNotesDocumentType])
+    else if ([[[absoluteURL path] pathExtension] isEqualToString:@"skim"] || 
[typeName isEqualToString:SKNotesDocumentType] || [typeName 
isEqualToString:SKNotesDocumentUTI])
         [dict setObject:[NSNumber numberWithUnsignedLong:'SKNT'] 
forKey:NSFileHFSTypeCode];
-    else if ([[[absoluteURL path] pathExtension] isEqualToString:@"fdf"] || 
[typeName isEqualToString:SKNotesFDFDocumentType])
+    else if ([[[absoluteURL path] pathExtension] isEqualToString:@"fdf"] || 
[typeName isEqualToString:SKNotesFDFDocumentType] || [typeName 
isEqualToString:SKFDFDocumentUTI])
         [dict setObject:[NSNumber numberWithUnsignedLong:'FDF '] 
forKey:NSFileHFSTypeCode];
-    else if ([[[absoluteURL path] pathExtension] isEqualToString:@"rtf"] || 
[typeName isEqualToString:SKNotesRTFDocumentType])
+    else if ([[[absoluteURL path] pathExtension] isEqualToString:@"rtf"] || 
[typeName isEqualToString:SKNotesRTFDocumentType] || [typeName 
isEqualToString:SKRTFDocumentUTI])
         [dict setObject:[NSNumber numberWithUnsignedLong:'RTF '] 
forKey:NSFileHFSTypeCode];
-    else if ([[[absoluteURL path] pathExtension] isEqualToString:@"txt"] || 
[typeName isEqualToString:SKNotesTextDocumentType])
+    else if ([[[absoluteURL path] pathExtension] isEqualToString:@"txt"] || 
[typeName isEqualToString:SKNotesTextDocumentType] || [typeName 
isEqualToString:SKTextDocumentUTI])
         [dict setObject:[NSNumber numberWithUnsignedLong:'TEXT'] 
forKey:NSFileHFSTypeCode];
     
     return dict;
@@ -526,7 +528,7 @@
     [self setPDFDoc:nil];
     [self setNoteDicts:nil];
     
-    if ([docType isEqualToString:SKPostScriptDocumentType]) {
+    if ([docType isEqualToString:SKPostScriptDocumentType] || [docType 
isEqualToString:SKPostScriptDocumentUTI]) {
         SKPSProgressController *psProgressController = 
[[[SKPSProgressController alloc] init] autorelease];
         data = [psProgressController PDFDataWithPostScriptData:data];
     }
@@ -559,7 +561,7 @@
     [self setPDFDoc:nil];
     [self setNoteDicts:nil];
     
-    if ([docType isEqualToString:SKPDFDocumentType]) {
+    if ([docType isEqualToString:SKPDFDocumentType] || [docType 
isEqualToString:SKPDFDocumentType]) {
         if ((data = [[NSData alloc] initWithContentsOfURL:absoluteURL 
options:NSUncachedRead error:&error]) &&
             (pdfDoc = [[PDFDocument alloc] initWithData:data])) {
             if ([self readNotesFromExtendedAttributesAtURL:absoluteURL 
error:&error] == NO) {
@@ -596,7 +598,7 @@
                 }
             }
         }
-    } else if ([docType isEqualToString:SKPDFBundleDocumentType]) {
+    } else if ([docType isEqualToString:SKPDFBundleDocumentType] || [docType 
isEqualToString:SKPDFBundleDocumentType]) {
         NSString *path = [absoluteURL path];
         NSString *pdfFile = [[NSFileManager defaultManager] 
subfileWithExtension:@"pdf" inPDFBundleAtPath:path];
         if (pdfFile) {
@@ -611,14 +613,14 @@
                 }
             }
         }
-    } else if ([docType isEqualToString:SKPostScriptDocumentType]) {
+    } else if ([docType isEqualToString:SKPostScriptDocumentType] || [docType 
isEqualToString:SKPostScriptDocumentType]) {
         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]) {
+    } else if ([docType isEqualToString:SKDVIDocumentType] || [docType 
isEqualToString:SKDVIDocumentType]) {
         if (data = [NSData dataWithContentsOfURL:absoluteURL 
options:NSUncachedRead error:&error]) {
             SKDVIProgressController *dviProgressController = 
[[SKDVIProgressController alloc] init];
             if (data = [[dviProgressController PDFDataWithDVIFile:[absoluteURL 
path]] retain])

Modified: trunk/SKDocumentController.h
===================================================================
--- trunk/SKDocumentController.h        2007-11-04 15:13:59 UTC (rev 3145)
+++ trunk/SKDocumentController.h        2007-11-04 16:05:36 UTC (rev 3146)
@@ -50,6 +50,18 @@
 extern NSString *SKPostScriptDocumentType;
 extern NSString *SKDVIDocumentType;
 
+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;
+
 enum {
     SKImagePboardTypesMask = 1,
     SKURLPboardTypesMask = 2

Modified: trunk/SKDocumentController.m
===================================================================
--- trunk/SKDocumentController.m        2007-11-04 15:13:59 UTC (rev 3145)
+++ trunk/SKDocumentController.m        2007-11-04 16:05:36 UTC (rev 3146)
@@ -57,6 +57,17 @@
 NSString *SKPostScriptDocumentType = @"PostScript document";
 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?
 
 @implementation SKDocumentController
 
@@ -92,7 +103,7 @@
     NSError *error = nil;
     NSString *type = [super typeForContentsOfURL:inAbsoluteURL error:&error];
     
-    if (type == nil || [type isEqualToString:SKNotesRTFDocumentType] || [type 
isEqualToString:SKNotesTextDocumentType]) {
+    if (type == nil || [type isEqualToString:SKNotesTextDocumentType] || [type 
isEqualToString:SKTextDocumentUTI]) {
         if ([inAbsoluteURL isFileURL]) {
             NSString *fileName = [inAbsoluteURL path];
             NSFileHandle *fh = [NSFileHandle 
fileHandleForReadingAtPath:fileName];

Modified: trunk/SKNotesDocument.m
===================================================================
--- trunk/SKNotesDocument.m     2007-11-04 15:13:59 UTC (rev 3145)
+++ trunk/SKNotesDocument.m     2007-11-04 16:05:36 UTC (rev 3146)
@@ -91,7 +91,7 @@
 - (NSData *)dataOfType:(NSString *)typeName error:(NSError **)outError {
     NSData *data = nil;
     
-    if ([typeName isEqualToString:SKNotesDocumentType]) {
+    if ([typeName isEqualToString:SKNotesDocumentType] || [typeName 
isEqualToString:SKNotesDocumentUTI]) {
         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]) {
+    } else if ([typeName isEqualToString:SKNotesRTFDocumentType] || [typeName 
isEqualToString:SKRTFDocumentUTI]) {
         data = [self notesRTFData];
-    } else if ([typeName isEqualToString:SKNotesTextDocumentType]) {
+    } else if ([typeName isEqualToString:SKNotesTextDocumentType] || [typeName 
isEqualToString:SKTextDocumentUTI]) {
         data = [[self notesString] dataUsingEncoding:NSUTF8StringEncoding];
     }
     
@@ -119,9 +119,9 @@
     BOOL didRead = NO;
     NSArray *array = nil;
     
-    if ([typeName isEqualToString:SKNotesDocumentType]) {
+    if ([typeName isEqualToString:SKNotesDocumentType] || [typeName 
isEqualToString:SKNotesDocumentUTI]) {
         array = [NSKeyedUnarchiver unarchiveObjectWithData:data];
-    } else if ([typeName isEqualToString:SKNotesFDFDocumentType]) {
+    } else if ([typeName isEqualToString:SKNotesFDFDocumentType] || [typeName 
isEqualToString:SKFDFDocumentUTI]) {
         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])
+    if ([[NSUserDefaults standardUserDefaults] 
boolForKey:SKShouldSetCreatorCodeKey] && ([typeName 
isEqualToString:SKNotesDocumentType] || [typeName 
isEqualToString:SKNotesDocumentUTI]))
         [dict setObject:[NSNumber numberWithUnsignedLong:'SKim'] 
forKey:NSFileHFSCreatorCode];
     
-    if ([[[absoluteURL path] pathExtension] isEqualToString:@"skim"] || 
[typeName isEqualToString:SKNotesDocumentType])
+    if ([[[absoluteURL path] pathExtension] isEqualToString:@"skim"] || 
[typeName isEqualToString:SKNotesDocumentType] || [typeName 
isEqualToString:SKNotesDocumentUTI])
         [dict setObject:[NSNumber numberWithUnsignedLong:'SKNT'] 
forKey:NSFileHFSTypeCode];
-    else if ([[[absoluteURL path] pathExtension] isEqualToString:@"rtf"] || 
[typeName isEqualToString:SKNotesRTFDocumentType])
+    else if ([[[absoluteURL path] pathExtension] isEqualToString:@"rtf"] || 
[typeName isEqualToString:SKNotesRTFDocumentType] || [typeName 
isEqualToString:SKRTFDocumentUTI])
         [dict setObject:[NSNumber numberWithUnsignedLong:'RTF '] 
forKey:NSFileHFSTypeCode];
-    else if ([[[absoluteURL path] pathExtension] isEqualToString:@"txt"] || 
[typeName isEqualToString:SKNotesTextDocumentType])
+    else if ([[[absoluteURL path] pathExtension] isEqualToString:@"txt"] || 
[typeName isEqualToString:SKNotesTextDocumentType] || [typeName 
isEqualToString:SKTextDocumentUTI])
         [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: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to