diff options
| author | ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> | 2020-10-05 11:53:49 +0200 |
|---|---|---|
| committer | ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> | 2020-10-05 11:54:02 +0200 |
| commit | 1e732164054c8b5c7371020a4b1e298bc79c0fdf (patch) | |
| tree | d410862fddafc00c0a41ded61e3b95695aaf6b25 /src/Fl_Native_File_Chooser_MAC.mm | |
| parent | 0c55cd1aca19b57a9b8837d1672ae260cfca4d78 (diff) | |
Fix issue #145: Native file dialog on macOS in the absence of another FLTK window.
Diffstat (limited to 'src/Fl_Native_File_Chooser_MAC.mm')
| -rw-r--r-- | src/Fl_Native_File_Chooser_MAC.mm | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/src/Fl_Native_File_Chooser_MAC.mm b/src/Fl_Native_File_Chooser_MAC.mm index 6ae29bee2..8cbd3bb52 100644 --- a/src/Fl_Native_File_Chooser_MAC.mm +++ b/src/Fl_Native_File_Chooser_MAC.mm @@ -617,18 +617,22 @@ int Fl_Quartz_Native_File_Chooser_Driver::runmodal() } if (usepath) { // Set only if full path exists - [_panel setDirectoryURL:[NSURL fileURLWithPath:path]]; + [_panel setDirectoryURL:[NSURL fileURLWithPath:path]]; // 10.6 } else { // didn't setDirectoryURL to full path? Set dir + fname separately.. - if (dir) [_panel setDirectoryURL:[NSURL fileURLWithPath:dir]]; - if (fname) [_panel setNameFieldStringValue:fname]; + if (dir) [_panel setDirectoryURL:[NSURL fileURLWithPath:dir]]; // 10.6 + if (fname) [_panel setNameFieldStringValue:fname]; // 10.6 } [path release]; - __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 ([_panel isVisible]) Fl::wait(100); // loop until end of file dialog - retval = complete; + if ([NSApp mainWindow]) { + __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 ([_panel isVisible]) Fl::wait(100); // loop until end of file dialog + retval = complete; + } else { + retval = [_panel runModal]; + } } else #endif |
