summaryrefslogtreecommitdiffstats
path: root/macosx/tkMacOSXFileTypes.c
diff options
context:
space:
mode:
Diffstat (limited to 'macosx/tkMacOSXFileTypes.c')
-rw-r--r--macosx/tkMacOSXFileTypes.c38
1 files changed, 24 insertions, 14 deletions
diff --git a/macosx/tkMacOSXFileTypes.c b/macosx/tkMacOSXFileTypes.c
index c89328d..66e4fbb 100644
--- a/macosx/tkMacOSXFileTypes.c
+++ b/macosx/tkMacOSXFileTypes.c
@@ -69,36 +69,46 @@ MODULE_SCOPE NSString *TkMacOSXOSTypeToUTI(OSType ostype) {
* accept an NSString which could be an encoding of an OSType, or a file extension,
* or a Uniform Type Idenfier. This function can serve as a replacement.
*/
-
MODULE_SCOPE NSImage *TkMacOSXIconForFileType(NSString *filetype) {
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101300
if (!initialized) {
initOSTypeTable();
}
+#if MAC_OS_X_VERSION_MAX_ALLOWED < 110000
+// We don't have UTType but iconForFileType is not deprecated, so use it.
+ return [[NSWorkspace sharedWorkspace] iconForFileType:filetype];
+#else
+// We might have UTType but iconForFileType might be deprecated.
if (@available(macOS 11.0, *)) {
+ /* Yes, we do have UTType */
UTType *uttype = [UTType typeWithIdentifier: filetype];
- if (![uttype isDeclared]) {
+ if (uttype == nil || !uttype.isDeclared) {
uttype = [UTType typeWithFilenameExtension: filetype];
}
- if (![uttype isDeclared] && [filetype length] == 4) {
+ if (uttype == nil || (!uttype.isDeclared && filetype.length == 4)) {
OSType ostype = CHARS_TO_OSTYPE(filetype.UTF8String);
NSString *UTI = TkMacOSXOSTypeToUTI(ostype);
- uttype = [UTType typeWithIdentifier:UTI];
+ if (UTI) {
+ uttype = [UTType typeWithIdentifier:UTI];
+ }
}
- if (![uttype isDeclared]) {
+ if (uttype == nil || !uttype.isDeclared) {
return nil;
}
return [[NSWorkspace sharedWorkspace] iconForContentType:uttype];
} else {
-/* Despite Apple's claims, @available does not prevent deprecation warnings. */
-# if MAC_OS_X_VERSION_MIN_REQUIRED < 110000
- return [[NSWorkspace sharedWorkspace] iconForFileType:filetype];
-#else
- return nil; /* Never executed. */
-#endif
- }
-#else /* @available is not available. */
+ /* No, we don't have UTType. */
+ #if MAC_OS_X_VERSION_MIN_REQUIRED < 110000
+ /* but iconForFileType is not deprecated, so we can use it. */
return [[NSWorkspace sharedWorkspace] iconForFileType:filetype];
+ #else
+ /*
+ * Cannot be reached: MIN_REQUIRED >= 110000 yet 11.0 is not available.
+ * But the compiler can't figure that out, so it will warn about an
+ * execution path with no return value unless we put a return here.
+ */
+ return nil;
+ #endif
+ }
#endif
}