Revision: 25420
          http://sourceforge.net/p/bibdesk/svn/25420
Author:   hofman
Date:     2021-01-17 18:24:19 +0000 (Sun, 17 Jan 2021)
Log Message:
-----------
Let the icon classes determine themselves whether they can handle a URL and 
file type. Use a generic class method to determine this.

Modified Paths:
--------------
    trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFinderIcon.m
    trunk/bibdesk_vendorsrc/amaxwell/FileView/FVIcon.m
    trunk/bibdesk_vendorsrc/amaxwell/FileView/FVIcon_Private.h
    trunk/bibdesk_vendorsrc/amaxwell/FileView/FVIcon_Private.m
    trunk/bibdesk_vendorsrc/amaxwell/FileView/FVImageIcon.h
    trunk/bibdesk_vendorsrc/amaxwell/FileView/FVImageIcon.m
    trunk/bibdesk_vendorsrc/amaxwell/FileView/FVMIMEIcon.m
    trunk/bibdesk_vendorsrc/amaxwell/FileView/FVMovieIcon.h
    trunk/bibdesk_vendorsrc/amaxwell/FileView/FVMovieIcon.m
    trunk/bibdesk_vendorsrc/amaxwell/FileView/FVPDFIcon.m
    trunk/bibdesk_vendorsrc/amaxwell/FileView/FVPreviewer.m
    trunk/bibdesk_vendorsrc/amaxwell/FileView/FVQuickLookIcon.m
    trunk/bibdesk_vendorsrc/amaxwell/FileView/FVTextIcon.h
    trunk/bibdesk_vendorsrc/amaxwell/FileView/FVTextIcon.m
    trunk/bibdesk_vendorsrc/amaxwell/FileView/FVWebViewIcon.m

Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFinderIcon.m
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFinderIcon.m    2021-01-17 
15:39:02 UTC (rev 25419)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFinderIcon.m    2021-01-17 
18:24:19 UTC (rev 25420)
@@ -105,6 +105,12 @@
     // no-op
 }
 
++ (BOOL)canInitWithURL:(NSURL *)aURL withType:(NSString *)type
+{
+    // FVFinderIcon can basically handle any type
+    return YES;
+}
+
 - (id)initWithURL:(NSURL *)aURL drawsLinkBadge:(BOOL)drawsLinkBadge {
     [self release];
     if (aURL == nil)

Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVIcon.m
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVIcon.m  2021-01-17 15:39:02 UTC 
(rev 25419)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVIcon.m  2021-01-17 18:24:19 UTC 
(rev 25420)
@@ -156,7 +156,12 @@
         return (id)[FVFinderIcon newMissing];
     }
     else if (NO == [representedURL isFileURL]) {
-        return (id)[[FVWebViewIcon alloc] initWithURL:representedURL];
+        if ([FVWebViewIcon canInitWithURL:representedURL withType:nil])
+            return (id)[[FVWebViewIcon alloc] initWithURL:representedURL];
+        else if ([FVFinderIcon canInitWithURL:representedURL withType:nil])
+            return (id)[[FVFinderIcon alloc] initWithURL:representedURL];
+        else
+            return (id)[FVFinderIcon newMissing];
     }
     
     NSURL *resolvedURL = nil;
@@ -222,6 +227,7 @@
     }
 
     FVIcon *anIcon = nil;
+    NSString *type = (NSString *)theUTI;
     
     /*
      Problems here.  TextMate claims a lot of plain text types but doesn't 
declare a UTI for any of them, 
@@ -230,46 +236,38 @@
      Additionally, files that are named "README" are public.data, but actually 
plain text files.  Since 
      LS doesn't sniff types, we'll just try to open anything that's equal (not 
conforming) to public.data.
      */
-    if ((NULL == theUTI || UTTypeEqual(theUTI, kUTTypeData)) && 
dataPhysicalSize < maximumTextDataSize && [FVTextIcon 
canInitWithURL:resolvedURL]) {
+    if ((NULL == theUTI || UTTypeEqual(theUTI, kUTTypeData)) && 
dataPhysicalSize < maximumTextDataSize && [FVTextIcon 
canInitWithURL:resolvedURL withType:nil]) {
         anIcon = [[FVTextIcon alloc] initWithURL:resolvedURL 
drawsLinkBadge:isLink];
     }
-    else if (UTTypeConformsTo(theUTI, kUTTypePDF)) {
+    else if ([FVPDFIcon canInitWithURL:resolvedURL withType:type]) {
         anIcon = [[FVPDFIcon alloc] initWithURL:resolvedURL 
drawsLinkBadge:isLink];
     }
-    else if (UTTypeConformsTo(theUTI, FVSTR("com.adobe.postscript"))) {
+    else if ([FVPostScriptIcon canInitWithURL:resolvedURL withType:type]) {
         anIcon = [[FVPostScriptIcon alloc] initWithURL:resolvedURL 
drawsLinkBadge:isLink];
     }
-    else if (UTTypeConformsTo(theUTI, FVSTR("net.sourceforge.skim-app.pdfd"))) 
{
+    else if ([FVPDFDIcon canInitWithURL:resolvedURL withType:type]) {
         anIcon = [[FVPDFDIcon alloc] initWithURL:resolvedURL 
drawsLinkBadge:isLink];
     }
-    else if (UTTypeConformsTo(theUTI, kUTTypeImage) && dataPhysicalSize < 
maximumImageDataSize && [FVImageIcon canInitWithUTI:theUTI]) {
+    else if (dataPhysicalSize < maximumImageDataSize && [FVImageIcon 
canInitWithURL:resolvedURL withType:type]) {
         // Acorn's type conforms to public.image but can't be opened by 
ImageIO, so have to make an additional check for cases like this.
         anIcon = [[FVImageIcon alloc] initWithURL:resolvedURL 
drawsLinkBadge:isLink];
     }
-    else if (UTTypeEqual(theUTI, FVSTR("com.microsoft.windows-media-wmv"))) {
-        /* 
-         Flip4Mac WMV plugin puts up a stupid progress bar and calls into 
WebCore, and it gives nothing 
-         if you uncheck "Open local files immediately" in its pref pane.  
Bypass it entirely if we have 
-         Quick Look.  No idea if this is a QT bug or Flip4Mac bug, so I 
suppose I should file something...
-         */
-        anIcon = [[FVQuickLookIcon alloc] initWithURL:resolvedURL 
drawsLinkBadge:isLink];
-    }
-    else if (UTTypeConformsTo(theUTI, kUTTypeMovie) && [FVMovieIcon 
canInitWithURL:resolvedURL]) {
+    else if ([FVMovieIcon canInitWithURL:resolvedURL withType:type]) {
         anIcon = [[FVMovieIcon alloc] initWithURL:resolvedURL 
drawsLinkBadge:isLink];
     }
-    else if (UTTypeConformsTo(theUTI, kUTTypeHTML) || UTTypeConformsTo(theUTI, 
kUTTypeWebArchive)) {
+    else if ([FVWebViewIcon  canInitWithURL:resolvedURL withType:type]) {
         anIcon = [[FVWebViewIcon alloc] initWithURL:resolvedURL];
     }
-    else if (dataPhysicalSize < maximumTextDataSize && [FVTextIcon 
canInitWithUTI:(NSString *)theUTI]) {
+    else if (dataPhysicalSize < maximumTextDataSize && [FVTextIcon 
canInitWithURL:resolvedURL withType:type]) {
         anIcon = [[FVTextIcon alloc] initWithURL:resolvedURL 
drawsLinkBadge:isLink isPlainText:(UTTypeConformsTo(theUTI, kUTTypePlainText))];
     }
     
     // In case some subclass returns nil, fall back to Quick Look.  If 
disabled, it returns nil.
-    if (nil == anIcon)
+    if (nil == anIcon && [FVQuickLookIcon canInitWithURL:resolvedURL 
withType:type])
         anIcon = [[FVQuickLookIcon alloc] initWithURL:resolvedURL 
drawsLinkBadge:isLink];
     
-    // In case all subclasses failed, fall back to a Finder icon.
-    if (nil == anIcon)
+    // In case all subclasses failed, fall back to a Finder icon.  +canInit... 
is a no-op
+    if (nil == anIcon && [FVFinderIcon canInitWithURL:resolvedURL 
withType:type])
         anIcon = [FVFinderIcon newWithURL:resolvedURL drawsLinkBadge:isLink];
     
     [(id)theUTI release];

Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVIcon_Private.h
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVIcon_Private.h  2021-01-17 
15:39:02 UTC (rev 25419)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVIcon_Private.h  2021-01-17 
18:24:19 UTC (rev 25420)
@@ -62,7 +62,18 @@
 + (void)_initializeCategory;
 
 /** @internal
+
+ \warning Concrete subclasses should always override this method, so it is 
basically a primitive method.
  
+ Determines whether a concrete icon subclass can be initialized with the given 
URL and UTI.
+ 
+ @param aURL The URL with which to initialize the icon.
+ @param type The UTI for the URL if this is a file URL.  May be nil, for 
instance for remote URLs.
+*/
++ (BOOL)canInitWithURL:(NSURL *)aURL withType:(NSString *)type;
+
+/** @internal
+ 
  \warning Subclasses should never have a need to override this method.
  
  Call FVIcon::_startRenderingForKey: for classes that should avoid multiple 
render requests for the same icon; useful for multiple views, since the 
operation queue only ensures uniqueness of rendering requests per-view.  
Requires synchronous caching to be effective, and must be called as @code 
[[self class] _startRenderingForKey:aKey] @endcode rather than @code [FVIcon 
_startRenderingForKey:aKey] @endcode in order to achieve proper granularity.  
Each FVIcon::_startRenderingForKey: must be matched by 
FVIcon::_stopRenderingForKey: or bad things will happen. */

Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVIcon_Private.m
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVIcon_Private.m  2021-01-17 
15:39:02 UTC (rev 25419)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVIcon_Private.m  2021-01-17 
18:24:19 UTC (rev 25420)
@@ -122,6 +122,8 @@
     }
 }
 
++ (BOOL)canInitWithURL:(NSURL *)aURL withType:(NSString *)type { return NO; }
+
 + (void)_startRenderingForKey:(id)aKey;
 {
     _FVQueuedKeys *qkeys = [(NSDictionary *)_queuedKeysByClass 
objectForKey:self];

Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVImageIcon.h
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVImageIcon.h     2021-01-17 
15:39:02 UTC (rev 25419)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVImageIcon.h     2021-01-17 
18:24:19 UTC (rev 25420)
@@ -48,7 +48,4 @@
     BOOL            _loadFailed;
     FVIcon         *_fallbackIcon;
 }
-
-+ (BOOL)canInitWithUTI:(CFStringRef)type;
-
 @end

Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVImageIcon.m
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVImageIcon.m     2021-01-17 
15:39:02 UTC (rev 25419)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVImageIcon.m     2021-01-17 
18:24:19 UTC (rev 25420)
@@ -53,19 +53,22 @@
     CFRelease(dict);    
 }
 
-+ (BOOL)canInitWithUTI:(CFStringRef)type
++ (BOOL)canInitWithURL:(NSURL *)aURL withType:(NSString *)type
 {
     NSParameterAssert(type);
     
+    if (false == UTTypeConformsTo((CFStringRef)type, kUTTypeImage))
+        return NO;
+    
     // should never be called in this case, but ImageIO lies about support for 
PDF rdar://problem/5447874
-    if (UTTypeEqual(type, kUTTypePDF)) return NO;
+    if (UTTypeEqual((CFStringRef)type, kUTTypePDF)) return NO;
     
-    BOOL canInit = NO;
-    CFArrayRef types = CGImageSourceCopyTypeIdentifiers();
-    if (types && CFArrayContainsValue(types, CFRangeMake(0, 
CFArrayGetCount(types)), type))
-        canInit = YES;
-    if (types) CFRelease(types);
-    return canInit;
+    static NSArray *types = nil;
+    if (types == nil) {
+        types = (NSArray *)CGImageSourceCopyTypeIdentifiers();
+    }
+    
+    return [types containsObject:type];
 }
 
 - (id)initWithURL:(NSURL *)aURL drawsLinkBadge:(BOOL)drawsLinkBadge

Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVMIMEIcon.m
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVMIMEIcon.m      2021-01-17 
15:39:02 UTC (rev 25419)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVMIMEIcon.m      2021-01-17 
18:24:19 UTC (rev 25420)
@@ -64,6 +64,12 @@
     return icon;
 }
 
++ (BOOL)canInitWithURL:(NSURL *)aURL withType:(NSString *)type
+{
+    // FVMIMEIcon is not initialized from a URL or type
+    return YES;
+}
+
 - (id)initWithMIMEType:(NSString *)type;
 {
     NSAssert2(pthread_main_np() != 0, @"*** threading violation *** +[%@ %@] 
requires main thread", self, NSStringFromSelector(_cmd));

Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVMovieIcon.h
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVMovieIcon.h     2021-01-17 
15:39:02 UTC (rev 25419)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVMovieIcon.h     2021-01-17 
18:24:19 UTC (rev 25420)
@@ -42,6 +42,4 @@
 
 @interface FVMovieIcon : FVImageIcon
 
-+ (BOOL)canInitWithURL:(NSURL *)url;
-
 @end

Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVMovieIcon.m
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVMovieIcon.m     2021-01-17 
15:39:02 UTC (rev 25419)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVMovieIcon.m     2021-01-17 
18:24:19 UTC (rev 25420)
@@ -105,18 +105,39 @@
     return data;
 }
 
-+ (BOOL)canInitWithURL:(NSURL *)url;
++ (BOOL)canInitWithURL:(NSURL *)aURL withType:(NSString *)type
 {
+    if (false == UTTypeConformsTo((CFStringRef)type, kUTTypeMovie))
+        return NO;
+    
+    /*
+     Flip4Mac WMV plugin puts up a stupid progress bar and calls into WebCore, 
and it gives nothing
+     if you uncheck "Open local files immediately" in its pref pane.  Bypass 
it entirely if we have
+     Quick Look.  No idea if this is a QT bug or Flip4Mac bug, so I suppose I 
should file something...
+     */
+    if (UTTypeEqual((CFStringRef)type, 
FVSTR("com.microsoft.windows-media-wmv")))
+        return NO;
+    
 /* @@ QTKit
-    return [QTMovie canInitWithURL:url];
+    return [QTMovie canInitWithURL:aURL];
  */
 #if !defined(MAC_OS_X_VERSION_10_7) || MAC_OS_X_VERSION_MAX_ALLOWED < 
MAC_OS_X_VERSION_10_7
     return NO;
-#elif MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_7
-    return YES;
 #else
-    return floor(NSAppKitVersionNumber) >= NSAppKitVersionNumber10_7;
+#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_7
+    if (floor(NSAppKitVersionNumber) < NSAppKitVersionNumber10_7)
+        return NO;
 #endif
+    static NSArray *types = nil;
+    if (types == nil) {
+        if ([AVURLAsset self])
+            types = [[AVURLAsset audiovisualTypes] copy];
+        else
+            types = [NSArray new];
+    }
+    
+    return [types containsObject:type];
+#endif
 }
 
 - (BOOL)canReleaseResources;
@@ -149,7 +170,7 @@
 - (CGImageRef)_copyImageWhileLocked {
     if ([AVAsset self] == Nil)
         return [super _copyImageWhileLocked];
-    AVAsset *asset = [AVAsset assetWithURL:_fileURL];
+    AVAsset *asset = [[AVURLAsset alloc] initWithURL:_fileURL options:nil];
     AVAssetImageGenerator *imageGenerator = [[AVAssetImageGenerator alloc] 
initWithAsset:asset];
     CMTime time = [asset duration];
     // 4% or 10 seconds, whichever is smaller
@@ -156,6 +177,7 @@
     time.value = MIN(time.value / 25, 10 * (CMTimeValue)time.timescale);
     CGImageRef image = [imageGenerator copyCGImageAtTime:time actualTime:NULL 
error:NULL];
     [imageGenerator release];
+    [asset release];
     return image;
 }
 

Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVPDFIcon.m
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVPDFIcon.m       2021-01-17 
15:39:02 UTC (rev 25419)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVPDFIcon.m       2021-01-17 
18:24:19 UTC (rev 25420)
@@ -124,6 +124,11 @@
     pthread_mutex_unlock(&_releaseLock);    
 }
 
++ (BOOL)canInitWithURL:(NSURL *)aURL withType:(NSString *)type
+{
+    return UTTypeConformsTo((CFStringRef)type, kUTTypePDF);
+}
+
 - (id)initWithURL:(NSURL *)aURL drawsLinkBadge:(BOOL)drawsLinkBadge
 {
     NSParameterAssert([aURL isFileURL]);
@@ -589,6 +594,11 @@
 
 @implementation FVPDFDIcon
 
++ (BOOL)canInitWithURL:(NSURL *)aURL withType:(NSString *)type
+{
+    return UTTypeConformsTo((CFStringRef)type, 
FVSTR("net.sourceforge.skim-app.pdfd"));
+}
+
 static NSURL * __FVCreatePDFURLForPDFBundleURL(NSURL *aURL)
 {
     NSCParameterAssert(pthread_main_np() != 0);
@@ -659,6 +669,11 @@
     [_convertedKeysLock unlock];
 }
 
++ (BOOL)canInitWithURL:(NSURL *)aURL withType:(NSString *)type
+{
+    return UTTypeConformsTo((CFStringRef)type, FVSTR("com.adobe.postscript"));
+}
+
 - (id)initWithURL:(NSURL *)aURL drawsLinkBadge:(BOOL)drawsLinkBadge
 {
     NSParameterAssert([aURL isFileURL]);

Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVPreviewer.m
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVPreviewer.m     2021-01-17 
15:39:02 UTC (rev 25419)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVPreviewer.m     2021-01-17 
18:24:19 UTC (rev 25420)
@@ -45,6 +45,7 @@
 #import <pthread.h>
 #import "_FVPreviewerWindow.h"
 #import "FVTextIcon.h" // for NSAttributedString initialization check
+#import "FVIcon_Private.h" // for NSAttributedString initialization check
 
 NSString * const FVPreviewerWillCloseNotification = 
@"FVPreviewerWillCloseNotification";
 
@@ -98,7 +99,7 @@
     else if (UTTypeConformsTo((CFStringRef)theUTI, kUTTypePDF) || 
UTTypeConformsTo((CFStringRef)theUTI, FVSTR("com.adobe.postscript"))) {
         return NO;
     }
-    else if ([FVTextIcon canInitWithUTI:theUTI]) {
+    else if ([FVTextIcon canInitWithURL:aURL withType:theUTI]) {
         NSAttributedString *string = [[[NSAttributedString alloc] 
initWithURL:aURL documentAttributes:NULL] autorelease];
         return (string == nil);
     }
@@ -378,7 +379,7 @@
         }
     }
  */
-    else if ([FVTextIcon canInitWithUTI:(NSString *)theUTI]) {
+    else if ([FVTextIcon canInitWithURL:representedURL withType:(NSString 
*)theUTI]) {
         theView = textView;
         NSDictionary *attrs;
         NSAttributedString *string = [[NSAttributedString alloc] 
initWithURL:representedURL documentAttributes:&attrs];

Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVQuickLookIcon.m
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVQuickLookIcon.m 2021-01-17 
15:39:02 UTC (rev 25419)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVQuickLookIcon.m 2021-01-17 
18:24:19 UTC (rev 25420)
@@ -76,6 +76,12 @@
     return ret;
 }
 
++ (BOOL)canInitWithURL:(NSURL *)aURL withType:(NSString *)type
+{
+    // FVQuickLookIcon can basically handle any type
+    return YES;
+}
+
 - (id)initWithURL:(NSURL *)aURL drawsLinkBadge:(BOOL)drawsLinkBadge
 {
     if (FVQLIconDisabled) {

Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVTextIcon.h
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVTextIcon.h      2021-01-17 
15:39:02 UTC (rev 25419)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVTextIcon.h      2021-01-17 
18:24:19 UTC (rev 25420)
@@ -49,8 +49,6 @@
     BOOL            _isPlainText;
 }
 
-+ (BOOL)canInitWithUTI:(NSString *)aUTI;
-+ (BOOL)canInitWithURL:(NSURL *)aURL;
 - (id)initWithURL:(NSURL *)aURL drawsLinkBadge:(BOOL)drawsLinkBadge 
isPlainText:(BOOL)isPlainText;
 
 @end

Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVTextIcon.m
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVTextIcon.m      2021-01-17 
15:39:02 UTC (rev 25419)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVTextIcon.m      2021-01-17 
18:24:19 UTC (rev 25420)
@@ -44,29 +44,35 @@
 @implementation FVTextIcon
 
 // This should be very reliable, but in practice it's only as reliable as the 
UTI declaration.  For instance, OmniGraffle declares .graffle files as 
public.composite-content and public.xml in its Info.plist.  Since we see that 
it's public.xml (which is in this list), we open it as text, and it will 
actually open with NSAttributedString...and display as binary garbage.
-+ (BOOL)canInitWithUTI:(NSString *)aUTI
++ (BOOL)canInitWithURL:(NSURL *)aURL withType:(NSString *)type
 {
+    /*
+     Problems here.  TextMate claims a lot of plain text types but doesn't 
declare a UTI for any of them,
+     so I end up with a dynamic UTI, and Spotlight/Quick Look ignore the files 
since they have no idea of
+     conformance to plain text.  That's broken behavior on TextMate's part, 
and it sucks for my purposes.
+     Additionally, files that are named "README" are public.data, but actually 
plain text files.  Since
+     LS doesn't sniff types, we'll just try to open anything that's equal (not 
conforming) to public.data.
+     */
+    if (type == nil || UTTypeEqual((CFStringRef)type, kUTTypeData)) {
+        // This is mainly useful to prove that the file cannot be opened; as 
in the case of OmniGraffle files (see comment above), it returns YES.
+        NSAttributedString *attributedString = [[NSAttributedString 
allocWithZone:[self zone]] initWithURL:aURL documentAttributes:NULL];
+        BOOL canInit = (nil != attributedString);
+        [attributedString release];
+        return canInit;
+    }
+    
     static NSArray *types = nil;
     if (nil == types) {
-        types = [[NSAttributedString textUnfilteredTypes] copyWithZone:[self 
zone]];
+        types = [[NSAttributedString textUnfilteredTypes] copy];
     }
 
     NSUInteger cnt = [types count];
     while (cnt--)
-        if (UTTypeConformsTo((CFStringRef)aUTI, (CFStringRef)[types 
objectAtIndex:cnt]))
+        if (UTTypeConformsTo((CFStringRef)type, (CFStringRef)[types 
objectAtIndex:cnt]))
             return YES;
     return NO;
 }
 
-// This is mainly useful to prove that the file cannot be opened; as in the 
case of OmniGraffle files (see comment above), it returns YES.
-+ (BOOL)canInitWithURL:(NSURL *)aURL;
-{
-    NSAttributedString *attributedString = [[NSAttributedString 
allocWithZone:[self zone]] initWithURL:aURL documentAttributes:NULL];
-    BOOL canInit = (nil != attributedString);
-    [attributedString release];
-    return canInit;
-}
-
 - (id)initWithURL:(NSURL *)aURL drawsLinkBadge:(BOOL)drawsLinkBadge 
isPlainText:(BOOL)isPlainText
 {
     self = [super initWithURL:aURL drawsLinkBadge:drawsLinkBadge];

Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVWebViewIcon.m
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVWebViewIcon.m   2021-01-17 
15:39:02 UTC (rev 25419)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVWebViewIcon.m   2021-01-17 
18:24:19 UTC (rev 25420)
@@ -110,12 +110,25 @@
     return [lcString isEqualToString:@"http"] || [lcString 
isEqualToString:@"https"] || [lcString isEqualToString:@"ftp"];
 }
 
++ (BOOL)canInitWithURL:(NSURL *)aURL withType:(NSString *)type
+{
+    // if webviews are disabled, return a finder icon to avoid problems with 
looping notifications
+    if (0 == _maxWebViews) {
+        return NO;
+    } else if ([aURL isFileURL]) {
+        return UTTypeConformsTo((CFStringRef)type, kUTTypeHTML) || 
UTTypeConformsTo((CFStringRef)type, kUTTypeWebArchive);
+    } else {
+        // if this is not an http or file URL, return a finder icon instead
+        return [self _isSupportedScheme:[aURL scheme]];
+    }
+}
+
 - (id)initWithURL:(NSURL *)aURL;
 {    
     NSParameterAssert(nil != [aURL scheme]);
     
-    // if webviews are disabled, return a finder icon to avoid problems with 
looping notifications
-    // if this is not an http or file URL, return a finder icon instead
+    // if not supported, return a finder icon instead
+    // this should be handled by the placeholder class
     if (0 == _maxWebViews || (NO == [[self class] _isSupportedScheme:[aURL 
scheme]] && NO == [aURL isFileURL])) {
         [self release];
         self = (id)[FVFinderIcon newWithScheme:[aURL scheme]];

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



_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit

Reply via email to