1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2007, 2009, 2010, 2011, 2012 Free Software Foundation
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 /* This module implements the RECODE dialog.
19 It has two forms. One for recoding values into the same variable.
20 The second for recoding into different variables.
25 #include "recode-dialog.h"
29 #include "psppire-var-view.h"
34 #include <ui/gui/psppire-data-window.h>
35 #include <ui/gui/dialog-common.h>
36 #include <ui/gui/dict-display.h>
37 #include <ui/gui/builder-wrapper.h>
39 #include <ui/gui/psppire-dialog.h>
41 #include "psppire-val-chooser.h"
43 #include <ui/syntax-gen.h>
45 #include "psppire-acr.h"
48 #define _(msgid) gettext (msgid)
49 #define N_(msgid) msgid
52 /* Define a boxed type to represent a value which is a candidate
53 to replace an existing value */
66 enum new_value_type type;
74 static struct new_value *
75 new_value_copy (struct new_value *nv)
77 struct new_value *copy = g_memdup (nv, sizeof (*copy));
79 if ( nv->type == NV_STRING )
80 copy->v.s = xstrdup (nv->v.s);
87 new_value_free (struct new_value *nv)
89 if ( nv->type == NV_STRING )
97 new_value_to_string (const GValue *src, GValue *dest)
99 const struct new_value *nv = g_value_get_boxed (src);
107 gchar *text = g_strdup_printf ("%g", nv->v.v);
108 g_value_set_string (dest, text);
113 g_value_set_string (dest, nv->v.s);
116 g_value_set_string (dest, "COPY");
119 g_value_set_string (dest, "SYSMIS");
122 /* Shouldn't ever happen */
123 g_warning ("Invalid type in new recode value");
124 g_value_set_string (dest, "???");
130 new_value_get_type (void)
136 t = g_boxed_type_register_static ("psppire-recode-new-values",
137 (GBoxedCopyFunc) new_value_copy,
138 (GBoxedFreeFunc) new_value_free);
140 g_value_register_transform_func (t, G_TYPE_STRING,
141 new_value_to_string);
163 PsppireDialog *old_and_new_dialog;
165 GtkWidget *dict_treeview;
166 GtkWidget *variable_treeview;
167 GtkWidget *toggle[n_BUTTONS];
169 GtkWidget *strings_box;
170 GtkWidget *convert_button;
171 GtkWidget *new_copy_label;
173 GtkWidget *new_value_entry;
175 GtkWidget *old_value_chooser;
177 GtkListStore *value_map;
179 /* Indicates that the INTO {new variables} form of the dialog
185 gboolean input_var_is_string;
187 GtkWidget *new_name_entry;
188 GtkWidget *new_label_entry;
189 GtkWidget *change_button;
191 GtkWidget *string_button;
192 GtkWidget *width_entry;
194 /* A hash table of struct nlp's indexed by variable */
199 static void run_old_and_new_dialog (struct recode_dialog *rd);
202 refresh (PsppireDialog *dialog, struct recode_dialog *rd)
205 gtk_tree_view_get_model (GTK_TREE_VIEW (rd->variable_treeview));
207 gtk_list_store_clear (GTK_LIST_STORE (vars));
209 gtk_widget_set_sensitive (rd->change_button, FALSE);
210 gtk_widget_set_sensitive (rd->new_name_entry, FALSE);
211 gtk_widget_set_sensitive (rd->new_label_entry, FALSE);
213 if ( rd->different && rd->varmap )
214 g_hash_table_remove_all (rd->varmap);
216 gtk_list_store_clear (GTK_LIST_STORE (rd->value_map));
219 static char * generate_syntax (const struct recode_dialog *rd);
227 /* Dialog is valid iff at least one variable has been selected,
228 AND the list of mappings is not empty.
231 dialog_state_valid (gpointer data)
233 GtkTreeIter not_used;
234 struct recode_dialog *rd = data;
236 if ( ! rd->value_map )
239 if ( ! gtk_tree_model_get_iter_first (GTK_TREE_MODEL (rd->value_map),
245 GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (rd->variable_treeview));
247 if (g_hash_table_size (rd->varmap) != gtk_tree_model_iter_n_children (model, NULL) )
253 gtk_tree_view_get_model (GTK_TREE_VIEW (rd->variable_treeview));
255 if ( !gtk_tree_model_get_iter_first (vars, ¬_used))
263 on_old_new_show (struct recode_dialog *rd)
265 gtk_toggle_button_set_active
266 (GTK_TOGGLE_BUTTON (rd->toggle[BUTTON_NEW_VALUE]), TRUE);
268 g_signal_emit_by_name (rd->toggle[BUTTON_NEW_VALUE], "toggled");
270 g_object_set (rd->toggle[BUTTON_NEW_COPY],
271 "visible", rd->different, NULL);
273 g_object_set (rd->new_copy_label,
274 "visible", rd->different, NULL);
276 g_object_set (rd->strings_box,
277 "visible", rd->different, NULL);
280 /* Sets the sensitivity of TARGET dependent upon the active status
283 toggle_sensitivity (GtkToggleButton *button, GtkWidget *target)
285 gboolean state = gtk_toggle_button_get_active (button);
287 /* g_print ("%s Setting %p (%s) to %d because of %p\n",
288 __FUNCTION__, target, gtk_widget_get_name (target), state, button); */
290 gtk_widget_set_sensitive (target, state);
293 static void recode_dialog (PsppireDataWindow *de, gboolean diff);
296 /* Pops up the Recode Same version of the dialog box */
298 recode_same_dialog (PsppireDataWindow *de)
300 recode_dialog (de, FALSE);
303 /* Pops up the Recode Different version of the dialog box */
305 recode_different_dialog (PsppireDataWindow *de)
307 recode_dialog (de, TRUE);
311 /* This might need to be changed to something less naive.
312 In particular, what happends with dates, etc?
315 num_to_string (gdouble x)
317 return g_strdup_printf ("%g", x);
320 /* Callback which gets called when a new row is selected
321 in the acr's variable treeview.
322 We use if to set the togglebuttons and entries to correspond to the
326 on_acr_selection_change (GtkTreeSelection *selection, gpointer data)
328 struct recode_dialog *rd = data;
329 GtkTreeModel *model = NULL;
332 GValue ov_value = {0};
333 GValue nv_value = {0};
334 struct old_value *ov = NULL;
335 struct new_value *nv = NULL;
337 if ( ! gtk_tree_selection_get_selected (selection, &model, &iter) )
341 gtk_tree_model_get_value (GTK_TREE_MODEL (model), &iter,
342 COL_VALUE_OLD, &ov_value);
344 gtk_tree_model_get_value (GTK_TREE_MODEL (model), &iter,
345 COL_VALUE_NEW, &nv_value);
347 ov = g_value_get_boxed (&ov_value);
348 nv = g_value_get_boxed (&nv_value);
356 gchar *str = num_to_string (nv->v.v);
358 gtk_toggle_button_set_active
359 (GTK_TOGGLE_BUTTON (rd->toggle [BUTTON_NEW_VALUE]), TRUE);
361 gtk_entry_set_text (GTK_ENTRY (rd->new_value_entry), str);
366 gtk_toggle_button_set_active
367 (GTK_TOGGLE_BUTTON (rd->toggle [BUTTON_NEW_VALUE]), TRUE);
369 gtk_entry_set_text (GTK_ENTRY (rd->new_value_entry), nv->v.s);
372 gtk_toggle_button_set_active
373 (GTK_TOGGLE_BUTTON (rd->toggle [BUTTON_NEW_SYSMIS]), TRUE);
377 gtk_toggle_button_set_active
378 (GTK_TOGGLE_BUTTON (rd->toggle [BUTTON_NEW_COPY]), TRUE);
382 g_warning ("Invalid new value type");
386 g_value_unset (&nv_value);
389 psppire_val_chooser_set_status (PSPPIRE_VAL_CHOOSER (rd->old_value_chooser), ov);
392 /* Name-Label pair */
400 nlp_create (const char *name, const char *label)
402 struct nlp *nlp = xmalloc (sizeof *nlp);
404 nlp->name = g_strdup (name);
408 if ( 0 != strcmp ("", label))
409 nlp->label = g_strdup (label);
415 nlp_destroy (gpointer data)
417 struct nlp *nlp = data ;
427 /* Callback which gets called when a new row is selected
428 in the variable treeview.
429 It sets the name and label entry widgets to reflect the
430 currently selected row.
433 on_selection_change (GtkTreeSelection *selection, gpointer data)
435 struct recode_dialog *rd = data;
437 GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (rd->variable_treeview));
439 GList *rows = gtk_tree_selection_get_selected_rows (selection, &model);
441 if ( rows && !rows->next)
443 /* Exactly one row is selected */
445 struct variable *var;
449 gtk_widget_set_sensitive (rd->change_button, TRUE);
450 gtk_widget_set_sensitive (rd->new_name_entry, TRUE);
451 gtk_widget_set_sensitive (rd->new_label_entry, TRUE);
453 ok = gtk_tree_model_get_iter (model, &iter, (GtkTreePath*) rows->data);
454 g_return_if_fail (ok);
456 gtk_tree_model_get (model, &iter,
460 nlp = g_hash_table_lookup (rd->varmap, var);
464 gtk_entry_set_text (GTK_ENTRY (rd->new_name_entry), nlp->name ? nlp->name : "");
465 gtk_entry_set_text (GTK_ENTRY (rd->new_label_entry), nlp->label ? nlp->label : "");
469 gtk_entry_set_text (GTK_ENTRY (rd->new_name_entry), "");
470 gtk_entry_set_text (GTK_ENTRY (rd->new_label_entry), "");
475 gtk_widget_set_sensitive (rd->change_button, FALSE);
476 gtk_widget_set_sensitive (rd->new_name_entry, FALSE);
477 gtk_widget_set_sensitive (rd->new_label_entry, FALSE);
479 gtk_entry_set_text (GTK_ENTRY (rd->new_name_entry), "");
480 gtk_entry_set_text (GTK_ENTRY (rd->new_label_entry), "");
484 g_list_foreach (rows, (GFunc) gtk_tree_path_free, NULL);
489 on_string_toggled (GtkToggleButton *b, struct recode_dialog *rd)
492 if (! rd->input_var_is_string )
495 active = gtk_toggle_button_get_active (b);
496 gtk_widget_set_sensitive (rd->convert_button, !active);
501 on_convert_toggled (GtkToggleButton *b, struct recode_dialog *rd)
505 g_return_if_fail (rd->input_var_is_string);
507 active = gtk_toggle_button_get_active (b);
508 gtk_widget_set_sensitive (rd->string_button, !active);
512 on_change_clicked (GObject *obj, gpointer data)
514 struct recode_dialog *rd = data;
515 struct variable *var = NULL;
518 GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (rd->variable_treeview));
521 GtkTreeSelection *selection =
522 gtk_tree_view_get_selection (GTK_TREE_VIEW (rd->variable_treeview));
524 GList *rows = gtk_tree_selection_get_selected_rows (selection, &model);
526 const gchar *dest_var_name =
527 gtk_entry_get_text (GTK_ENTRY (rd->new_name_entry));
529 const gchar *dest_var_label =
530 gtk_entry_get_text (GTK_ENTRY (rd->new_label_entry));
532 if ( NULL == rows || rows->next != NULL)
535 gtk_tree_model_get_iter (model, &iter, rows->data);
537 gtk_tree_model_get (model, &iter, 0, &var, -1);
539 g_hash_table_remove (rd->varmap, var);
541 nlp = nlp_create (dest_var_name, dest_var_label);
543 g_hash_table_insert (rd->varmap, var, nlp);
545 gtk_tree_model_row_changed (model, rows->data, &iter);
548 g_list_foreach (rows, (GFunc) gtk_tree_path_free, NULL);
554 focus_value_entry (GtkWidget *w, struct recode_dialog *rd)
556 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (w)))
557 gtk_widget_grab_focus (rd->new_value_entry);
561 /* Callback for the new_value_entry and new_value_togglebutton widgets.
562 It's used to enable/disable the acr. */
564 set_acr (struct recode_dialog *rd)
568 if ( !gtk_toggle_button_get_active
569 (GTK_TOGGLE_BUTTON (rd->toggle[BUTTON_NEW_VALUE])))
571 psppire_acr_set_enabled (rd->acr, TRUE);
575 text = gtk_entry_get_text (GTK_ENTRY (rd->new_value_entry));
577 psppire_acr_set_enabled (rd->acr, !g_str_equal (text, ""));
581 render_new_var_name (GtkTreeViewColumn *tree_column,
582 GtkCellRenderer *cell,
583 GtkTreeModel *tree_model,
587 struct nlp *nlp = NULL;
588 struct recode_dialog *rd = data;
590 struct variable *var = NULL;
592 gtk_tree_model_get (tree_model, iter,
596 nlp = g_hash_table_lookup (rd->varmap, var);
599 g_object_set (cell, "text", nlp->name, NULL);
601 g_object_set (cell, "text", "", NULL);
607 recode_dialog (PsppireDataWindow *de, gboolean diff)
611 struct recode_dialog rd;
613 GtkBuilder *builder = builder_new ("recode.ui");
615 GtkWidget *selector = get_widget_assert (builder, "psppire-selector1");
617 GtkWidget *oldandnew = get_widget_assert (builder, "button1");
620 GtkWidget *output_variable_box = get_widget_assert (builder,"frame4");
622 rd.change_button = get_widget_assert (builder, "change-button");
624 rd.dialog = get_widget_assert (builder, "recode-dialog");
625 rd.dict_treeview = get_widget_assert (builder, "treeview1");
626 rd.variable_treeview = get_widget_assert (builder, "treeview2");
627 rd.new_name_entry = get_widget_assert (builder, "dest-name-entry");
628 rd.new_label_entry = get_widget_assert (builder, "dest-label-entry");
630 g_object_get (de->data_editor, "dictionary", &rd.dict, NULL);
632 rd.value_map = gtk_list_store_new (2,
633 old_value_get_type (),
634 new_value_get_type ()
637 g_object_set (output_variable_box, "visible", diff, NULL);
640 gtk_window_set_title (GTK_WINDOW (rd.dialog),
641 _("Recode into Different Variables"));
643 gtk_window_set_title (GTK_WINDOW (rd.dialog),
644 _("Recode into Same Variables"));
648 gtk_window_set_transient_for (GTK_WINDOW (rd.dialog), GTK_WINDOW (de));
650 g_object_set (rd.dict_treeview, "model", rd.dict, NULL);
654 GtkTreeSelection *sel;
656 GtkCellRenderer *renderer = gtk_cell_renderer_text_new ();
658 GtkTreeViewColumn *col = gtk_tree_view_column_new_with_attributes (_("New"),
663 gtk_tree_view_column_set_cell_data_func (col, renderer,
668 gtk_tree_view_append_column (GTK_TREE_VIEW (rd.variable_treeview), col);
671 col = gtk_tree_view_get_column (GTK_TREE_VIEW (rd.variable_treeview), 0);
673 g_object_set (col, "title", _("Old"), NULL);
675 g_object_set (rd.variable_treeview, "headers-visible", TRUE, NULL);
677 rd.varmap = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, nlp_destroy);
679 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (rd.variable_treeview));
681 g_signal_connect (sel, "changed",
682 G_CALLBACK (on_selection_change), &rd);
684 g_signal_connect (rd.change_button, "clicked",
685 G_CALLBACK (on_change_clicked), &rd);
689 psppire_selector_set_allow (PSPPIRE_SELECTOR (selector), homogeneous_types);
691 /* Set up the Old & New Values subdialog */
693 rd.string_button = get_widget_assert (builder, "checkbutton1");
694 rd.width_entry = get_widget_assert (builder, "spinbutton1");
696 rd.convert_button = get_widget_assert (builder, "checkbutton2");
698 rd.old_value_chooser = get_widget_assert (builder, "val-chooser");
700 rd.new_value_entry = get_widget_assert (builder, "entry1");
703 rd.toggle[BUTTON_NEW_VALUE] = get_widget_assert (builder, "radiobutton1");
704 rd.toggle[BUTTON_NEW_SYSMIS] = get_widget_assert (builder, "radiobutton2");
705 rd.toggle[BUTTON_NEW_COPY] = get_widget_assert (builder, "radiobutton3");
707 rd.new_copy_label = get_widget_assert (builder, "label3");
708 rd.strings_box = get_widget_assert (builder, "table3");
710 rd.old_and_new_dialog =
711 PSPPIRE_DIALOG (get_widget_assert (builder, "old-new-values-dialog"));
713 gtk_window_set_transient_for (GTK_WINDOW (rd.old_and_new_dialog),
716 rd.acr = PSPPIRE_ACR (get_widget_assert (builder, "psppire-acr1"));
718 g_signal_connect_swapped (rd.toggle[BUTTON_NEW_VALUE], "toggled",
719 G_CALLBACK (set_acr), &rd);
721 g_signal_connect_after (rd.toggle[BUTTON_NEW_VALUE], "toggled",
722 G_CALLBACK (focus_value_entry), &rd);
724 g_signal_connect_swapped (rd.new_value_entry, "changed",
725 G_CALLBACK (set_acr), &rd);
728 GtkTreeSelection *sel;
729 /* Remove the ACR's default column. We don't like it */
730 GtkTreeViewColumn *column = gtk_tree_view_get_column (rd.acr->tv, 0);
731 gtk_tree_view_remove_column (rd.acr->tv, column);
735 gtk_tree_view_column_new_with_attributes (_("Old"),
736 gtk_cell_renderer_text_new (),
740 gtk_tree_view_append_column (rd.acr->tv, column);
743 gtk_tree_view_column_new_with_attributes (_("New"),
744 gtk_cell_renderer_text_new (),
748 gtk_tree_view_append_column (rd.acr->tv, column);
749 g_object_set (rd.acr->tv, "headers-visible", TRUE, NULL);
752 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (rd.acr->tv));
753 g_signal_connect (sel, "changed",
754 G_CALLBACK (on_acr_selection_change), &rd);
758 g_signal_connect_swapped (oldandnew, "clicked",
759 G_CALLBACK (run_old_and_new_dialog), &rd);
762 g_signal_connect (rd.toggle[BUTTON_NEW_VALUE], "toggled",
763 G_CALLBACK (toggle_sensitivity), rd.new_value_entry);
765 g_signal_connect (rd.string_button, "toggled",
766 G_CALLBACK (toggle_sensitivity), rd.width_entry);
768 g_signal_connect (rd.string_button, "toggled",
769 G_CALLBACK (on_string_toggled), &rd);
771 g_signal_connect (rd.convert_button, "toggled",
772 G_CALLBACK (on_convert_toggled), &rd);
774 g_signal_connect_swapped (rd.old_and_new_dialog, "show",
775 G_CALLBACK (on_old_new_show), &rd);
778 g_signal_connect (rd.dialog, "refresh", G_CALLBACK (refresh), &rd);
781 psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (rd.dialog),
782 dialog_state_valid, &rd);
784 response = psppire_dialog_run (PSPPIRE_DIALOG (rd.dialog));
788 case GTK_RESPONSE_OK:
789 g_free (execute_syntax_string (de, generate_syntax (&rd)));
791 case PSPPIRE_RESPONSE_PASTE:
792 g_free (paste_syntax_to_window (generate_syntax (&rd)));
799 g_hash_table_destroy (rd.varmap);
801 gtk_list_store_clear (GTK_LIST_STORE (rd.value_map));
802 g_object_unref (rd.value_map);
804 g_object_unref (builder);
807 /* Initialise VAL to reflect the current status of RD */
809 set_old_value (GValue *val, const struct recode_dialog *rd)
811 PsppireValChooser *vc = PSPPIRE_VAL_CHOOSER (rd->old_value_chooser);
815 psppire_val_chooser_get_status (vc, &ov);
817 g_value_init (val, old_value_get_type ());
818 g_value_set_boxed (val, &ov);
824 /* Initialse VAL to reflect the current status of RD */
826 set_new_value (GValue *val, const struct recode_dialog *rd)
828 const gchar *text = NULL;
831 if ( gtk_toggle_button_get_active
832 (GTK_TOGGLE_BUTTON (rd->toggle [BUTTON_NEW_VALUE])))
834 text = gtk_entry_get_text (GTK_ENTRY (rd->new_value_entry));
836 nv.type = NV_NUMERIC;
838 (! rd->different && rd->input_var_is_string) ||
840 gtk_toggle_button_get_active
841 (GTK_TOGGLE_BUTTON (rd->string_button)))
847 if ( nv.type == NV_STRING )
848 nv.v.s = g_strdup (text);
850 nv.v.v = g_strtod (text, 0);
852 else if ( gtk_toggle_button_get_active
853 (GTK_TOGGLE_BUTTON (rd->toggle [BUTTON_NEW_COPY])))
858 else if ( gtk_toggle_button_get_active
859 (GTK_TOGGLE_BUTTON (rd->toggle [BUTTON_NEW_SYSMIS])))
866 g_value_init (val, new_value_get_type ());
867 g_value_set_boxed (val, &nv);
873 /* A function to set a value in a column in the ACR */
875 set_value (gint col, GValue *val, gpointer data)
877 struct recode_dialog *rd = data;
882 set_old_value (val, rd);
885 set_new_value (val, rd);
895 run_old_and_new_dialog (struct recode_dialog *rd)
898 GtkListStore *local_store = clone_list_store (rd->value_map);
900 psppire_acr_set_model (rd->acr, local_store);
901 psppire_acr_set_get_value_func (rd->acr, set_value, rd);
903 gtk_window_set_title (GTK_WINDOW (rd->old_and_new_dialog),
905 ? _("Recode into Different Variables: Old and New Values ")
906 : _("Recode into Same Variables: Old and New Values")
911 /* Find the type of the first variable (it's invariant that
912 all variables are of the same type) */
913 const struct variable *v;
915 GtkTreeModel *model =
916 gtk_tree_view_get_model (GTK_TREE_VIEW (rd->variable_treeview));
918 gboolean not_empty = gtk_tree_model_get_iter_first (model, &iter);
920 g_return_if_fail (not_empty);
922 gtk_tree_model_get (model, &iter, 0, &v, -1);
924 rd->input_var_is_string = var_is_alpha (v);
926 g_object_set (rd->old_value_chooser, "is-string", rd->input_var_is_string, NULL);
928 gtk_widget_set_sensitive (rd->toggle [BUTTON_NEW_SYSMIS],
931 gtk_widget_set_sensitive (rd->convert_button, var_is_alpha (v));
935 response = psppire_dialog_run (rd->old_and_new_dialog);
936 psppire_acr_set_model (rd->acr, NULL);
939 if ( response == PSPPIRE_RESPONSE_CONTINUE )
941 g_object_unref (rd->value_map);
942 rd->value_map = clone_list_store (local_store);
945 g_object_unref (local_store);
948 psppire_dialog_notify_change (PSPPIRE_DIALOG (rd->dialog));
952 /* Generate a syntax fragment for NV and append it to STR */
954 new_value_append_syntax (struct string *dds, const struct new_value *nv)
959 ds_put_c_format (dds, "%g", nv->v.v);
962 syntax_gen_string (dds, ss_cstr (nv->v.s));
965 ds_put_cstr (dds, "COPY");
968 ds_put_cstr (dds, "SYSMIS");
971 /* Shouldn't ever happen */
972 g_warning ("Invalid type in new recode value");
973 ds_put_cstr (dds, "???");
980 generate_syntax (const struct recode_dialog *rd)
987 ds_init_empty (&dds);
990 /* Declare new string variables if applicable */
991 if ( rd->different &&
992 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->string_button)))
996 struct variable *var = NULL;
997 struct nlp *nlp = NULL;
999 g_hash_table_iter_init (&iter, rd->varmap);
1000 while (g_hash_table_iter_next (&iter, (void**) &var, (void**) &nlp))
1002 ds_put_cstr (&dds, "\nSTRING ");
1003 ds_put_cstr (&dds, nlp->name);
1004 ds_put_c_format (&dds, " (A%d).",
1006 gtk_spin_button_get_value (GTK_SPIN_BUTTON (rd->width_entry) )
1011 ds_put_cstr (&dds, "\nRECODE ");
1013 psppire_var_view_append_names_str (PSPPIRE_VAR_VIEW (rd->variable_treeview), 0, &dds);
1015 ds_put_cstr (&dds, "\n\t");
1017 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->convert_button)))
1019 ds_put_cstr (&dds, "(CONVERT) ");
1022 for (ok = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (rd->value_map),
1025 ok = gtk_tree_model_iter_next (GTK_TREE_MODEL (rd->value_map), &iter))
1027 GValue ov_value = {0};
1028 GValue nv_value = {0};
1029 struct old_value *ov;
1030 struct new_value *nv;
1031 gtk_tree_model_get_value (GTK_TREE_MODEL (rd->value_map), &iter,
1032 COL_VALUE_OLD, &ov_value);
1034 gtk_tree_model_get_value (GTK_TREE_MODEL (rd->value_map), &iter,
1035 COL_VALUE_NEW, &nv_value);
1037 ov = g_value_get_boxed (&ov_value);
1038 nv = g_value_get_boxed (&nv_value);
1040 ds_put_cstr (&dds, "(");
1042 old_value_append_syntax (&dds, ov);
1043 ds_put_cstr (&dds, " = ");
1044 new_value_append_syntax (&dds, nv);
1046 ds_put_cstr (&dds, ") ");
1047 g_value_unset (&ov_value);
1048 g_value_unset (&nv_value);
1052 if ( rd->different )
1056 ds_put_cstr (&dds, "\n\tINTO ");
1058 for (ok = psppire_var_view_get_iter_first (PSPPIRE_VAR_VIEW (rd->variable_treeview), &iter);
1060 ok = psppire_var_view_get_iter_next (PSPPIRE_VAR_VIEW (rd->variable_treeview), &iter))
1062 struct nlp *nlp = NULL;
1063 const struct variable *var = psppire_var_view_get_variable (PSPPIRE_VAR_VIEW (rd->variable_treeview), 0, &iter);
1065 nlp = g_hash_table_lookup (rd->varmap, var);
1067 ds_put_cstr (&dds, nlp->name);
1068 ds_put_cstr (&dds, " ");
1072 ds_put_cstr (&dds, ".");
1074 /* If applicable, set labels for the new variables. */
1075 if ( rd->different )
1077 GHashTableIter iter;
1079 struct variable *var = NULL;
1080 struct nlp *nlp = NULL;
1082 g_hash_table_iter_init (&iter, rd->varmap);
1083 while (g_hash_table_iter_next (&iter, (void**) &var, (void**) &nlp))
1088 ds_init_empty (&sl);
1089 syntax_gen_string (&sl, ss_cstr (nlp->label));
1090 ds_put_c_format (&dds, "\nVARIABLE LABELS %s %s.",
1091 nlp->name, ds_cstr (&sl));
1098 ds_put_cstr (&dds, "\nEXECUTE.\n");
1101 text = ds_steal_cstr (&dds);