1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2007, 2009, 2010, 2011, 2012 Free Software Foundation
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 #include "ui/gui/psppire-dialog-action-var-info.h"
25 #include "data/format.h"
26 #include "data/value-labels.h"
27 #include "data/variable.h"
28 #include "libpspp/i18n.h"
29 #include "ui/gui/builder-wrapper.h"
30 #include "ui/gui/helper.h"
31 #include "ui/gui/psppire-data-window.h"
32 #include "ui/gui/psppire-dialog.h"
33 #include "ui/gui/psppire-dictview.h"
34 #include "ui/gui/var-display.h"
36 static void psppire_dialog_action_var_info_init (PsppireDialogActionVarInfo *act);
37 static void psppire_dialog_action_var_info_class_init (PsppireDialogActionVarInfoClass *class);
39 G_DEFINE_TYPE (PsppireDialogActionVarInfo, psppire_dialog_action_var_info, PSPPIRE_TYPE_DIALOG_ACTION);
42 #define _(msgid) gettext (msgid)
43 #define N_(msgid) msgid
46 static const gchar none[] = N_("None");
50 label_to_string (const struct variable *var)
52 const char *label = var_get_label (var);
54 if (NULL == label) return g_strdup (none);
61 treeview_item_selected (gpointer data)
63 PsppireDialogAction *pda = data;
64 GtkTreeView *tv = GTK_TREE_VIEW (pda->source);
65 GtkTreeModel *model = gtk_tree_view_get_model (tv);
67 gint n_rows = gtk_tree_model_iter_n_children (model, NULL);
76 generate_syntax (PsppireDialogAction *act)
79 const struct variable *var =
80 psppire_dict_view_get_selected_variable (PSPPIRE_DICT_VIEW (act->source));
85 return g_strdup (var_get_name (var));
91 populate_text (PsppireDictView *treeview, gpointer data)
97 GtkTextBuffer *textbuffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (data));
98 const struct variable *var =
99 psppire_dict_view_get_selected_variable (treeview);
104 g_object_get (treeview, "model", &dict,
107 gstring = g_string_sized_new (200);
108 g_string_assign (gstring, var_get_name (var));
109 g_string_append (gstring, "\n");
112 g_string_append_printf (gstring, _("Label: %s\n"), label_to_string (var));
114 const struct fmt_spec *fmt = var_get_print_format (var);
115 char buffer[FMT_STRING_LEN_MAX + 1];
117 fmt_to_string (fmt, buffer);
118 /* No conversion necessary. buffer will always be ascii */
119 g_string_append_printf (gstring, _("Type: %s\n"), buffer);
122 text = missing_values_to_string (var, NULL);
123 g_string_append_printf (gstring, _("Missing Values: %s\n"),
127 g_string_append_printf (gstring, _("Measurement Level: %s\n"),
128 measure_to_string (var_get_measure (var)));
132 if ( var_has_value_labels (var))
134 const struct val_labs *vls = var_get_value_labels (var);
135 const struct val_lab **labels;
139 g_string_append (gstring, "\n");
140 g_string_append (gstring, _("Value Labels:\n"));
142 labels = val_labs_sorted (vls);
143 n_labels = val_labs_count (vls);
144 for (i = 0; i < n_labels; i++)
146 const struct val_lab *vl = labels[i];
147 gchar *const vstr = value_to_text (vl->value, var);
149 g_string_append_printf (gstring, _("%s %s\n"),
150 vstr, val_lab_get_escaped_label (vl));
157 gtk_text_buffer_set_text (textbuffer, gstring->str, gstring->len);
159 g_string_free (gstring, TRUE);
164 jump_to (PsppireDialog *d, gint response, gpointer data)
166 PsppireDataWindow *dw;
167 PsppireDialogAction *pda = PSPPIRE_DIALOG_ACTION (data);
168 const struct variable *var;
170 if (response != PSPPIRE_RESPONSE_GOTO)
173 var = psppire_dict_view_get_selected_variable (PSPPIRE_DICT_VIEW (pda->source));
178 g_object_get (pda, "top-level", &dw, NULL);
180 psppire_data_editor_goto_variable (dw->data_editor,
181 var_get_dict_index (var));
185 psppire_dialog_action_var_info_activate (GtkAction *a)
187 PsppireDialogAction *pda = PSPPIRE_DIALOG_ACTION (a);
189 GtkBuilder *xml = builder_new ("variable-info.ui");
190 GtkWidget *textview = get_widget_assert (xml, "textview1");
192 pda->dialog = get_widget_assert (xml, "variable-info-dialog");
193 pda->source = get_widget_assert (xml, "treeview2");
195 g_object_set (pda->source,
196 "selection-mode", GTK_SELECTION_SINGLE,
199 g_signal_connect (pda->source, "cursor-changed", G_CALLBACK (populate_text),
203 g_signal_connect (pda->dialog, "response", G_CALLBACK (jump_to),
206 psppire_dialog_action_set_valid_predicate (pda,
207 treeview_item_selected);
209 g_object_unref (xml);
211 if (PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_var_info_parent_class)->activate)
212 PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_var_info_parent_class)->activate (pda);
216 psppire_dialog_action_var_info_class_init (PsppireDialogActionVarInfoClass *class)
218 GtkActionClass *action_class = GTK_ACTION_CLASS (class);
220 action_class->activate = psppire_dialog_action_var_info_activate;
221 PSPPIRE_DIALOG_ACTION_CLASS (class)->generate_syntax = generate_syntax;
226 psppire_dialog_action_var_info_init (PsppireDialogActionVarInfo *act)