[gtk+] Add gtk_native_dialog_destroy()



commit 51dc4873fd8b4d4f14f902870b6110dd70a224e3
Author: Alexander Larsson <alexl redhat com>
Date:   Wed Nov 11 16:06:44 2015 +0100

    Add gtk_native_dialog_destroy()
    
    Its very easy to get extra references to the NativeDialog so that
    when you release your last reference any visible dialog is not
    hidden. We handle this by adding a destroy method similar to how
    you destroy regular toplevels.

 demos/gtk-demo/application.c         |    1 +
 docs/reference/gtk/gtk3-sections.txt |    1 +
 gtk/gtkfilechooserbutton.c           |    6 +++++-
 gtk/gtknativedialog.c                |   24 ++++++++++++++++++++++++
 gtk/gtknativedialog.h                |    2 ++
 tests/testgtk.c                      |    9 ++++++++-
 6 files changed, 41 insertions(+), 2 deletions(-)
---
diff --git a/demos/gtk-demo/application.c b/demos/gtk-demo/application.c
index 02c12f9..6124c3f 100644
--- a/demos/gtk-demo/application.c
+++ b/demos/gtk-demo/application.c
@@ -113,6 +113,7 @@ open_response_cb (GtkNativeDialog *dialog,
         }
     }
 
+  gtk_native_dialog_destroy (GTK_NATIVE_DIALOG (native));
   g_object_unref (native);
 }
 
diff --git a/docs/reference/gtk/gtk3-sections.txt b/docs/reference/gtk/gtk3-sections.txt
index e8ad757..767ad26 100644
--- a/docs/reference/gtk/gtk3-sections.txt
+++ b/docs/reference/gtk/gtk3-sections.txt
@@ -2520,6 +2520,7 @@ GTK_TYPE_NATIVE_DIALOG
 GtkNativeDialogClass
 gtk_native_dialog_show
 gtk_native_dialog_hide
+gtk_native_dialog_destroy
 gtk_native_dialog_get_visible
 gtk_native_dialog_set_modal
 gtk_native_dialog_get_modal
diff --git a/gtk/gtkfilechooserbutton.c b/gtk/gtkfilechooserbutton.c
index 1df73bc..000482e 100644
--- a/gtk/gtkfilechooserbutton.c
+++ b/gtk/gtkfilechooserbutton.c
@@ -1008,7 +1008,11 @@ gtk_file_chooser_button_destroy (GtkWidget *widget)
       priv->dialog = NULL;
     }
 
-  g_clear_object (&priv->native);
+  if (priv->native)
+    {
+      gtk_native_dialog_destroy (GTK_NATIVE_DIALOG (priv->native));
+      g_clear_object (&priv->native);
+    }
 
   priv->chooser = NULL;
 
diff --git a/gtk/gtknativedialog.c b/gtk/gtknativedialog.c
index d67047c..e4fbb67 100644
--- a/gtk/gtknativedialog.c
+++ b/gtk/gtknativedialog.c
@@ -361,6 +361,30 @@ gtk_native_dialog_hide (GtkNativeDialog *self)
   g_object_notify_by_pspec (G_OBJECT (self), native_props[PROP_VISIBLE]);
 }
 
+/**
+ * gtk_native_dialog_destroy:
+ * @self: a #GtkNativeDialog
+ *
+ * Destroys a dialog.
+ *
+ * When a dialog is destroyed, it will break any references it holds
+ * to other objects. If it is visible it will be hidden and any underlying
+ * window system resources will be destroyed.
+ *
+ * Note that this does not release any reference to the object (as opposed to
+ * destroying a GtkWindow) because there is no reference from the windowing
+ * system to the #GtkNativeDialog.
+ *
+ * Since: 3.20
+ **/
+void
+gtk_native_dialog_destroy (GtkNativeDialog *self)
+{
+  g_return_if_fail (GTK_IS_NATIVE_DIALOG (self));
+
+  g_object_run_dispose (G_OBJECT (self));
+}
+
 void
 _gtk_native_dialog_emit_response (GtkNativeDialog *self,
                                   int response_id)
diff --git a/gtk/gtknativedialog.h b/gtk/gtknativedialog.h
index 8d5bd60..de1a655 100644
--- a/gtk/gtknativedialog.h
+++ b/gtk/gtknativedialog.h
@@ -54,6 +54,8 @@ void                  gtk_native_dialog_show (GtkNativeDialog *self);
 GDK_AVAILABLE_IN_3_20
 void                  gtk_native_dialog_hide (GtkNativeDialog *self);
 GDK_AVAILABLE_IN_3_20
+void                  gtk_native_dialog_destroy (GtkNativeDialog *self);
+GDK_AVAILABLE_IN_3_20
 gboolean              gtk_native_dialog_get_visible (GtkNativeDialog *self);
 GDK_AVAILABLE_IN_3_20
 void                  gtk_native_dialog_set_modal (GtkNativeDialog *self,
diff --git a/tests/testgtk.c b/tests/testgtk.c
index 7dec326..d00e7f7 100644
--- a/tests/testgtk.c
+++ b/tests/testgtk.c
@@ -9660,6 +9660,13 @@ native_filter_changed (GtkWidget *combo,
     }
 }
 
+static void
+destroy_native (GtkFileChooserNative *native)
+{
+  gtk_native_dialog_destroy (GTK_NATIVE_DIALOG (native));
+  g_object_unref (native);
+}
+
 void
 create_native_dialogs (GtkWidget *widget)
 {
@@ -9681,7 +9688,7 @@ create_native_dialogs (GtkWidget *widget)
                                             "_accept&native",
                                             "_cancel__native");
 
-      g_signal_connect_swapped (G_OBJECT (window), "destroy", G_CALLBACK (g_object_unref), native);
+      g_signal_connect_swapped (G_OBJECT (window), "destroy", G_CALLBACK (destroy_native), native);
 
       gtk_file_chooser_add_shortcut_folder (GTK_FILE_CHOOSER (native),
                                             g_get_current_dir (),


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]