From 071c4c551319c25c44f6d67bdc6caeec59421d14 Mon Sep 17 00:00:00 2001 From: Karel Bilek Date: Mon, 19 Feb 2024 16:51:57 +0100 Subject: [PATCH] Fix deprecated warnings for macOS macOS has a new framework UniformTypeIdentifiers that needs to be used for this. Note that the behavior is not exactly the same - if you add "jpg", it will find a UTType that has "jpg" extension and will use that instead of creating a new type; so it will match both "jpg" and "jpeg". I think it is acceptable (and, probably, even better). --- cocoa/dlg.m | 11 ++++++++++- cocoa/dlg_darwin.go | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/cocoa/dlg.m b/cocoa/dlg.m index f29448e..a6c47f2 100644 --- a/cocoa/dlg.m +++ b/cocoa/dlg.m @@ -1,4 +1,5 @@ #import +#import #include "dlg.h" void* NSStr(void* buf, int len) { @@ -93,7 +94,15 @@ - (NSInteger)runPanel:(NSSavePanel*)panel { [panel setTitle:[[NSString alloc] initWithUTF8String:self->params->title]]; } if(self->params->numext > 0) { - [panel setAllowedFileTypes:[NSArray arrayWithObjects:(NSString**)self->params->exts count:self->params->numext]]; + NSString** exts = (NSString**)self->params->exts; + NSMutableArray *types = [NSMutableArray array]; + + for (int i=0; iparams->numext; i++) { + NSString* ext = exts[i]; + UTType *t = [UTType typeWithFilenameExtension: exts[i]]; + [types addObject: t]; + } + [panel setAllowedContentTypes:types]; } if(self->params->relaxext) { [panel setAllowsOtherFileTypes:YES]; diff --git a/cocoa/dlg_darwin.go b/cocoa/dlg_darwin.go index f59dd20..c3356a4 100644 --- a/cocoa/dlg_darwin.go +++ b/cocoa/dlg_darwin.go @@ -1,6 +1,6 @@ package cocoa -// #cgo darwin LDFLAGS: -framework Cocoa +// #cgo darwin LDFLAGS: -framework Cocoa -framework UniformTypeIdentifiers // #include // #include // #include "dlg.h"