From 97d2836f5e72054f640289a93c4f2dd776c4fd00 Mon Sep 17 00:00:00 2001 From: ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> Date: Sat, 23 Mar 2024 17:16:57 +0100 Subject: macOS: remove deprecated use of property allowedFileTypes in class NSSavePanel MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The recommended replacement requires macos ≥ 11.0 and a new framework: UniformTypeIdentifiers --- src/Fl_Native_File_Chooser_MAC.mm | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'src') 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 #define MAXFILTERS 80 #import +#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_VERSION_11_0 +# import +#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); } } -- cgit v1.2.3