From 1e732164054c8b5c7371020a4b1e298bc79c0fdf Mon Sep 17 00:00:00 2001 From: ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> Date: Mon, 5 Oct 2020 11:53:49 +0200 Subject: Fix issue #145: Native file dialog on macOS in the absence of another FLTK window. --- src/Fl_Native_File_Chooser_MAC.mm | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'src') 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 -- cgit v1.2.3