Use a more reliable way of setting the initial state of PsppireDialogAction objects.
[pspp] / src / ui / gui / psppire-dialog-action.c
index ab04cae3021b51ee68f9793d96f2c01673180569..9eeed98d8dd608fe8b101159017cd5a1ea269ad6 100644 (file)
@@ -22,6 +22,7 @@
 #include "executor.h"
 #include "helper.h"
 #include "psppire-data-window.h"
+#include "builder-wrapper.h"
 
 static void psppire_dialog_action_init            (PsppireDialogAction      *act);
 static void psppire_dialog_action_class_init      (PsppireDialogActionClass *class);
@@ -188,14 +189,14 @@ on_destroy_dataset (GObject *w)
 {
   GHashTable *t = g_object_get_data (w, "thing-table");
   GSList *dl = g_object_get_data (w, "widget-list");
-  
+
   g_slist_free_full (dl, (GDestroyNotify) gtk_widget_destroy);
   g_hash_table_unref (t);
 }
 
 /* Each toplevel widget - that is the data window, which generally has a 1-1 association
    with a dataset - has an associated GHashTable.
-   
+
    This GHashTable is keyed by the address of a PsppireDialogAction, and its values
    are user determined pointers (typically a GtkBuilder*).
 
@@ -216,6 +217,14 @@ psppire_dialog_action_get_hash_table (PsppireDialogAction *act)
   return t;
 }
 
+GtkBuilder *
+psppire_dialog_action_get_xml (PsppireDialogAction *da)
+{
+  GHashTable *thing = psppire_dialog_action_get_hash_table (da);
+  GtkBuilder *xml = g_hash_table_lookup (thing, da);
+  return xml;
+}
+
 
 static void
 psppire_dialog_action_activate (PsppireDialogAction *act, GVariant *parameter)
@@ -230,9 +239,25 @@ psppire_dialog_action_activate (PsppireDialogAction *act, GVariant *parameter)
   wl = g_slist_prepend (wl, act->dialog);
   g_object_set_data (G_OBJECT (act->toplevel), "widget-list", wl);
 
-  if (class->activate)
-    class->activate (act, parameter);
+  if (class->initial_activate)
+    {
+      GHashTable *thing = psppire_dialog_action_get_hash_table (act);
+      GtkBuilder *xml = g_hash_table_lookup (thing, act);
+      if (xml == NULL)
+       {
+         xml = class->initial_activate (act, parameter);
+         g_hash_table_insert (thing, act, xml);
+       }
+    }
 
+  if (class->activate)
+    {
+      GHashTable *thing = psppire_dialog_action_get_hash_table (act);
+      GtkBuilder *xml = g_hash_table_lookup (thing, act);
+      if (xml != NULL)
+       class->activate (act, parameter);
+    }
+  
   gtk_window_set_transient_for (GTK_WINDOW (act->dialog),
                                GTK_WINDOW (act->toplevel));
 
@@ -285,8 +310,6 @@ psppire_dialog_action_class_init (PsppireDialogActionClass *class)
 
   class->generate_syntax = NULL;
 
-  class->activate = psppire_dialog_action_activate;
-
   g_object_class_install_property (object_class,
                                    PROP_TOPLEVEL,
                                    toplevel_spec);
@@ -309,7 +332,7 @@ psppire_dialog_action_init (PsppireDialogAction *act)
 }
 
 void
-psppire_dialog_action_set_valid_predicate (PsppireDialogAction *act, 
+psppire_dialog_action_set_valid_predicate (PsppireDialogAction *act,
                                           ContentsAreValid dialog_state_valid)
 {
   psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (act->dialog),
@@ -317,16 +340,8 @@ psppire_dialog_action_set_valid_predicate (PsppireDialogAction *act,
 }
 
 void
-psppire_dialog_action_set_refresh (PsppireDialogAction *pda, 
+psppire_dialog_action_set_refresh (PsppireDialogAction *pda,
                                   PsppireDialogActionRefresh refresh)
 {
   g_signal_connect_swapped (pda->dialog, "refresh", G_CALLBACK (refresh),  pda);
 }
-
-
-void 
-psppire_dialog_action_set_activation (gpointer class, activation activate)
-{
-  PSPPIRE_DIALOG_ACTION_CLASS (class)->activate = (void (*)(PsppireDialogAction *, GVariant *)) activate;
-}
-