Merge commit 'window-manager/master'
[pspp-builds.git] / src / ui / gui / helper.c
index 6a3a0f9e6ce0b83ee360f62ca9f790205084da7e..b1fdb27193df933ab583420693bd6b6b5f8481ec 100644 (file)
@@ -119,6 +119,19 @@ builder_new_real (const gchar *name)
 }
 
 
+GObject *
+get_object_assert (GtkBuilder *builder, const gchar *name)
+{
+  GObject *o = NULL;
+  g_assert (name);
+
+  o = gtk_builder_get_object (builder, name);
+
+  if ( !o )
+    g_critical ("Object \"%s\" could not be found\n", name);
+
+  return o;
+}
 
 GtkWidget *
 get_widget_assert (gpointer x, const gchar *name)
@@ -166,8 +179,38 @@ give_help (void)
   gtk_widget_destroy (dialog);
 }
 
-void
-connect_help (GladeXML *xml)
+static void
+connect_help_builder (GtkBuilder *xml)
+{
+  GSList *helps = gtk_builder_get_objects (xml);
+
+  GSList *i;
+  for ( i = helps; i ; i = g_slist_next (i))
+    {
+      GObject *o = i->data;
+      if ( GTK_IS_WIDGET (o) )
+       {
+         gchar *name = NULL;
+         gchar s[12] = {0};
+         g_object_get (o, "name", &name, NULL);
+
+         if ( name)
+           strncpy (s, name, 11);
+         s[11] = '\0';
+
+
+         if ( 0 == strcmp ("help_button", s))
+           {
+           g_signal_connect (GTK_WIDGET (o), "clicked", give_help, 0);
+           }
+       }
+    }
+
+  g_slist_free (helps);
+}
+
+static void
+connect_help_glade (GladeXML *xml)
 {
   GList *helps = glade_xml_get_widget_prefix (xml, "help_button_");
 
@@ -179,6 +222,22 @@ connect_help (GladeXML *xml)
 }
 
 
+void
+connect_help (gpointer xml)
+{
+  if (GTK_IS_BUILDER (xml))
+    connect_help_builder (GTK_BUILDER (xml));
+
+  else if (GLADE_IS_XML (xml))
+    connect_help_glade (GLADE_XML (xml));
+
+  else
+    {
+      g_error ("XML of type %s", G_OBJECT_TYPE_NAME (xml));
+    }
+}
+
+
 
 void
 reference_manual (GtkMenuItem *menu, gpointer data)
@@ -321,7 +380,6 @@ clone_list_store (const GtkListStore *src)
 }
 
 
-
 void
 paste_syntax_in_new_window (const gchar *syntax)
 {