[gtk+] Add "parent widget" button to test property editor



commit c94002f8c0af429d57b0e4988f18909db98760fd
Author: Alexander Larsson <alexl redhat com>
Date:   Wed Nov 7 12:54:55 2012 +0100

    Add "parent widget" button to test property editor
    
    Without this its hard to access the properties of container
    widgets.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=687842

 tests/prop-editor.c |   36 +++++++++++++++++++++++++++++++++---
 1 files changed, 33 insertions(+), 3 deletions(-)
---
diff --git a/tests/prop-editor.c b/tests/prop-editor.c
index 6ba124f..7911d97 100644
--- a/tests/prop-editor.c
+++ b/tests/prop-editor.c
@@ -1346,15 +1346,29 @@ cells_from_object (GObject *object)
   return sw;
 }
 
+static void
+open_parent_widget (GtkWidget *button,
+		    GObject   *object)
+{
+  GtkWidget *parent;
+
+  parent = gtk_widget_get_parent (GTK_WIDGET (object));
+  if (parent != NULL)
+    create_prop_editor (G_OBJECT (parent), 0);
+}
+
+
 /* Pass zero for type if you want all properties */
 GtkWidget*
 create_prop_editor (GObject   *object,
                     GType      type)
 {
-  GtkWidget *win;
+  GtkWidget *win, *parent;
   GtkWidget *notebook;
   GtkWidget *properties;
   GtkWidget *label;
+  GtkWidget *button;
+  GtkWidget *vbox;
   gchar *title;
   GType *ifaces;
   guint n_ifaces;
@@ -1374,12 +1388,15 @@ create_prop_editor (GObject   *object,
   g_object_set_data_full (G_OBJECT (object), "prop-editor-win", win, model_destroy);
   g_object_set_data_full (G_OBJECT (win), "model-object", object, window_destroy);
 
+  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
+  gtk_container_add (GTK_CONTAINER (win), vbox);
+
   if (type == 0)
     {
       notebook = gtk_notebook_new ();
       gtk_notebook_set_tab_pos (GTK_NOTEBOOK (notebook), GTK_POS_LEFT);
 
-      gtk_container_add (GTK_CONTAINER (win), notebook);
+      gtk_box_pack_start (GTK_BOX (vbox), notebook, TRUE, TRUE, 0);
 
       type = G_TYPE_FROM_INSTANCE (object);
 
@@ -1437,11 +1454,24 @@ create_prop_editor (GObject   *object,
           gtk_notebook_append_page (GTK_NOTEBOOK (notebook),
                                     properties, label);
         }
+
+      if (GTK_IS_WIDGET (object))
+	{
+	  parent = gtk_widget_get_parent (GTK_WIDGET (object));
+	  if (parent != NULL)
+	    {
+	      button = gtk_button_new_with_label ("Parent widget");
+	      gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
+	      g_signal_connect (button, "clicked",
+				G_CALLBACK (open_parent_widget),
+				object);
+	    }
+	}
     }
   else
     {
       properties = properties_from_type (object, type);
-      gtk_container_add (GTK_CONTAINER (win), properties);
+      gtk_box_pack_start (GTK_BOX (vbox), properties, TRUE, TRUE, 0);
       title = g_strdup_printf ("Properties of %s", g_type_name (type));
       gtk_window_set_title (GTK_WINDOW (win), title);
       g_free (title);



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