colordialogbutton: Survive window closing
authorMatthias Clasen <mclasen@redhat.com>
Wed, 30 Nov 2022 00:25:54 +0000 (19:25 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Fri, 9 Dec 2022 16:05:48 +0000 (11:05 -0500)
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/gtkcolordialogbutton.c

index 76e007f6cc242b81b56255bad4873c77610b7c82..10f527febf12405cc03780d4ceb29740c7b717ad 100644 (file)
@@ -338,8 +338,9 @@ drag_prepare (GtkDragSource        *source,
 static void
 update_button_sensitivity (GtkColorDialogButton *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
@@ -347,10 +348,11 @@ color_chosen (GObject      *source,
               GAsyncResult *result,
               gpointer      data)
 {
+  GtkColorDialog *dialog = GTK_COLOR_DIALOG (source);
   GtkColorDialogButton *self = data;
   GdkRGBA *color;
 
-  color = gtk_color_dialog_choose_rgba_finish (self->dialog, result, NULL);
+  color = gtk_color_dialog_choose_rgba_finish (dialog, result, NULL);
   if (color)
     {
       gtk_color_dialog_button_set_rgba (self, color);