3636
3737#include " compat.h"
3838
39+ #include < libaegisub/dispatch.h>
3940#include < libaegisub/lua/utils.h>
4041
4142#include < wx/filedlg.h>
@@ -197,7 +198,6 @@ namespace Automation4 {
197198
198199 int LuaProgressSink::LuaDisplayOpenDialog (lua_State *L)
199200 {
200- ProgressSink *ps = GetObjPointer (L, lua_upvalueindex (1 ));
201201 wxString message (check_wxstring (L, 1 ));
202202 wxString dir (check_wxstring (L, 2 ));
203203 wxString file (check_wxstring (L, 3 ));
@@ -211,26 +211,24 @@ namespace Automation4 {
211211 if (must_exist)
212212 flags |= wxFD_FILE_MUST_EXIST;
213213
214- wxFileDialog diag (nullptr , message, dir, file, wildcard, flags);
215- if (ps->ShowDialog (&diag) == wxID_CANCEL) {
216- lua_pushnil (L);
217- return 1 ;
218- }
219-
220- if (multiple) {
221- wxArrayString files;
222- diag.GetPaths (files);
223-
224- lua_createtable (L, files.size (), 0 );
225- for (size_t i = 0 ; i < files.size (); ++i) {
226- lua_pushstring (L, files[i].utf8_str ());
227- lua_rawseti (L, -2 , i + 1 );
214+ agi::dispatch::Main ().Sync ([&] {
215+ wxFileDialog diag (nullptr , message, dir, file, wildcard, flags);
216+ if (diag.ShowModal () == wxID_CANCEL) {
217+ lua_pushnil (L);
218+ } else if (multiple) {
219+ wxArrayString files;
220+ diag.GetPaths (files);
221+
222+ lua_createtable (L, files.size (), 0 );
223+ for (size_t i = 0 ; i < files.size (); ++i) {
224+ lua_pushstring (L, files[i].utf8_str ());
225+ lua_rawseti (L, -2 , i + 1 );
226+ }
227+ } else {
228+ lua_pushstring (L, diag.GetPath ().utf8_str ());
228229 }
230+ });
229231
230- return 1 ;
231- }
232-
233- lua_pushstring (L, diag.GetPath ().utf8_str ());
234232 return 1 ;
235233 }
236234
@@ -247,13 +245,15 @@ namespace Automation4 {
247245 if (prompt_overwrite)
248246 flags |= wxFD_OVERWRITE_PROMPT;
249247
250- wxFileDialog diag (ps->GetParentWindow (), message, dir, file, wildcard, flags);
251- if (ps->ShowDialog (&diag) == wxID_CANCEL) {
252- lua_pushnil (L);
253- return 1 ;
254- }
248+ agi::dispatch::Main ().Sync ([&] {
249+ wxFileDialog diag (ps->GetParentWindow (), message, dir, file, wildcard, flags);
250+ if (diag.ShowModal () == wxID_CANCEL) {
251+ lua_pushnil (L);
252+ } else {
253+ lua_pushstring (L, diag.GetPath ().utf8_str ());
254+ }
255+ });
255256
256- lua_pushstring (L, diag.GetPath ().utf8_str ());
257257 return 1 ;
258258 }
259259}
0 commit comments