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>
40 #include <ui/gui/psppire-var-store.h>
42 #include "psppire-val-chooser.h"
44 #include <ui/syntax-gen.h>
46 #include "psppire-acr.h"
49 #define _(msgid) gettext (msgid)
50 #define N_(msgid) msgid
53 /* Define a boxed type to represent a value which is a candidate
54 to replace an existing value */
67 enum new_value_type type;
75 static struct new_value *
76 new_value_copy (struct new_value *nv)
78 struct new_value *copy = g_memdup (nv, sizeof (*copy));
80 if ( nv->type == NV_STRING )
81 copy->v.s = xstrdup (nv->v.s);
88 new_value_free (struct new_value *nv)
90 if ( nv->type == NV_STRING )
98 new_value_to_string (const GValue *src, GValue *dest)
100 const struct new_value *nv = g_value_get_boxed (src);
108 gchar *text = g_strdup_printf ("%g", nv->v.v);
109 g_value_set_string (dest, text);
114 g_value_set_string (dest, nv->v.s);
117 g_value_set_string (dest, "COPY");
120 g_value_set_string (dest, "SYSMIS");
123 /* Shouldn't ever happen */
124 g_warning ("Invalid type in new recode value");
125 g_value_set_string (dest, "???");
131 new_value_get_type (void)
137 t = g_boxed_type_register_static ("psppire-recode-new-values",
138 (GBoxedCopyFunc) new_value_copy,
139 (GBoxedFreeFunc) new_value_free);
141 g_value_register_transform_func (t, G_TYPE_STRING,
142 new_value_to_string);
164 PsppireDialog *old_and_new_dialog;
166 GtkWidget *dict_treeview;
167 GtkWidget *variable_treeview;
168 GtkWidget *toggle[n_BUTTONS];
170 GtkWidget *strings_box;
171 GtkWidget *convert_button;
172 GtkWidget *new_copy_label;
174 GtkWidget *new_value_entry;
176 GtkWidget *old_value_chooser;
178 GtkListStore *value_map;
180 /* Indicates that the INTO {new variables} form of the dialog
186 gboolean input_var_is_string;
188 GtkWidget *new_name_entry;
189 GtkWidget *new_label_entry;
190 GtkWidget *change_button;
192 GtkWidget *string_button;
193 GtkWidget *width_entry;
195 /* A hash table of struct nlp's indexed by variable */
200 static void run_old_and_new_dialog (struct recode_dialog *rd);
203 refresh (PsppireDialog *dialog, struct recode_dialog *rd)
206 gtk_tree_view_get_model (GTK_TREE_VIEW (rd->variable_treeview));
208 gtk_list_store_clear (GTK_LIST_STORE (vars));
210 gtk_widget_set_sensitive (rd->change_button, FALSE);
211 gtk_widget_set_sensitive (rd->new_name_entry, FALSE);
212 gtk_widget_set_sensitive (rd->new_label_entry, FALSE);
214 if ( rd->different && rd->varmap )
215 g_hash_table_remove_all (rd->varmap);
217 gtk_list_store_clear (GTK_LIST_STORE (rd->value_map));
220 static char * generate_syntax (const struct recode_dialog *rd);
228 /* Dialog is valid iff at least one variable has been selected,
229 AND the list of mappings is not empty.
232 dialog_state_valid (gpointer data)
234 GtkTreeIter not_used;
235 struct recode_dialog *rd = data;
237 if ( ! rd->value_map )
240 if ( ! gtk_tree_model_get_iter_first (GTK_TREE_MODEL (rd->value_map),
246 GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (rd->variable_treeview));
248 if (g_hash_table_size (rd->varmap) != gtk_tree_model_iter_n_children (model, NULL) )
254 gtk_tree_view_get_model (GTK_TREE_VIEW (rd->variable_treeview));
256 if ( !gtk_tree_model_get_iter_first (vars, ¬_used))
264 on_old_new_show (struct recode_dialog *rd)
266 gtk_toggle_button_set_active
267 (GTK_TOGGLE_BUTTON (rd->toggle[BUTTON_NEW_VALUE]), TRUE);
269 g_signal_emit_by_name (rd->toggle[BUTTON_NEW_VALUE], "toggled");
271 g_object_set (rd->toggle[BUTTON_NEW_COPY],
272 "visible", rd->different, NULL);
274 g_object_set (rd->new_copy_label,
275 "visible", rd->different, NULL);
277 g_object_set (rd->strings_box,
278 "visible", rd->different, NULL);
281 /* Sets the sensitivity of TARGET dependent upon the active status
284 toggle_sensitivity (GtkToggleButton *button, GtkWidget *target)
286 gboolean state = gtk_toggle_button_get_active (button);
288 /* g_print ("%s Setting %p (%s) to %d because of %p\n",
289 __FUNCTION__, target, gtk_widget_get_name (target), state, button); */
291 gtk_widget_set_sensitive (target, state);
294 static void recode_dialog (PsppireDataWindow *de, gboolean diff);
297 /* Pops up the Recode Same version of the dialog box */
299 recode_same_dialog (PsppireDataWindow *de)
301 recode_dialog (de, FALSE);
304 /* Pops up the Recode Different version of the dialog box */
306 recode_different_dialog (PsppireDataWindow *de)
308 recode_dialog (de, TRUE);
312 /* This might need to be changed to something less naive.
313 In particular, what happends with dates, etc?
316 num_to_string (gdouble x)
318 return g_strdup_printf ("%g", x);
321 /* Callback which gets called when a new row is selected
322 in the acr's variable treeview.
323 We use if to set the togglebuttons and entries to correspond to the
327 on_acr_selection_change (GtkTreeSelection *selection, gpointer data)
329 struct recode_dialog *rd = data;
330 GtkTreeModel *model = NULL;
333 GValue ov_value = {0};
334 GValue nv_value = {0};
335 struct old_value *ov = NULL;
336 struct new_value *nv = NULL;
338 if ( ! gtk_tree_selection_get_selected (selection, &model, &iter) )
342 gtk_tree_model_get_value (GTK_TREE_MODEL (model), &iter,
343 COL_VALUE_OLD, &ov_value);
345 gtk_tree_model_get_value (GTK_TREE_MODEL (model), &iter,
346 COL_VALUE_NEW, &nv_value);
348 ov = g_value_get_boxed (&ov_value);
349 nv = g_value_get_boxed (&nv_value);
357 gchar *str = num_to_string (nv->v.v);
359 gtk_toggle_button_set_active
360 (GTK_TOGGLE_BUTTON (rd->toggle [BUTTON_NEW_VALUE]), TRUE);
362 gtk_entry_set_text (GTK_ENTRY (rd->new_value_entry), str);
367 gtk_toggle_button_set_active
368 (GTK_TOGGLE_BUTTON (rd->toggle [BUTTON_NEW_VALUE]), TRUE);
370 gtk_entry_set_text (GTK_ENTRY (rd->new_value_entry), nv->v.s);
373 gtk_toggle_button_set_active
374 (GTK_TOGGLE_BUTTON (rd->toggle [BUTTON_NEW_SYSMIS]), TRUE);
378 gtk_toggle_button_set_active
379 (GTK_TOGGLE_BUTTON (rd->toggle [BUTTON_NEW_COPY]), TRUE);
383 g_warning ("Invalid new value type");
387 g_value_unset (&nv_value);
390 psppire_val_chooser_set_status (PSPPIRE_VAL_CHOOSER (rd->old_value_chooser), ov);
393 /* Name-Label pair */
401 nlp_create (const char *name, const char *label)
403 struct nlp *nlp = xmalloc (sizeof *nlp);
405 nlp->name = g_strdup (name);
409 if ( 0 != strcmp ("", label))
410 nlp->label = g_strdup (label);
416 nlp_destroy (gpointer data)
418 struct nlp *nlp = data ;
428 /* Callback which gets called when a new row is selected
429 in the variable treeview.
430 It sets the name and label entry widgets to reflect the
431 currently selected row.
434 on_selection_change (GtkTreeSelection *selection, gpointer data)
436 struct recode_dialog *rd = data;
438 GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (rd->variable_treeview));
440 GList *rows = gtk_tree_selection_get_selected_rows (selection, &model);
442 if ( rows && !rows->next)
444 /* Exactly one row is selected */
446 struct variable *var;
450 gtk_widget_set_sensitive (rd->change_button, TRUE);
451 gtk_widget_set_sensitive (rd->new_name_entry, TRUE);
452 gtk_widget_set_sensitive (rd->new_label_entry, TRUE);
454 ok = gtk_tree_model_get_iter (model, &iter, (GtkTreePath*) rows->data);
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);
553 /* Callback for the new_value_entry and new_value_togglebutton widgets.
554 It's used to enable/disable the acr. */
556 set_acr (struct recode_dialog *rd)
560 if ( !gtk_toggle_button_get_active
561 (GTK_TOGGLE_BUTTON (rd->toggle[BUTTON_NEW_VALUE])))
563 psppire_acr_set_enabled (rd->acr, TRUE);
567 text = gtk_entry_get_text (GTK_ENTRY (rd->new_value_entry));
569 psppire_acr_set_enabled (rd->acr, !g_str_equal (text, ""));
573 render_new_var_name (GtkTreeViewColumn *tree_column,
574 GtkCellRenderer *cell,
575 GtkTreeModel *tree_model,
579 struct nlp *nlp = NULL;
580 struct recode_dialog *rd = data;
582 struct variable *var = NULL;
584 gtk_tree_model_get (tree_model, iter,
588 nlp = g_hash_table_lookup (rd->varmap, var);
591 g_object_set (cell, "text", nlp->name, NULL);
593 g_object_set (cell, "text", "", NULL);
599 recode_dialog (PsppireDataWindow *de, gboolean diff)
603 struct recode_dialog rd;
605 GtkBuilder *builder = builder_new ("recode.ui");
607 GtkWidget *selector = get_widget_assert (builder, "psppire-selector1");
609 GtkWidget *oldandnew = get_widget_assert (builder, "button1");
612 GtkWidget *output_variable_box = get_widget_assert (builder,"frame4");
614 PsppireVarStore *vs = NULL;
615 g_object_get (de->data_editor, "var-store", &vs, NULL);
617 rd.change_button = get_widget_assert (builder, "change-button");
619 rd.dialog = get_widget_assert (builder, "recode-dialog");
620 rd.dict_treeview = get_widget_assert (builder, "treeview1");
621 rd.variable_treeview = get_widget_assert (builder, "treeview2");
622 rd.new_name_entry = get_widget_assert (builder, "dest-name-entry");
623 rd.new_label_entry = get_widget_assert (builder, "dest-label-entry");
625 g_object_get (vs, "dictionary", &rd.dict, NULL);
627 rd.value_map = gtk_list_store_new (2,
628 old_value_get_type (),
629 new_value_get_type ()
632 g_object_set (output_variable_box, "visible", diff, NULL);
635 gtk_window_set_title (GTK_WINDOW (rd.dialog),
636 _("Recode into Different Variables"));
638 gtk_window_set_title (GTK_WINDOW (rd.dialog),
639 _("Recode into Same Variables"));
643 gtk_window_set_transient_for (GTK_WINDOW (rd.dialog), GTK_WINDOW (de));
645 g_object_set (rd.dict_treeview, "model", rd.dict, NULL);
649 GtkTreeSelection *sel;
651 GtkCellRenderer *renderer = gtk_cell_renderer_text_new ();
653 GtkTreeViewColumn *col = gtk_tree_view_column_new_with_attributes (_("New"),
658 gtk_tree_view_column_set_cell_data_func (col, renderer,
663 gtk_tree_view_append_column (GTK_TREE_VIEW (rd.variable_treeview), col);
666 col = gtk_tree_view_get_column (GTK_TREE_VIEW (rd.variable_treeview), 0);
668 g_object_set (col, "title", _("Old"), NULL);
670 g_object_set (rd.variable_treeview, "headers-visible", TRUE, NULL);
672 rd.varmap = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, nlp_destroy);
674 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (rd.variable_treeview));
676 g_signal_connect (sel, "changed",
677 G_CALLBACK (on_selection_change), &rd);
679 g_signal_connect (rd.change_button, "clicked",
680 G_CALLBACK (on_change_clicked), &rd);
684 psppire_selector_set_allow (PSPPIRE_SELECTOR (selector), homogeneous_types);
686 /* Set up the Old & New Values subdialog */
688 rd.string_button = get_widget_assert (builder, "checkbutton1");
689 rd.width_entry = get_widget_assert (builder, "spinbutton1");
691 rd.convert_button = get_widget_assert (builder, "checkbutton2");
693 rd.old_value_chooser = get_widget_assert (builder, "val-chooser");
695 rd.new_value_entry = get_widget_assert (builder, "entry1");
698 rd.toggle[BUTTON_NEW_VALUE] = get_widget_assert (builder, "radiobutton1");
699 rd.toggle[BUTTON_NEW_SYSMIS] = get_widget_assert (builder, "radiobutton2");
700 rd.toggle[BUTTON_NEW_COPY] = get_widget_assert (builder, "radiobutton3");
702 rd.new_copy_label = get_widget_assert (builder, "label3");
703 rd.strings_box = get_widget_assert (builder, "table3");
705 rd.old_and_new_dialog =
706 PSPPIRE_DIALOG (get_widget_assert (builder, "old-new-values-dialog"));
708 gtk_window_set_transient_for (GTK_WINDOW (rd.old_and_new_dialog),
711 rd.acr = PSPPIRE_ACR (get_widget_assert (builder, "psppire-acr1"));
713 g_signal_connect_swapped (rd.toggle[BUTTON_NEW_VALUE], "toggled",
714 G_CALLBACK (set_acr), &rd);
716 g_signal_connect_swapped (rd.new_value_entry, "changed",
717 G_CALLBACK (set_acr), &rd);
720 GtkTreeSelection *sel;
721 /* Remove the ACR's default column. We don't like it */
722 GtkTreeViewColumn *column = gtk_tree_view_get_column (rd.acr->tv, 0);
723 gtk_tree_view_remove_column (rd.acr->tv, column);
727 gtk_tree_view_column_new_with_attributes (_("Old"),
728 gtk_cell_renderer_text_new (),
732 gtk_tree_view_append_column (rd.acr->tv, column);
735 gtk_tree_view_column_new_with_attributes (_("New"),
736 gtk_cell_renderer_text_new (),
740 gtk_tree_view_append_column (rd.acr->tv, column);
741 g_object_set (rd.acr->tv, "headers-visible", TRUE, NULL);
744 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (rd.acr->tv));
745 g_signal_connect (sel, "changed",
746 G_CALLBACK (on_acr_selection_change), &rd);
750 g_signal_connect_swapped (oldandnew, "clicked",
751 G_CALLBACK (run_old_and_new_dialog), &rd);
754 g_signal_connect (rd.toggle[BUTTON_NEW_VALUE], "toggled",
755 G_CALLBACK (toggle_sensitivity), rd.new_value_entry);
757 g_signal_connect (rd.string_button, "toggled",
758 G_CALLBACK (toggle_sensitivity), rd.width_entry);
760 g_signal_connect (rd.string_button, "toggled",
761 G_CALLBACK (on_string_toggled), &rd);
763 g_signal_connect (rd.convert_button, "toggled",
764 G_CALLBACK (on_convert_toggled), &rd);
766 g_signal_connect_swapped (rd.old_and_new_dialog, "show",
767 G_CALLBACK (on_old_new_show), &rd);
770 g_signal_connect (rd.dialog, "refresh", G_CALLBACK (refresh), &rd);
773 psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (rd.dialog),
774 dialog_state_valid, &rd);
776 response = psppire_dialog_run (PSPPIRE_DIALOG (rd.dialog));
780 case GTK_RESPONSE_OK:
781 g_free (execute_syntax_string (de, generate_syntax (&rd)));
783 case PSPPIRE_RESPONSE_PASTE:
784 g_free (paste_syntax_to_window (generate_syntax (&rd)));
791 g_hash_table_destroy (rd.varmap);
793 gtk_list_store_clear (GTK_LIST_STORE (rd.value_map));
794 g_object_unref (rd.value_map);
796 g_object_unref (builder);
799 /* Initialise VAL to reflect the current status of RD */
801 set_old_value (GValue *val, const struct recode_dialog *rd)
803 PsppireValChooser *vc = PSPPIRE_VAL_CHOOSER (rd->old_value_chooser);
807 psppire_val_chooser_get_status (vc, &ov);
809 g_value_init (val, old_value_get_type ());
810 g_value_set_boxed (val, &ov);
816 /* Initialse VAL to reflect the current status of RD */
818 set_new_value (GValue *val, const struct recode_dialog *rd)
820 const gchar *text = NULL;
823 if ( gtk_toggle_button_get_active
824 (GTK_TOGGLE_BUTTON (rd->toggle [BUTTON_NEW_VALUE])))
826 text = gtk_entry_get_text (GTK_ENTRY (rd->new_value_entry));
828 nv.type = NV_NUMERIC;
830 (! rd->different && rd->input_var_is_string) ||
832 gtk_toggle_button_get_active
833 (GTK_TOGGLE_BUTTON (rd->string_button)))
839 if ( nv.type == NV_STRING )
840 nv.v.s = g_strdup (text);
842 nv.v.v = g_strtod (text, 0);
844 else if ( gtk_toggle_button_get_active
845 (GTK_TOGGLE_BUTTON (rd->toggle [BUTTON_NEW_COPY])))
850 else if ( gtk_toggle_button_get_active
851 (GTK_TOGGLE_BUTTON (rd->toggle [BUTTON_NEW_SYSMIS])))
858 g_value_init (val, new_value_get_type ());
859 g_value_set_boxed (val, &nv);
865 /* A function to set a value in a column in the ACR */
867 set_value (gint col, GValue *val, gpointer data)
869 struct recode_dialog *rd = data;
874 set_old_value (val, rd);
877 set_new_value (val, rd);
887 run_old_and_new_dialog (struct recode_dialog *rd)
890 GtkListStore *local_store = clone_list_store (rd->value_map);
892 psppire_acr_set_model (rd->acr, local_store);
893 psppire_acr_set_get_value_func (rd->acr, set_value, rd);
895 gtk_window_set_title (GTK_WINDOW (rd->old_and_new_dialog),
897 ? _("Recode into Different Variables: Old and New Values ")
898 : _("Recode into Same Variables: Old and New Values")
903 /* Find the type of the first variable (it's invariant that
904 all variables are of the same type) */
905 const struct variable *v;
907 GtkTreeModel *model =
908 gtk_tree_view_get_model (GTK_TREE_VIEW (rd->variable_treeview));
910 gboolean not_empty = gtk_tree_model_get_iter_first (model, &iter);
912 g_return_if_fail (not_empty);
914 gtk_tree_model_get (model, &iter, 0, &v, -1);
916 rd->input_var_is_string = var_is_alpha (v);
918 g_object_set (rd->old_value_chooser, "is-string", rd->input_var_is_string, NULL);
920 gtk_widget_set_sensitive (rd->toggle [BUTTON_NEW_SYSMIS],
923 gtk_widget_set_sensitive (rd->convert_button, var_is_alpha (v));
927 response = psppire_dialog_run (rd->old_and_new_dialog);
928 psppire_acr_set_model (rd->acr, NULL);
931 if ( response == PSPPIRE_RESPONSE_CONTINUE )
933 g_object_unref (rd->value_map);
934 rd->value_map = clone_list_store (local_store);
937 g_object_unref (local_store);
940 psppire_dialog_notify_change (PSPPIRE_DIALOG (rd->dialog));
944 /* Generate a syntax fragment for NV and append it to STR */
946 new_value_append_syntax (GString *str, const struct new_value *nv)
951 g_string_append_printf (str, "%g", nv->v.v);
955 struct string ds = DS_EMPTY_INITIALIZER;
956 syntax_gen_string (&ds, ss_cstr (nv->v.s));
957 g_string_append (str, ds_cstr (&ds));
962 g_string_append (str, "COPY");
965 g_string_append (str, "SYSMIS");
968 /* Shouldn't ever happen */
969 g_warning ("Invalid type in new recode value");
970 g_string_append (str, "???");
977 generate_syntax (const struct recode_dialog *rd)
983 GString *str = g_string_sized_new (100);
985 /* Declare new string variables if applicable */
986 if ( rd->different &&
987 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->string_button)))
991 struct variable *var = NULL;
992 struct nlp *nlp = NULL;
994 g_hash_table_iter_init (&iter, rd->varmap);
995 while (g_hash_table_iter_next (&iter, (void**) &var, (void**) &nlp))
997 g_string_append (str, "\nSTRING ");
998 g_string_append (str, nlp->name);
999 g_string_append_printf (str, " (A%d).",
1001 gtk_spin_button_get_value (GTK_SPIN_BUTTON (rd->width_entry) )
1006 g_string_append (str, "\nRECODE ");
1008 psppire_var_view_append_names (PSPPIRE_VAR_VIEW (rd->variable_treeview), 0, str);
1010 g_string_append (str, "\n\t");
1012 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->convert_button)))
1014 g_string_append (str, "(CONVERT) ");
1017 for (ok = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (rd->value_map),
1020 ok = gtk_tree_model_iter_next (GTK_TREE_MODEL (rd->value_map), &iter))
1022 GValue ov_value = {0};
1023 GValue nv_value = {0};
1024 struct old_value *ov;
1025 struct new_value *nv;
1026 gtk_tree_model_get_value (GTK_TREE_MODEL (rd->value_map), &iter,
1027 COL_VALUE_OLD, &ov_value);
1029 gtk_tree_model_get_value (GTK_TREE_MODEL (rd->value_map), &iter,
1030 COL_VALUE_NEW, &nv_value);
1032 ov = g_value_get_boxed (&ov_value);
1033 nv = g_value_get_boxed (&nv_value);
1035 g_string_append (str, "(");
1037 old_value_append_syntax (str, ov);
1038 g_string_append (str, " = ");
1039 new_value_append_syntax (str, nv);
1041 g_string_append (str, ") ");
1042 g_value_unset (&ov_value);
1043 g_value_unset (&nv_value);
1047 if ( rd->different )
1051 g_string_append (str, "\n\tINTO ");
1053 for (ok = psppire_var_view_get_iter_first (PSPPIRE_VAR_VIEW (rd->variable_treeview), &iter);
1055 ok = psppire_var_view_get_iter_next (PSPPIRE_VAR_VIEW (rd->variable_treeview), &iter))
1057 struct nlp *nlp = NULL;
1058 const struct variable *var = psppire_var_view_get_variable (PSPPIRE_VAR_VIEW (rd->variable_treeview), 0, &iter);
1060 nlp = g_hash_table_lookup (rd->varmap, var);
1062 g_string_append (str, nlp->name);
1063 g_string_append (str, " ");
1067 g_string_append (str, ".");
1069 /* If applicable, set labels for the new variables. */
1070 if ( rd->different )
1072 GHashTableIter iter;
1074 struct variable *var = NULL;
1075 struct nlp *nlp = NULL;
1077 g_hash_table_iter_init (&iter, rd->varmap);
1078 while (g_hash_table_iter_next (&iter, (void**) &var, (void**) &nlp))
1083 ds_init_empty (&sl);
1084 syntax_gen_string (&sl, ss_cstr (nlp->label));
1085 g_string_append_printf (str, "\nVARIABLE LABELS %s %s.",
1086 nlp->name, ds_cstr (&sl));
1093 g_string_append (str, "\nEXECUTE.\n");
1098 g_string_free (str, FALSE);