FLTK logo

[master] 1e73216 - Fix issue #145: Native file dialog on macOS in the absence of another FLTK window.

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.commit  ]
 
Previous Message ]Next Message ]

[master] 1e73216 - Fix issue #145: Native file dialog on macOS in the absence of another FLTK window. "ManoloFLTK" Oct 05, 2020  
 
commit 1e732164054c8b5c7371020a4b1e298bc79c0fdf
Author:     ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>
AuthorDate: Mon Oct 5 11:53:49 2020 +0200
Commit:     ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>
CommitDate: Mon Oct 5 11:54:02 2020 +0200

    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(-)

diff --git src/Fl_Native_File_Chooser_MAC.mm src/Fl_Native_File_Chooser_MAC.mm
index 6ae29be..8cbd3bb 100644
--- src/Fl_Native_File_Chooser_MAC.mm
+++ 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
Direct Link to Message ]
 
     
Previous Message ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.