Fix file selection dialog boxes not working on macOS 11.0+
parent
c0bfd8bafd
commit
feebb9fcf8
|
@ -21,6 +21,7 @@
|
||||||
#include "SDL_internal.h"
|
#include "SDL_internal.h"
|
||||||
|
|
||||||
#import <Cocoa/Cocoa.h>
|
#import <Cocoa/Cocoa.h>
|
||||||
|
#import <UniformTypeIdentifiers/UTType.h>
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
|
@ -59,6 +60,7 @@ void show_file_dialog(cocoa_FileDialogType type, SDL_DialogFileCallback callback
|
||||||
|
|
||||||
int n = -1;
|
int n = -1;
|
||||||
while (filters[++n].name && filters[n].pattern);
|
while (filters[++n].name && filters[n].pattern);
|
||||||
|
// On macOS 11.0 and up, this is an array of UTType. Prior to that, it's an array of NSString
|
||||||
NSMutableArray *types = [[NSMutableArray alloc] initWithCapacity:n ];
|
NSMutableArray *types = [[NSMutableArray alloc] initWithCapacity:n ];
|
||||||
|
|
||||||
int has_all_files = 0;
|
int has_all_files = 0;
|
||||||
|
@ -75,7 +77,11 @@ void show_file_dialog(cocoa_FileDialogType type, SDL_DialogFileCallback callback
|
||||||
for (char *c = pattern; *c; c++) {
|
for (char *c = pattern; *c; c++) {
|
||||||
if (*c == ';') {
|
if (*c == ';') {
|
||||||
*c = '\0';
|
*c = '\0';
|
||||||
[types addObject: [NSString stringWithFormat: @"%s", pattern_ptr]];
|
if(@available(macOS 11.0, *)) {
|
||||||
|
[types addObject: [UTType typeWithFilenameExtension:[NSString stringWithFormat: @"%s", pattern_ptr]]];
|
||||||
|
} else {
|
||||||
|
[types addObject: [NSString stringWithFormat: @"%s", pattern_ptr]];
|
||||||
|
}
|
||||||
pattern_ptr = c + 1;
|
pattern_ptr = c + 1;
|
||||||
} else if (!((*c >= 'a' && *c <= 'z') || (*c >= 'A' && *c <= 'Z') || (*c >= '0' && *c <= '9') || *c == '.' || *c == '_' || *c == '-' || (*c == '*' && (c[1] == '\0' || c[1] == ';')))) {
|
} else if (!((*c >= 'a' && *c <= 'z') || (*c >= 'A' && *c <= 'Z') || (*c >= '0' && *c <= '9') || *c == '.' || *c == '_' || *c == '-' || (*c == '*' && (c[1] == '\0' || c[1] == ';')))) {
|
||||||
SDL_SetError("Illegal character in pattern name: %c (Only alphanumeric characters, periods, underscores and hyphens allowed)", *c);
|
SDL_SetError("Illegal character in pattern name: %c (Only alphanumeric characters, periods, underscores and hyphens allowed)", *c);
|
||||||
|
@ -85,7 +91,11 @@ void show_file_dialog(cocoa_FileDialogType type, SDL_DialogFileCallback callback
|
||||||
has_all_files = 1;
|
has_all_files = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
[types addObject: [NSString stringWithFormat: @"%s", pattern_ptr]];
|
if(@available(macOS 11.0, *)) {
|
||||||
|
[types addObject: [UTType typeWithFilenameExtension:[NSString stringWithFormat: @"%s", pattern_ptr]]];
|
||||||
|
} else {
|
||||||
|
[types addObject: [NSString stringWithFormat: @"%s", pattern_ptr]];
|
||||||
|
}
|
||||||
|
|
||||||
SDL_free(pattern);
|
SDL_free(pattern);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue