1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2007, 2009, 2010, 2011, 2012, 2014, 2016 Free Software Foundation
3
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.
8
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.
13
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/>. */
16
17
18 #include <config.h>
19
20 #include "psppire-var-view.h"
21
22 #include "psppire-dialog-action-recode-same.h"
23 #include "builder-wrapper.h"
24 #include <ui/gui/dialog-common.h>
25
26 #include "psppire-acr.h"
27
28 #include "psppire-selector.h"
29 #include "psppire-val-chooser.h"
30
31 #include "helper.h"
32 #include <ui/syntax-gen.h>
33
34 #include "gettext.h"
35 #define _(msgid) gettext (msgid)
36 #define N_(msgid) msgid
37
38 static gboolean
difx_variable_treeview_is_populated(PsppireDialogActionRecode * rd)39 difx_variable_treeview_is_populated (PsppireDialogActionRecode *rd)
40 {
41 GtkTreeIter not_used;
42
43 GtkTreeModel *vars =
44 gtk_tree_view_get_model (GTK_TREE_VIEW (rd->variable_treeview));
45
46 if (!gtk_tree_model_get_iter_first (vars, ¬_used))
47 return FALSE;
48
49 return TRUE;
50 }
51
52
53 /* Dialog is valid iff at least one variable has been selected,
54 AND the list of mappings is not empty.
55 */
56 static gboolean
dialog_state_valid(gpointer data)57 dialog_state_valid (gpointer data)
58 {
59 PsppireDialogActionRecode *rd = data;
60 GtkTreeIter not_used;
61
62 if (! rd->value_map)
63 return FALSE;
64
65 if (! gtk_tree_model_get_iter_first (GTK_TREE_MODEL (rd->value_map),
66 ¬_used))
67 return FALSE;
68
69 return difx_variable_treeview_is_populated (rd);
70 }
71
72
73
74
75 static void
76 psppire_dialog_action_recode_same_class_init (PsppireDialogActionRecodeSameClass *class);
77
78 G_DEFINE_TYPE (PsppireDialogActionRecodeSame, psppire_dialog_action_recode_same, PSPPIRE_TYPE_DIALOG_ACTION_RECODE);
79
80 static void
refresh(PsppireDialogAction * rd)81 refresh (PsppireDialogAction *rd)
82 {
83 psppire_dialog_action_recode_refresh (rd);
84 }
85
86 static void
on_old_new_show(PsppireDialogActionRecode * rd)87 on_old_new_show (PsppireDialogActionRecode *rd)
88 {
89 gtk_toggle_button_set_active
90 (GTK_TOGGLE_BUTTON (rd->toggle[BUTTON_NEW_VALUE]), TRUE);
91
92 g_signal_emit_by_name (rd->toggle[BUTTON_NEW_VALUE], "toggled");
93
94 gtk_widget_hide (rd->toggle[BUTTON_NEW_COPY]);
95 gtk_widget_hide (rd->new_copy_label);
96 gtk_widget_hide (rd->strings_box);
97 }
98
99 static GtkBuilder *
psppire_dialog_action_recode_same_activate(PsppireDialogAction * a,GVariant * param)100 psppire_dialog_action_recode_same_activate (PsppireDialogAction *a, GVariant *param)
101 {
102 PsppireDialogActionRecode *act = PSPPIRE_DIALOG_ACTION_RECODE (a);
103 PsppireDialogAction *pda = PSPPIRE_DIALOG_ACTION (a);
104
105 GtkBuilder *xml = psppire_dialog_action_recode_pre_activate (act, NULL);
106
107 gtk_window_set_title (GTK_WINDOW (pda->dialog),
108 _("Recode into Same Variables"));
109
110 g_signal_connect_swapped (act->old_and_new_dialog, "show",
111 G_CALLBACK (on_old_new_show), act);
112
113 gtk_window_set_title (GTK_WINDOW (act->old_and_new_dialog),
114 _("Recode into Same Variables: Old and New Values"));
115
116 gtk_widget_hide (act->output_variable_box);
117
118 psppire_dialog_action_set_refresh (pda, refresh);
119
120 psppire_dialog_action_set_valid_predicate (pda,
121 dialog_state_valid);
122
123 return xml;
124 }
125
126 static void
null_op(const PsppireDialogActionRecode * rd,struct string * dds)127 null_op (const PsppireDialogActionRecode *rd, struct string *dds)
128 {
129 }
130
131 static char *
same_generate_syntax(const PsppireDialogAction * act)132 same_generate_syntax (const PsppireDialogAction *act)
133 {
134 return psppire_dialog_action_recode_generate_syntax (act, null_op, null_op, null_op);
135 }
136
137 static gboolean
target_is_string(const PsppireDialogActionRecode * rd)138 target_is_string (const PsppireDialogActionRecode *rd)
139 {
140 return rd->input_var_is_string;
141 }
142
143
144 static void
psppire_dialog_action_recode_same_class_init(PsppireDialogActionRecodeSameClass * class)145 psppire_dialog_action_recode_same_class_init (PsppireDialogActionRecodeSameClass *class)
146 {
147 PSPPIRE_DIALOG_ACTION_CLASS (class)->initial_activate = psppire_dialog_action_recode_same_activate;
148
149 PSPPIRE_DIALOG_ACTION_CLASS (class)->generate_syntax = same_generate_syntax;
150 PSPPIRE_DIALOG_ACTION_RECODE_CLASS (class)->target_is_string = target_is_string;
151 }
152
153
154 static void
psppire_dialog_action_recode_same_init(PsppireDialogActionRecodeSame * act)155 psppire_dialog_action_recode_same_init (PsppireDialogActionRecodeSame *act)
156 {
157 }
158
159