Revision: 12360
          http://bibdesk.svn.sourceforge.net/bibdesk/?rev=12360&view=rev
Author:   hofman
Date:     2008-01-08 07:58:32 -0800 (Tue, 08 Jan 2008)

Log Message:
-----------
Use webviewicon for html files. In case texticon is used for a html file, load 
the attributed string on the main thread on Tiger as this is not thread safe.

Modified Paths:
--------------
    trunk/bibdesk_vendorsrc/amaxwell/FileView/FVIcon.m
    trunk/bibdesk_vendorsrc/amaxwell/FileView/FVTextIcon.m
    trunk/bibdesk_vendorsrc/amaxwell/FileView/FVWebViewIcon.m

Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVIcon.m
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVIcon.m  2008-01-08 12:44:43 UTC 
(rev 12359)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVIcon.m  2008-01-08 15:58:32 UTC 
(rev 12360)
@@ -205,6 +205,9 @@
     else if (UTTypeConformsTo(theUTI, kUTTypeMovie)) {
         anIcon = [[FVCGImageIcon allocWithZone:[self zone]] 
initWithQTMovieAtURL:representedURL];
     }
+    else if (UTTypeConformsTo(theUTI, kUTTypeHTML)) {
+        anIcon = [[FVWebViewIcon allocWithZone:[self zone]] 
initWithURL:representedURL];
+    }
     else if ([FVTextIcon canInitWithUTI:(NSString *)theUTI]) {
         anIcon = [[FVTextIcon allocWithZone:[self zone]] 
initWithTextAtURL:representedURL];
     }

Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVTextIcon.m
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVTextIcon.m      2008-01-08 
12:44:43 UTC (rev 12359)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVTextIcon.m      2008-01-08 
15:58:32 UTC (rev 12360)
@@ -262,6 +262,47 @@
     [FVBitmapContextCache disposeOfBitmapContext:ctxt];
 }
 
+- (BOOL)_isHTML
+{
+    FSRef fileRef;
+    OSStatus err = noErr;
+    CFStringRef theUTI = NULL;
+    
+    // convert to an FSRef, to get the UTI of the actual URL
+    const UInt8 *fsPath = (void *)[[_fileURL path] UTF8String];
+    err = FSPathMakeRef(fsPath, &fileRef, NULL);
+    
+    // kLSItemContentType returns a CFStringRef, according to the header
+    if (noErr == err)
+        err = LSCopyItemAttribute(&fileRef, kLSRolesAll, kLSItemContentType, 
(CFTypeRef *)&theUTI);
+            
+    // For a link/alias, get the target's UTI in order to determine which 
concrete subclass to create.  Subclasses that are file-based need to check the 
URL to see if it should be badged using _shouldDrawBadgeForURL, and then call 
_resolvedURLWithURL in order to actually load the file's content.
+    
+    // aliases and symlinks are kUTTypeResolvable, so the alias manager should 
handle either of them
+    if (NULL != theUTI && UTTypeConformsTo(theUTI, kUTTypeResolvable)) {
+        Boolean isFolder, wasAliased;
+        err = FSResolveAliasFileWithMountFlags(&fileRef, TRUE, &isFolder, 
&wasAliased, kARMNoUI);
+        // don't change the UTI if it couldn't be resolved; in that case, we 
should just show a finder icon
+        if (noErr == err) {
+            CFRelease(theUTI);
+            theUTI = NULL;
+            err = LSCopyItemAttribute(&fileRef, kLSRolesAll, 
kLSItemContentType, (CFTypeRef *)&theUTI);
+        }
+    }
+    
+    return NULL != theUTI && UTTypeConformsTo(theUTI, kUTTypeHTML);
+}
+
+- (void)_loadHTML:(NSMutableDictionary *)HTMLDict {
+    NSDictionary *documentAttributes = nil;
+    NSAttributedString *attrString = [[NSAttributedString alloc] 
initWithURL:_fileURL documentAttributes:&documentAttributes];
+    if (attrString)
+        [HTMLDict setObject:attrString forKey:@"attributedString"];
+    if (documentAttributes)
+        [HTMLDict setObject:documentAttributes forKey:@"documentAttributes"];
+    [attrString release];
+}
+
 - (void)renderOffscreen
 {
     // hold the lock to let needsRenderForSize: know that this icon doesn't 
need rendering
@@ -294,9 +335,19 @@
     // originally kept the attributed string as an ivar, but it's not worth it 
in most cases
     
     // no need to lock for -fileURL since it's invariant
-    NSDictionary *documentAttributes;
-    NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] 
initWithURL:_fileURL documentAttributes:&documentAttributes];
+    NSDictionary *documentAttributes = nil;
+    NSMutableAttributedString *attrString = nil;
     
+    // NSAttributedString uses WebKit for HTML, and is not thread safe on Tiger
+    if (floor(NSAppKitVersionNumber) <= NSAppKitVersionNumber10_4 && [self 
_isHTML]) {
+        NSMutableDictionary *HTMLDict = [NSMutableDictionary dictionary];
+        [self performSelectorOnMainThread:@selector(_loadHTML:) 
withObject:HTMLDict waitUntilDone:YES];
+        attrString = [[HTMLDict objectForKey:@"attributedString"] mutableCopy];
+        documentAttributes = [HTMLDict objectForKey:@"documentAttributes"];
+    } else {
+        attrString = [[NSMutableAttributedString alloc] initWithURL:_fileURL 
documentAttributes:&documentAttributes];
+    }
+    
     CGAffineTransform pageTransform = __paperTransform;
     NSSize containerSize = __containerSize;
     NSSize paperSize = __paperSize;

Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVWebViewIcon.m
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVWebViewIcon.m   2008-01-08 
12:44:43 UTC (rev 12359)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVWebViewIcon.m   2008-01-08 
15:58:32 UTC (rev 12360)
@@ -38,6 +38,7 @@
 
 #import "FVWebViewIcon.h"
 #import "FVFinderIcon.h"
+#import "FVTextIcon.h"
 #import <WebKit/WebKit.h>
 #import <SystemConfiguration/SystemConfiguration.h>
 
@@ -104,13 +105,16 @@
 
 - (id)initWithURL:(NSURL *)aURL;
 {    
-    NSParameterAssert(nil != [aURL scheme] && NO == [aURL isFileURL]);
+    NSParameterAssert(nil != [aURL scheme]);
     
     // if this is disabled or not an http URL, return a finder icon instead
-    if (FVWebIconDisabled || NO == [[aURL scheme] isEqualToString:@"http"]) {
+    if (FVWebIconDisabled || (NO == [[aURL scheme] isEqualToString:@"http"] && 
NO == [aURL isFileURL])) {
         NSZone *zone = [self zone];
         [self release];
-        self = [[FVFinderIcon allocWithZone:zone] initWithURLScheme:[aURL 
scheme]];
+        if ([aURL isFileURL])
+            self = [[FVTextIcon allocWithZone:zone] initWithTextAtURL:aURL];
+        else
+            self = [[FVFinderIcon allocWithZone:zone] initWithURLScheme:[aURL 
scheme]];
     }
     else if ((self = [super init])) {
         _httpURL = [aURL copy];
@@ -445,7 +449,10 @@
         [self 
performSelectorOnMainThread:@selector(renderOffscreenOnMainThread) 
withObject:nil waitUntilDone:NO];
     }
     else if (YES == _webviewFailed && nil == _fallbackIcon) {
-        _fallbackIcon = [[FVFinderIcon alloc] initWithURLScheme:[_httpURL 
scheme]];
+        if ([_httpURL isFileURL])
+            _fallbackIcon = [[FVTextIcon alloc] initWithTextAtURL:_httpURL];
+        else
+            _fallbackIcon = [[FVFinderIcon alloc] initWithURLScheme:[_httpURL 
scheme]];
     }
     pthread_mutex_unlock(&_mutex);
 }


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

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit

Reply via email to