Descriptives Dialog: Avoid multiple appendages to the statistics list box
[pspp] / src / ui / gui / psppire-dialog-action-descriptives.c
index 1b5b7a5781618738fece2f1f3beb9f7a8ba5b562..2d6cca337d4219d88691b5a0a85af3e8cdf83294 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPPIRE - a graphical user interface for PSPP.
-   Copyright (C) 2012  Free Software Foundation
+   Copyright (C) 2015  Free Software Foundation
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -192,29 +192,35 @@ dialog_refresh (PsppireDialogAction *scd_)
   gtk_toggle_button_set_active (scd->save_z_scores, false);
 }
 
+
 static void
 psppire_dialog_action_descriptives_activate (GtkAction *a)
 {
   PsppireDialogAction *pda = PSPPIRE_DIALOG_ACTION (a);
   PsppireDialogActionDescriptives *act = PSPPIRE_DIALOG_ACTION_DESCRIPTIVES (a);
 
-  GtkBuilder *xml = builder_new ("descriptives.ui");
-
-  GtkWidget *stats_treeview = get_widget_assert    (xml, "statistics");
+  GHashTable *thing = psppire_dialog_action_get_pointer (pda);
+  GtkBuilder *xml = g_hash_table_lookup (thing, a);
+  if (!xml)
+    {
+      xml = builder_new ("descriptives.ui");
+      g_hash_table_insert (thing, a, xml);
+
+      GtkWidget *stats_treeview = get_widget_assert (xml, "statistics");
+      psppire_checkbox_treeview_populate (PSPPIRE_CHECKBOX_TREEVIEW (stats_treeview),
+                                         B_DS_DEFAULT,
+                                         N_DESCRIPTIVE_STATS, stats);
+      act->stats = gtk_tree_view_get_model (GTK_TREE_VIEW (stats_treeview));
+    }
 
   pda->dialog = get_widget_assert   (xml, "descriptives-dialog");
   pda->source = get_widget_assert   (xml, "all-variables");
   act->variables =   get_widget_assert   (xml, "stat-variables");
 
   g_object_set (pda->source,
-       "predicate", var_is_numeric, NULL);
-
-  psppire_checkbox_treeview_populate (PSPPIRE_CHECKBOX_TREEVIEW (stats_treeview),
-                                     B_DS_DEFAULT,
-                                     N_DESCRIPTIVE_STATS, stats);
+               "predicate", var_is_numeric, NULL);
 
   act->stat_vars = GTK_TREE_VIEW (act->variables);
-  act->stats = gtk_tree_view_get_model (GTK_TREE_VIEW (stats_treeview));
   
   act->include_user_missing =
     GTK_TOGGLE_BUTTON (get_widget_assert (xml, "include_user_missing"));
@@ -227,14 +233,12 @@ psppire_dialog_action_descriptives_activate (GtkAction *a)
   psppire_dialog_action_set_refresh (pda, dialog_refresh);
 
   PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_descriptives_parent_class)->activate (pda);
-
-  g_object_unref (xml);
 }
 
 static void
 psppire_dialog_action_descriptives_class_init (PsppireDialogActionDescriptivesClass *class)
 {
-  GTK_ACTION_CLASS (class)->activate = psppire_dialog_action_descriptives_activate;
+  psppire_dialog_action_set_activation (class, psppire_dialog_action_descriptives_activate);
 
   PSPPIRE_DIALOG_ACTION_CLASS (class)->generate_syntax = generate_syntax;
 }