Skip to content

Commit

Permalink
Fix deprecated warnings for macOS
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
karelbilek committed Feb 19, 2024
1 parent e981b27 commit 071c4c5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion cocoa/dlg.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#import <Cocoa/Cocoa.h>
#import <UniformTypeIdentifiers/UniformTypeIdentifiers.h>
#include "dlg.h"

void* NSStr(void* buf, int len) {
Expand Down Expand Up @@ -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; i<self->params->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];
Expand Down
2 changes: 1 addition & 1 deletion cocoa/dlg_darwin.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package cocoa

// #cgo darwin LDFLAGS: -framework Cocoa
// #cgo darwin LDFLAGS: -framework Cocoa -framework UniformTypeIdentifiers
// #include <stdlib.h>
// #include <sys/syslimits.h>
// #include "dlg.h"
Expand Down

0 comments on commit 071c4c5

Please sign in to comment.