1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2007, 2009, 2010, 2011 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/helper.h>
38 #include <ui/gui/psppire-dialog.h>
39 #include <ui/gui/psppire-var-store.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_MODEL (PSPPIRE_VAR_VIEW (rd->variable_treeview)->list);
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_MODEL (PSPPIRE_VAR_VIEW (rd->variable_treeview)->list);
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);
455 gtk_tree_model_get (model, &iter,
459 nlp = g_hash_table_lookup (rd->varmap, var);
463 gtk_entry_set_text (GTK_ENTRY (rd->new_name_entry), nlp->name ? nlp->name : "");
464 gtk_entry_set_text (GTK_ENTRY (rd->new_label_entry), nlp->label ? nlp->label : "");
468 gtk_entry_set_text (GTK_ENTRY (rd->new_name_entry), "");
469 gtk_entry_set_text (GTK_ENTRY (rd->new_label_entry), "");
474 gtk_widget_set_sensitive (rd->change_button, FALSE);
475 gtk_widget_set_sensitive (rd->new_name_entry, FALSE);
476 gtk_widget_set_sensitive (rd->new_label_entry, FALSE);
478 gtk_entry_set_text (GTK_ENTRY (rd->new_name_entry), "");
479 gtk_entry_set_text (GTK_ENTRY (rd->new_label_entry), "");
483 g_list_foreach (rows, (GFunc) gtk_tree_path_free, NULL);
488 on_string_toggled (GtkToggleButton *b, struct recode_dialog *rd)
491 if (! rd->input_var_is_string )
494 active = gtk_toggle_button_get_active (b);
495 gtk_widget_set_sensitive (rd->convert_button, !active);
500 on_convert_toggled (GtkToggleButton *b, struct recode_dialog *rd)
504 g_return_if_fail (rd->input_var_is_string);
506 active = gtk_toggle_button_get_active (b);
507 gtk_widget_set_sensitive (rd->string_button, !active);
511 on_change_clicked (GObject *obj, gpointer data)
513 struct recode_dialog *rd = data;
514 struct variable *var = NULL;
516 GtkTreeModel *model = GTK_TREE_MODEL (PSPPIRE_VAR_VIEW (rd->variable_treeview)->list);
518 GtkTreeSelection *selection =
519 gtk_tree_view_get_selection (GTK_TREE_VIEW (rd->variable_treeview));
521 GList *rows = gtk_tree_selection_get_selected_rows (selection, &model);
523 const gchar *dest_var_name =
524 gtk_entry_get_text (GTK_ENTRY (rd->new_name_entry));
526 const gchar *dest_var_label =
527 gtk_entry_get_text (GTK_ENTRY (rd->new_label_entry));
529 if ( NULL == rows || rows->next != NULL)
532 gtk_tree_model_get_iter (model, &iter, rows->data);
534 gtk_tree_model_get (model, &iter, 0, &var, -1);
536 g_hash_table_remove (rd->varmap, var);
538 nlp = nlp_create (dest_var_name, dest_var_label);
540 g_hash_table_insert (rd->varmap, var, nlp);
542 gtk_tree_model_row_changed (model, rows->data, &iter);
545 g_list_foreach (rows, (GFunc) gtk_tree_path_free, NULL);
550 /* Callback for the new_value_entry and new_value_togglebutton widgets.
551 It's used to enable/disable the acr. */
553 set_acr (struct recode_dialog *rd)
557 if ( !gtk_toggle_button_get_active
558 (GTK_TOGGLE_BUTTON (rd->toggle[BUTTON_NEW_VALUE])))
560 psppire_acr_set_enabled (rd->acr, TRUE);
564 text = gtk_entry_get_text (GTK_ENTRY (rd->new_value_entry));
566 psppire_acr_set_enabled (rd->acr, !g_str_equal (text, ""));
570 render_new_var_name (GtkTreeViewColumn *tree_column,
571 GtkCellRenderer *cell,
572 GtkTreeModel *tree_model,
576 struct nlp *nlp = NULL;
577 struct recode_dialog *rd = data;
579 struct variable *var = NULL;
581 gtk_tree_model_get (tree_model, iter,
585 nlp = g_hash_table_lookup (rd->varmap, var);
588 g_object_set (cell, "text", nlp->name, NULL);
590 g_object_set (cell, "text", "", NULL);
596 recode_dialog (PsppireDataWindow *de, gboolean diff)
600 struct recode_dialog rd;
602 GtkBuilder *builder = builder_new ("recode.ui");
604 GtkWidget *selector = get_widget_assert (builder, "psppire-selector1");
606 GtkWidget *oldandnew = get_widget_assert (builder, "button1");
609 GtkWidget *output_variable_box = get_widget_assert (builder,"frame4");
611 PsppireVarStore *vs = NULL;
612 g_object_get (de->data_editor, "var-store", &vs, NULL);
614 rd.change_button = get_widget_assert (builder, "change-button");
616 rd.dialog = get_widget_assert (builder, "recode-dialog");
617 rd.dict_treeview = get_widget_assert (builder, "treeview1");
618 rd.variable_treeview = get_widget_assert (builder, "treeview2");
619 rd.new_name_entry = get_widget_assert (builder, "dest-name-entry");
620 rd.new_label_entry = get_widget_assert (builder, "dest-label-entry");
622 g_object_get (vs, "dictionary", &rd.dict, NULL);
624 rd.value_map = gtk_list_store_new (2,
625 old_value_get_type (),
626 new_value_get_type ()
629 g_object_set (output_variable_box, "visible", diff, NULL);
632 gtk_window_set_title (GTK_WINDOW (rd.dialog),
633 _("Recode into Different Variables"));
635 gtk_window_set_title (GTK_WINDOW (rd.dialog),
636 _("Recode into Same Variables"));
640 gtk_window_set_transient_for (GTK_WINDOW (rd.dialog), GTK_WINDOW (de));
642 g_object_set (rd.dict_treeview, "model", rd.dict, NULL);
646 GtkTreeSelection *sel;
648 GtkCellRenderer *renderer = gtk_cell_renderer_text_new ();
650 GtkTreeViewColumn *col = gtk_tree_view_column_new_with_attributes (_("New"),
655 gtk_tree_view_column_set_cell_data_func (col, renderer,
660 gtk_tree_view_append_column (GTK_TREE_VIEW (rd.variable_treeview), col);
663 col = gtk_tree_view_get_column (GTK_TREE_VIEW (rd.variable_treeview), 0);
665 g_object_set (col, "title", _("Old"), NULL);
667 g_object_set (rd.variable_treeview, "headers-visible", TRUE, NULL);
669 rd.varmap = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, nlp_destroy);
671 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (rd.variable_treeview));
673 g_signal_connect (sel, "changed",
674 G_CALLBACK (on_selection_change), &rd);
676 g_signal_connect (rd.change_button, "clicked",
677 G_CALLBACK (on_change_clicked), &rd);
681 psppire_selector_set_allow (PSPPIRE_SELECTOR (selector), homogeneous_types);
683 /* Set up the Old & New Values subdialog */
685 rd.string_button = get_widget_assert (builder, "checkbutton1");
686 rd.width_entry = get_widget_assert (builder, "spinbutton1");
688 rd.convert_button = get_widget_assert (builder, "checkbutton2");
690 rd.old_value_chooser = get_widget_assert (builder, "val-chooser");
692 rd.new_value_entry = get_widget_assert (builder, "entry1");
695 rd.toggle[BUTTON_NEW_VALUE] = get_widget_assert (builder, "radiobutton1");
696 rd.toggle[BUTTON_NEW_SYSMIS] = get_widget_assert (builder, "radiobutton2");
697 rd.toggle[BUTTON_NEW_COPY] = get_widget_assert (builder, "radiobutton3");
699 rd.new_copy_label = get_widget_assert (builder, "label3");
700 rd.strings_box = get_widget_assert (builder, "table3");
702 rd.old_and_new_dialog =
703 PSPPIRE_DIALOG (get_widget_assert (builder, "old-new-values-dialog"));
705 gtk_window_set_transient_for (GTK_WINDOW (rd.old_and_new_dialog),
708 rd.acr = PSPPIRE_ACR (get_widget_assert (builder, "psppire-acr1"));
710 g_signal_connect_swapped (rd.toggle[BUTTON_NEW_VALUE], "toggled",
711 G_CALLBACK (set_acr), &rd);
713 g_signal_connect_swapped (rd.new_value_entry, "changed",
714 G_CALLBACK (set_acr), &rd);
717 GtkTreeSelection *sel;
718 /* Remove the ACR's default column. We don't like it */
719 GtkTreeViewColumn *column = gtk_tree_view_get_column (rd.acr->tv, 0);
720 gtk_tree_view_remove_column (rd.acr->tv, column);
724 gtk_tree_view_column_new_with_attributes (_("Old"),
725 gtk_cell_renderer_text_new (),
729 gtk_tree_view_append_column (rd.acr->tv, column);
732 gtk_tree_view_column_new_with_attributes (_("New"),
733 gtk_cell_renderer_text_new (),
737 gtk_tree_view_append_column (rd.acr->tv, column);
738 g_object_set (rd.acr->tv, "headers-visible", TRUE, NULL);
741 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (rd.acr->tv));
742 g_signal_connect (sel, "changed",
743 G_CALLBACK (on_acr_selection_change), &rd);
747 g_signal_connect_swapped (oldandnew, "clicked",
748 G_CALLBACK (run_old_and_new_dialog), &rd);
751 g_signal_connect (rd.toggle[BUTTON_NEW_VALUE], "toggled",
752 G_CALLBACK (toggle_sensitivity), rd.new_value_entry);
754 g_signal_connect (rd.string_button, "toggled",
755 G_CALLBACK (toggle_sensitivity), rd.width_entry);
757 g_signal_connect (rd.string_button, "toggled",
758 G_CALLBACK (on_string_toggled), &rd);
760 g_signal_connect (rd.convert_button, "toggled",
761 G_CALLBACK (on_convert_toggled), &rd);
763 g_signal_connect_swapped (rd.old_and_new_dialog, "show",
764 G_CALLBACK (on_old_new_show), &rd);
767 g_signal_connect (rd.dialog, "refresh", G_CALLBACK (refresh), &rd);
770 psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (rd.dialog),
771 dialog_state_valid, &rd);
773 response = psppire_dialog_run (PSPPIRE_DIALOG (rd.dialog));
777 case GTK_RESPONSE_OK:
778 g_free (execute_syntax_string (de, generate_syntax (&rd)));
780 case PSPPIRE_RESPONSE_PASTE:
781 g_free (paste_syntax_to_window (generate_syntax (&rd)));
788 g_hash_table_destroy (rd.varmap);
790 gtk_list_store_clear (GTK_LIST_STORE (rd.value_map));
791 g_object_unref (rd.value_map);
793 g_object_unref (builder);
796 /* Initialise VAL to reflect the current status of RD */
798 set_old_value (GValue *val, const struct recode_dialog *rd)
800 PsppireValChooser *vc = PSPPIRE_VAL_CHOOSER (rd->old_value_chooser);
804 psppire_val_chooser_get_status (vc, &ov);
806 g_value_init (val, old_value_get_type ());
807 g_value_set_boxed (val, &ov);
813 /* Initialse VAL to reflect the current status of RD */
815 set_new_value (GValue *val, const struct recode_dialog *rd)
817 const gchar *text = NULL;
820 if ( gtk_toggle_button_get_active
821 (GTK_TOGGLE_BUTTON (rd->toggle [BUTTON_NEW_VALUE])))
823 text = gtk_entry_get_text (GTK_ENTRY (rd->new_value_entry));
825 nv.type = NV_NUMERIC;
827 (! rd->different && rd->input_var_is_string) ||
829 gtk_toggle_button_get_active
830 (GTK_TOGGLE_BUTTON (rd->string_button)))
836 if ( nv.type == NV_STRING )
837 nv.v.s = g_strdup (text);
839 nv.v.v = g_strtod (text, 0);
841 else if ( gtk_toggle_button_get_active
842 (GTK_TOGGLE_BUTTON (rd->toggle [BUTTON_NEW_COPY])))
847 else if ( gtk_toggle_button_get_active
848 (GTK_TOGGLE_BUTTON (rd->toggle [BUTTON_NEW_SYSMIS])))
855 g_value_init (val, new_value_get_type ());
856 g_value_set_boxed (val, &nv);
862 /* A function to set a value in a column in the ACR */
864 set_value (gint col, GValue *val, gpointer data)
866 struct recode_dialog *rd = data;
871 set_old_value (val, rd);
874 set_new_value (val, rd);
884 run_old_and_new_dialog (struct recode_dialog *rd)
887 GtkListStore *local_store = clone_list_store (rd->value_map);
889 psppire_acr_set_model (rd->acr, local_store);
890 psppire_acr_set_get_value_func (rd->acr, set_value, rd);
892 gtk_window_set_title (GTK_WINDOW (rd->old_and_new_dialog),
894 ? _("Recode into Different Variables: Old and New Values ")
895 : _("Recode into Same Variables: Old and New Values")
900 /* Find the type of the first variable (it's invariant that
901 all variables are of the same type) */
902 const struct variable *v;
904 GtkTreeModel *model =
905 gtk_tree_view_get_model (GTK_TREE_VIEW (rd->variable_treeview));
907 gboolean not_empty = gtk_tree_model_get_iter_first (model, &iter);
909 g_return_if_fail (not_empty);
911 gtk_tree_model_get (model, &iter, 0, &v, -1);
913 rd->input_var_is_string = var_is_alpha (v);
915 g_object_set (rd->old_value_chooser, "is-string", rd->input_var_is_string, NULL);
917 gtk_widget_set_sensitive (rd->toggle [BUTTON_NEW_SYSMIS],
920 gtk_widget_set_sensitive (rd->convert_button, var_is_alpha (v));
924 response = psppire_dialog_run (rd->old_and_new_dialog);
925 psppire_acr_set_model (rd->acr, NULL);
928 if ( response == PSPPIRE_RESPONSE_CONTINUE )
930 g_object_unref (rd->value_map);
931 rd->value_map = clone_list_store (local_store);
934 g_object_unref (local_store);
937 psppire_dialog_notify_change (PSPPIRE_DIALOG (rd->dialog));
941 /* Generate a syntax fragment for NV and append it to STR */
943 new_value_append_syntax (GString *str, const struct new_value *nv)
948 g_string_append_printf (str, "%g", nv->v.v);
952 struct string ds = DS_EMPTY_INITIALIZER;
953 syntax_gen_string (&ds, ss_cstr (nv->v.s));
954 g_string_append (str, ds_cstr (&ds));
959 g_string_append (str, "COPY");
962 g_string_append (str, "SYSMIS");
965 /* Shouldn't ever happen */
966 g_warning ("Invalid type in new recode value");
967 g_string_append (str, "???");
974 generate_syntax (const struct recode_dialog *rd)
980 GString *str = g_string_sized_new (100);
982 /* Declare new string variables if applicable */
983 if ( rd->different &&
984 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->string_button)))
988 struct variable *var = NULL;
989 struct nlp *nlp = NULL;
991 g_hash_table_iter_init (&iter, rd->varmap);
992 while (g_hash_table_iter_next (&iter, (void**) &var, (void**) &nlp))
994 g_string_append (str, "\nSTRING ");
995 g_string_append (str, nlp->name);
996 g_string_append_printf (str, " (A%d).",
998 gtk_spin_button_get_value (GTK_SPIN_BUTTON (rd->width_entry) )
1003 g_string_append (str, "\nRECODE ");
1005 psppire_var_view_append_names (PSPPIRE_VAR_VIEW (rd->variable_treeview), 0, str);
1007 g_string_append (str, "\n\t");
1009 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->convert_button)))
1011 g_string_append (str, "(CONVERT) ");
1014 for (ok = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (rd->value_map),
1017 ok = gtk_tree_model_iter_next (GTK_TREE_MODEL (rd->value_map), &iter))
1019 GValue ov_value = {0};
1020 GValue nv_value = {0};
1021 struct old_value *ov;
1022 struct new_value *nv;
1023 gtk_tree_model_get_value (GTK_TREE_MODEL (rd->value_map), &iter,
1024 COL_VALUE_OLD, &ov_value);
1026 gtk_tree_model_get_value (GTK_TREE_MODEL (rd->value_map), &iter,
1027 COL_VALUE_NEW, &nv_value);
1029 ov = g_value_get_boxed (&ov_value);
1030 nv = g_value_get_boxed (&nv_value);
1032 g_string_append (str, "(");
1034 old_value_append_syntax (str, ov);
1035 g_string_append (str, " = ");
1036 new_value_append_syntax (str, nv);
1038 g_string_append (str, ") ");
1039 g_value_unset (&ov_value);
1040 g_value_unset (&nv_value);
1044 if ( rd->different )
1048 g_string_append (str, "\n\tINTO ");
1050 for (ok = psppire_var_view_get_iter_first (PSPPIRE_VAR_VIEW (rd->variable_treeview), &iter);
1052 ok = psppire_var_view_get_iter_next (PSPPIRE_VAR_VIEW (rd->variable_treeview), &iter))
1054 struct nlp *nlp = NULL;
1055 const struct variable *var = psppire_var_view_get_variable (PSPPIRE_VAR_VIEW (rd->variable_treeview), 0, &iter);
1057 nlp = g_hash_table_lookup (rd->varmap, var);
1059 g_string_append (str, nlp->name);
1060 g_string_append (str, " ");
1064 g_string_append (str, ".");
1066 /* If applicable, set labels for the new variables. */
1067 if ( rd->different )
1069 GHashTableIter iter;
1071 struct variable *var = NULL;
1072 struct nlp *nlp = NULL;
1074 g_hash_table_iter_init (&iter, rd->varmap);
1075 while (g_hash_table_iter_next (&iter, (void**) &var, (void**) &nlp))
1078 g_string_append_printf (str, "\nVARIABLE LABELS %s %s.",
1079 nlp->name, nlp->label);
1083 g_string_append (str, "\nEXECUTE.\n");
1088 g_string_free (str, FALSE);