From 45e3e1594fe993e8348867898172abba9bcdc13a Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Tue, 29 Nov 2022 19:27:02 -0500 Subject: [PATCH] fontdialogbutton: Survive window closing If the parent window of the button gets destroyed while the dialog is open, we cancel the async op, but we need to be a little more careful about not stepping on glass. --- gtk/gtkfontdialogbutton.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/gtk/gtkfontdialogbutton.c b/gtk/gtkfontdialogbutton.c index 162e0f0890..9dc25cce7c 100644 --- a/gtk/gtkfontdialogbutton.c +++ b/gtk/gtkfontdialogbutton.c @@ -393,8 +393,9 @@ gtk_font_dialog_button_class_init (GtkFontDialogButtonClass *class) static void update_button_sensitivity (GtkFontDialogButton *self) { - gtk_widget_set_sensitive (self->button, - self->dialog != NULL && self->cancellable == NULL); + if (self->button) + gtk_widget_set_sensitive (self->button, + self->dialog != NULL && self->cancellable == NULL); } static void @@ -402,10 +403,11 @@ family_chosen (GObject *source, GAsyncResult *result, gpointer data) { + GtkFontDialog *dialog = GTK_FONT_DIALOG (source); GtkFontDialogButton *self = data; PangoFontFamily *family; - family = gtk_font_dialog_choose_family_finish (self->dialog, result, NULL); + family = gtk_font_dialog_choose_family_finish (dialog, result, NULL); if (family) { PangoFontDescription *desc; @@ -428,10 +430,11 @@ face_chosen (GObject *source, GAsyncResult *result, gpointer data) { + GtkFontDialog *dialog = GTK_FONT_DIALOG (source); GtkFontDialogButton *self = data; PangoFontFace *face; - face = gtk_font_dialog_choose_face_finish (self->dialog, result, NULL); + face = gtk_font_dialog_choose_face_finish (dialog, result, NULL); if (face) { PangoFontDescription *desc; @@ -453,10 +456,11 @@ font_chosen (GObject *source, GAsyncResult *result, gpointer data) { + GtkFontDialog *dialog = GTK_FONT_DIALOG (source); GtkFontDialogButton *self = data; PangoFontDescription *desc; - desc = gtk_font_dialog_choose_font_finish (self->dialog, result, NULL); + desc = gtk_font_dialog_choose_font_finish (dialog, result, NULL); if (desc) { gtk_font_dialog_button_set_font_desc (self, desc); @@ -472,12 +476,13 @@ font_and_features_chosen (GObject *source, GAsyncResult *result, gpointer data) { + GtkFontDialog *dialog = GTK_FONT_DIALOG (source); GtkFontDialogButton *self = data; PangoFontDescription *desc; char *features; PangoLanguage *language; - if (gtk_font_dialog_choose_font_and_features_finish (self->dialog, result, + if (gtk_font_dialog_choose_font_and_features_finish (dialog, result, &desc, &features, &language, NULL)) { -- 2.30.2