9
9
#include < Availability.h>
10
10
#include " nfd.h"
11
11
12
- // At least one of NFD_NEEDS_ALLOWEDCONTENTTYPES and NFD_NEEDS_ALLOWEDFILETYPES will be defined
13
- #if defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && defined(__MAC_12_0) && \
14
- __MAC_OS_X_VERSION_MAX_ALLOWED >= __MAC_12_0
15
- #include < UniformTypeIdentifiers/UniformTypeIdentifiers.h>
16
- #define NFD_NEEDS_ALLOWEDCONTENTTYPES
17
- #if !defined(__MAC_OS_X_VERSION_MIN_ALLOWED) || !defined(__MAC_12_0) || \
18
- __MAC_OS_X_VERSION_MIN_ALLOWED < __MAC_12_0
19
- #define NFD_NEEDS_ALLOWEDFILETYPES
20
- #endif
12
+ // MacOS is deprecating the allowedFileTypes property in favour of allowedContentTypes, so we have
13
+ // to introduce this breaking change. Define NFD_MACOS_ALLOWEDCONTENTTYPES to 1 to have it set the
14
+ // allowedContentTypes property of the SavePanel or OpenPanel. Define
15
+ // NFD_MACOS_ALLOWEDCONTENTTYPES to 0 to have it set the allowedFileTypes property of the SavePanel
16
+ // or OpenPanel. If NFD_MACOS_ALLOWEDCONTENTTYPES is undefined, then it will set it to 1 if
17
+ // __MAC_OS_X_VERSION_MIN_REQUIRED >= 11.0, and 0 otherwise.
18
+ #if !defined(NFD_MACOS_ALLOWEDCONTENTTYPES)
19
+ #if !defined(__MAC_OS_X_VERSION_MIN_REQUIRED) || !defined(__MAC_11_0) || \
20
+ __MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_11_0
21
+ #define NFD_MACOS_ALLOWEDCONTENTTYPES 0
21
22
#else
22
- #define NFD_NEEDS_ALLOWEDFILETYPES
23
+ #define NFD_MACOS_ALLOWEDCONTENTTYPES 1
24
+ #endif
25
+ #endif
26
+
27
+ #if NFD_MACOS_ALLOWEDCONTENTTYPES == 1
28
+ #include < UniformTypeIdentifiers/UniformTypeIdentifiers.h>
23
29
#endif
24
30
25
31
static const char * g_errorstr = NULL ;
@@ -40,7 +46,7 @@ static void NFDi_Free(void* ptr) {
40
46
free (ptr);
41
47
}
42
48
43
- #if defined(NFD_NEEDS_ALLOWEDCONTENTTYPES)
49
+ #if NFD_MACOS_ALLOWEDCONTENTTYPES == 1
44
50
// Returns an NSArray of UTType representing the content types.
45
51
static NSArray * BuildAllowedContentTypes (const nfdnfilteritem_t * filterList,
46
52
nfdfiltersize_t filterCount) {
@@ -81,9 +87,7 @@ static void NFDi_Free(void* ptr) {
81
87
82
88
return returnArray;
83
89
}
84
- #endif
85
-
86
- #if defined(NFD_NEEDS_ALLOWEDFILETYPES)
90
+ #else
87
91
// Returns an NSArray of NSString representing the file types.
88
92
static NSArray * BuildAllowedFileTypes (const nfdnfilteritem_t * filterList,
89
93
nfdfiltersize_t filterCount) {
@@ -130,21 +134,8 @@ static void AddFilterListToDialog(NSSavePanel* dialog,
130
134
assert (filterList);
131
135
132
136
// Make NSArray of file types and set it on the dialog
133
- // We use setAllowedFileTypes or setAllowedContentTypes depending on the OS version
134
- #if defined(NFD_NEEDS_ALLOWEDCONTENTTYPES) && defined(NFD_NEEDS_ALLOWEDFILETYPES)
135
- // If both are needed, it means we have to do a runtime check
136
- if (@available (macOS 12.0 , *)) {
137
- NSArray * allowedContentTypes = BuildAllowedContentTypes (filterList, filterCount);
138
- [dialog setAllowedContentTypes: allowedContentTypes];
139
- } else {
140
- NSArray * allowedFileTypes = BuildAllowedFileTypes (filterList, filterCount);
141
- // Unfortunately @available doesn't silence deprecation warnings so we need these pragmas
142
- #pragma clang diagnostic push
143
- #pragma clang diagnostic ignored "-Wdeprecated-declarations"
144
- [dialog setAllowedFileTypes: allowedFileTypes];
145
- #pragma clang diagnostic pop
146
- }
147
- #elif defined(NFD_NEEDS_ALLOWEDCONTENTTYPES)
137
+ // We use setAllowedFileTypes or setAllowedContentTypes depending on the deployment target
138
+ #if NFD_MACOS_ALLOWEDCONTENTTYPES == 1
148
139
NSArray * allowedContentTypes = BuildAllowedContentTypes (filterList, filterCount);
149
140
[dialog setAllowedContentTypes: allowedContentTypes];
150
141
#else
0 commit comments