@@ -114,38 +114,73 @@ void doLoadDialogModeless(const std::vector<std::string>* allowed_types,
114114
115115 @autoreleasepool
116116 {
117- // Note: might need to return and save this panel
118- // so that it does not close immediately
119117 NSOpenPanel *panel = init_panel (allowed_types,flags);
118+ NSWindow *mainWindow = [NSApp mainWindow ];
120119
121- [panel beginWithCompletionHandler: ^( NSModalResponse result )
120+ if (mainWindow )
122121 {
123- std::vector<std::string> outfiles;
124- if (result == NSModalResponseOK )
122+ [panel beginSheetModalForWindow: mainWindow
123+ completionHandler: ^( NSModalResponse result )
125124 {
126- NSArray *filesToOpen = [panel URLs ];
127- int i, count = [filesToOpen count ];
128-
129- if (count > 0 )
125+ std::vector<std::string> outfiles;
126+ if (result == NSModalResponseOK )
130127 {
131-
132- for (i=0 ; i<count; i++) {
133- NSString *aFile = [[filesToOpen objectAtIndex: i] path ];
134- std::string *afilestr = new std::string ([aFile UTF8String ]);
135- outfiles.push_back (*afilestr);
128+ NSArray *filesToOpen = [panel URLs ];
129+ int i, count = [filesToOpen count ];
130+
131+ if (count > 0 )
132+ {
133+
134+ for (i=0 ; i<count; i++) {
135+ NSString *aFile = [[filesToOpen objectAtIndex: i] path ];
136+ std::string *afilestr = new std::string ([aFile UTF8String ]);
137+ outfiles.push_back (*afilestr);
138+ }
139+ callback (true , outfiles, userdata);
140+ }
141+ else // no valid result
142+ {
143+ callback (false , outfiles, userdata);
136144 }
137- callback (true , outfiles, userdata);
138145 }
139- else // no valid result
146+ else // cancel
140147 {
141148 callback (false , outfiles, userdata);
142149 }
143- }
144- else // cancel
150+ }];
151+ }
152+ else
153+ {
154+ // present as modeless window
155+ [panel beginWithCompletionHandler: ^(NSModalResponse result)
145156 {
146- callback (false , outfiles, userdata);
147- }
148- }];
157+ std::vector<std::string> outfiles;
158+ if (result == NSModalResponseOK )
159+ {
160+ NSArray *filesToOpen = [panel URLs ];
161+ int i, count = [filesToOpen count ];
162+
163+ if (count > 0 )
164+ {
165+
166+ for (i=0 ; i<count; i++) {
167+ NSString *aFile = [[filesToOpen objectAtIndex: i] path ];
168+ std::string *afilestr = new std::string ([aFile UTF8String ]);
169+ outfiles.push_back (*afilestr);
170+ }
171+ callback (true , outfiles, userdata);
172+ }
173+ else // no valid result
174+ {
175+ callback (false , outfiles, userdata);
176+ }
177+ }
178+ else // cancel
179+ {
180+ callback (false , outfiles, userdata);
181+ }
182+ }];
183+ }
149184 }
150185}
151186
0 commit comments