Persist dialog box widget settings.
[pspp] / src / ui / gui / psppire-dialog-action-sort.c
index 2a80a6e7dc5471ba5830135e6b614de43979cdaf..024a659de15992d725abdd16eccf07934d7a081e 100644 (file)
@@ -36,7 +36,8 @@ generate_syntax (PsppireDialogAction *act)
   gchar *text;
   GString *string = g_string_new ("SORT CASES BY ");
 
-  gint n_vars = psppire_var_view_append_names (scd->variables, 0, string);
+  PsppireVarView *var_view = PSPPIRE_VAR_VIEW (scd->variables);
+  gint n_vars = psppire_var_view_append_names (var_view, 0, string);
 
   if ( n_vars == 0 )
     {
@@ -45,7 +46,8 @@ generate_syntax (PsppireDialogAction *act)
   else
     {
       const char up_down =
-       gtk_toggle_button_get_active (scd->ascending) ? 'A' : 'D';
+       (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (scd->ascending))
+         ? 'A' : 'D');
       g_string_append_printf (string, "(%c)", up_down);
       g_string_append (string, ".");
     }
@@ -66,14 +68,14 @@ reset (PsppireDialogAction *act)
 
   gtk_list_store_clear (GTK_LIST_STORE (liststore));
 
-  gtk_toggle_button_set_active (scd->ascending, TRUE);
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (scd->ascending), TRUE);
 }
 
 
 
 
 static gboolean
-dialog_state_valid (PsppireDialogAction *act)
+dialog_state_valid (gpointer act)
 {
   PsppireDialogActionSort *scd = PSPPIRE_DIALOG_ACTION_SORT (act);
   GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (scd->variables));
@@ -93,11 +95,18 @@ psppire_dialog_action_sort_activate (GtkAction *a)
   PsppireDialogAction *pda = PSPPIRE_DIALOG_ACTION (a);
   PsppireDialogActionSort *act = PSPPIRE_DIALOG_ACTION_SORT (a);
 
-  GtkBuilder *xml = builder_new ("sort.ui");
-  pda->dialog = get_widget_assert   (xml, "sort-cases-dialog");
-  pda->source = get_widget_assert   (xml, "sort-cases-treeview1");
+  GHashTable *thing = psppire_dialog_action_get_pointer (pda);
+  GtkBuilder *xml = g_hash_table_lookup (thing, a);
+  if (!xml)
+    {
+      xml = builder_new ("sort.ui");
+      g_hash_table_insert (thing, a, xml);
+    }
+
+  pda->dialog = get_widget_assert (xml, "sort-cases-dialog");
+  pda->source = get_widget_assert (xml, "sort-cases-treeview1");
   
-  act->variables =  get_widget_assert   (xml, "sort-cases-treeview2");
+  act->variables =  get_widget_assert (xml, "sort-cases-treeview2");
   act->ascending = get_widget_assert (xml, "sort-cases-radiobutton0");
 
   psppire_dialog_action_set_refresh (pda, reset);
@@ -112,10 +121,8 @@ psppire_dialog_action_sort_activate (GtkAction *a)
 static void
 psppire_dialog_action_sort_class_init (PsppireDialogActionSortClass *class)
 {
-  GtkActionClass *action_class = GTK_ACTION_CLASS (class);
-  PsppireDialogActionClass *pdac = PSPPIRE_DIALOG_ACTION_CLASS (class);
-
-  action_class->activate = psppire_dialog_action_sort_activate;
+ PsppireDialogActionClass *pdac = PSPPIRE_DIALOG_ACTION_CLASS (class);
+  psppire_dialog_action_set_activation (class, psppire_dialog_action_sort_activate);
 
   pdac->generate_syntax = generate_syntax;
 }