diff --git a/src/dialog/cocoa/SDL_cocoadialog.m b/src/dialog/cocoa/SDL_cocoadialog.m index 64b4b3563..970b1884f 100644 --- a/src/dialog/cocoa/SDL_cocoadialog.m +++ b/src/dialog/cocoa/SDL_cocoadialog.m @@ -21,6 +21,7 @@ #include "SDL_internal.h" #import +#import typedef enum { @@ -59,6 +60,7 @@ void show_file_dialog(cocoa_FileDialogType type, SDL_DialogFileCallback callback int n = -1; 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 ]; 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++) { if (*c == ';') { *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; } 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); @@ -85,7 +91,11 @@ void show_file_dialog(cocoa_FileDialogType type, SDL_DialogFileCallback callback 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); }