Updated the Windows GTK3 native file-dialog flow to use asynchronous handling (gtk_native_dialog_show + "response" signal) instead of synchronous gtk_native_dialog_run, reducing risky dispose/unrealize timing during dialog close.

Added gtkutil_native_file_req_response() to keep completion semantics consistent: process selected files on accept, send the trailing callback(..., NULL) completion notification, free request state, and defer dialog unref to idle.
This commit is contained in:
2026-02-16 17:29:25 -07:00
parent a6af143ba7
commit 6df8a98fa0

View File

@@ -499,6 +499,23 @@ gtkutil_native_dialog_unref_idle (gpointer native)
g_object_unref (native);
return G_SOURCE_REMOVE;
}
static void
gtkutil_native_file_req_response (GtkNativeDialog *dialog, gint res, struct file_req *freq)
{
if (res == GTK_RESPONSE_ACCEPT)
gtkutil_file_req_done_chooser (GTK_FILE_CHOOSER (dialog), freq);
/* Match gtk dialog flow by always sending NULL to indicate completion. */
freq->callback (freq->userdata, NULL);
g_free (freq);
/*
* Defer unref until idle to avoid disposing the native chooser while
* still in the button-release signal stack on Windows.
*/
g_idle_add (gtkutil_native_dialog_unref_idle, dialog);
}
#endif
void
@@ -529,7 +546,6 @@ gtkutil_file_req (GtkWindow *parent, const char *title, void *callback, void *us
(flags & FRF_WRITE) ? _("_Save") : _("_Open"),
_("_Cancel"));
GtkFileChooser *native_chooser = GTK_FILE_CHOOSER (native);
int response;
if (flags & FRF_MULTIPLE)
gtk_file_chooser_set_select_multiple (native_chooser, TRUE);
@@ -587,16 +603,9 @@ gtkutil_file_req (GtkWindow *parent, const char *title, void *callback, void *us
freq->callback = callback;
freq->userdata = userdata;
response = gtk_native_dialog_run (GTK_NATIVE_DIALOG (native));
if (response == GTK_RESPONSE_ACCEPT)
gtkutil_file_req_done_chooser (native_chooser, freq);
/*
* Defer unref until idle to avoid disposing the native chooser while
* still in the button-release signal stack on Windows.
*/
g_idle_add (gtkutil_native_dialog_unref_idle, native);
g_free (freq);
g_signal_connect (native, "response",
G_CALLBACK (gtkutil_native_file_req_response), freq);
gtk_native_dialog_show (GTK_NATIVE_DIALOG (native));
return;
}
#endif