summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>2024-03-23 17:16:57 +0100
committerManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>2024-03-23 17:16:57 +0100
commit97d2836f5e72054f640289a93c4f2dd776c4fd00 (patch)
tree84f60fb06ef7a03103cf2a1499c5602df88e9655 /src
parentf3640a7312413ef8afc2db1060137a04eea2a016 (diff)
macOS: remove deprecated use of property allowedFileTypes in class NSSavePanel
The recommended replacement requires macos ≥ 11.0 and a new framework: UniformTypeIdentifiers
Diffstat (limited to 'src')
-rw-r--r--src/Fl_Native_File_Chooser_MAC.mm25
1 files changed, 22 insertions, 3 deletions
diff --git a/src/Fl_Native_File_Chooser_MAC.mm b/src/Fl_Native_File_Chooser_MAC.mm
index 4272a0d5a..a10aa6c9d 100644
--- a/src/Fl_Native_File_Chooser_MAC.mm
+++ b/src/Fl_Native_File_Chooser_MAC.mm
@@ -2,7 +2,7 @@
// FLTK native OS file chooser widget for macOS
//
// Copyright 2004 Greg Ercolano.
-// Copyright 1998-2022 by Bill Spitzak and others.
+// Copyright 1998-2024 by Bill Spitzak and others.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file. If this
@@ -28,6 +28,9 @@
#include <FL/fl_string_functions.h>
#define MAXFILTERS 80
#import <Cocoa/Cocoa.h>
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_VERSION_11_0
+# import <UniformTypeIdentifiers/UniformTypeIdentifiers.h>
+#endif
#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_9
const NSInteger NSModalResponseOK = NSFileHandlingPanelOKButton;
@@ -513,6 +516,7 @@ static char *prepareMacFilter(int count, const char *filter, char **patterns) {
BOOL saveas_confirm;
}
- (NSString *)panel:(id)sender userEnteredFilename:(NSString *)filename confirmed:(BOOL)okFlag;
+- (void)control_allowed_types:(const char *)p;
- (void)changedPopup:(id)sender;
- (void)panel:(NSSavePanel*)p;
- (void)option:(BOOL)o;
@@ -525,6 +529,21 @@ static char *prepareMacFilter(int count, const char *filter, char **patterns) {
// To get the latter, we need to change the name we return (hence the prefix):
return [@ UNLIKELYPREFIX stringByAppendingString:filename];
}
+- (void)control_allowed_types:(const char *)p
+{
+ NSString *ext = [NSString stringWithUTF8String:p];
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_VERSION_11_0
+ if (fl_mac_os_version >= 110000) {
+ UTType *type = [UTType typeWithFilenameExtension:ext]; // 11.0 + framework UniformTypeIdentifiers
+ [dialog setAllowedContentTypes:[NSArray arrayWithObject:type]]; // 11.0
+ }
+ else
+#endif
+ if (fl_mac_os_version >= 100900) {
+ [dialog performSelector:@selector(setAllowedFileTypes:)
+ withObject:[NSArray arrayWithObject:ext]];
+ }
+}
- (void)changedPopup:(id)sender
// runs when the save panel popup menu changes output file type
// correspondingly changes the extension of the output file name
@@ -545,7 +564,7 @@ static char *prepareMacFilter(int count, const char *filter, char **patterns) {
NSString *ns = [NSString stringWithFormat:@"%@.%@",
[[dialog performSelector:@selector(nameFieldStringValue)] stringByDeletingPathExtension],
[NSString stringWithUTF8String:p]];
- if (fl_mac_os_version >= 100900) [dialog setAllowedFileTypes:[NSArray arrayWithObject:[NSString stringWithUTF8String:p]]];
+ [self control_allowed_types:p];
free(s);
[dialog performSelector:@selector(setNameFieldStringValue:) withObject:ns];
}
@@ -785,7 +804,7 @@ int Fl_Quartz_Native_File_Chooser_Driver::post() {
do q++; while (*q==' ' || *q=='{');
p = fl_strdup(q);
q = strchr(p, ','); if (q) *q = 0;
- [_panel setAllowedFileTypes:[NSArray arrayWithObject:[NSString stringWithUTF8String:p]]];
+ [saveDelegate control_allowed_types:p];
free(p);
}
}