SDL: Fix file selection dialog boxes not working on macOS 11.0+

From feebb9fcf8c5204599bb4f5ab2897ab1eedb4aba Mon Sep 17 00:00:00 2001
From: Sean Ridenour <[EMAIL REDACTED]>
Date: Sun, 31 Mar 2024 19:26:03 -0600
Subject: [PATCH] Fix file selection dialog boxes not working on macOS 11.0+

---
 src/dialog/cocoa/SDL_cocoadialog.m | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/src/dialog/cocoa/SDL_cocoadialog.m b/src/dialog/cocoa/SDL_cocoadialog.m
index 64b4b35635cc6..970b1884f5ae9 100644
--- a/src/dialog/cocoa/SDL_cocoadialog.m
+++ b/src/dialog/cocoa/SDL_cocoadialog.m
@@ -21,6 +21,7 @@
 #include "SDL_internal.h"
 
 #import <Cocoa/Cocoa.h>
+#import <UniformTypeIdentifiers/UTType.h>
 
 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);
     }