diff options
| author | ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> | 2020-04-10 18:40:26 +0200 |
|---|---|---|
| committer | ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> | 2020-04-10 18:41:24 +0200 |
| commit | 84b753e7e9f8ee925fbcf44a282b5b38b3c8970e (patch) | |
| tree | 6d3bdc92ffa786f98ddec0a3195d7df8c1fdf2de /src | |
| parent | f930e834c58750ef3ca4bf81537d7b7b9b1dbd5c (diff) | |
Fix regression in Fl_Native_File_Chooser under macOS when USE_FILTER_EXT is ON.
Diffstat (limited to 'src')
| -rw-r--r-- | src/Fl_Native_File_Chooser_MAC.mm | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/src/Fl_Native_File_Chooser_MAC.mm b/src/Fl_Native_File_Chooser_MAC.mm index 48d489f1e..07d8dba15 100644 --- a/src/Fl_Native_File_Chooser_MAC.mm +++ b/src/Fl_Native_File_Chooser_MAC.mm @@ -536,6 +536,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]]]; free(s); [dialog performSelector:@selector(setNameFieldStringValue:) withObject:ns]; } @@ -601,6 +602,7 @@ int Fl_Quartz_Native_File_Chooser_Driver::runmodal() fname = [preset lastPathComponent]; } if (_directory && !dir) dir = [[NSString alloc] initWithUTF8String:_directory]; +#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6 if (fl_mac_os_version >= 100600) { bool usepath = false; NSString *path = nil; @@ -615,15 +617,22 @@ int Fl_Quartz_Native_File_Chooser_Driver::runmodal() } if (usepath) { // Set only if full path exists - [_panel performSelector:@selector(setDirectoryURL:) withObject:[NSURL fileURLWithPath:path]]; + [_panel setDirectoryURL:[NSURL fileURLWithPath:path]]; } else { // didn't setDirectoryURL to full path? Set dir + fname separately.. - if (dir) [_panel performSelector:@selector(setDirectoryURL:) withObject:[NSURL fileURLWithPath:dir]]; - if (fname) [_panel performSelector:@selector(setNameFieldStringValue:) withObject:fname]; + if (dir) [_panel setDirectoryURL:[NSURL fileURLWithPath:dir]]; + if (fname) [_panel setNameFieldStringValue:fname]; } [path release]; - retval = [_panel runModal]; + __block NSInteger complete = -1; + [_panel beginSheetModalForWindow:[NSApp mainWindow] completionHandler:^(NSInteger returnCode) { + complete = returnCode; // this block runs after OK or Cancel was triggered in file dialog + }]; // this message returns immediately and begins the file dialog as a sheet + while (complete < 0) Fl::wait(100); // loop until end of file dialog + retval = complete; } - else { + else +#endif + { retval = [(id)_panel runModalForDirectory:dir file:fname]; } [dir release]; @@ -712,6 +721,16 @@ int Fl_Quartz_Native_File_Chooser_Driver::post() { [popup setAction:@selector(changedPopup:)]; [popup setTarget:saveDelegate]; [saveDelegate panel:(NSSavePanel*)_panel]; + if (fl_mac_os_version >= 100900) { + char *p = _filt_patt[_filt_value]; + char *q = strchr(p, '.'); if(!q) q = p-1; + do q++; while (*q==' ' || *q=='{'); + p = strdup(q); + q = strchr(p, ','); if (q) *q = 0; + [_panel setAllowedFileTypes:[NSArray arrayWithObject:[NSString stringWithUTF8String:p]]]; + free(p); + [_panel setExtensionHidden:NO]; + } } [_panel setCanSelectHiddenExtension:YES]; } |
