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 "psppire-dialog-action-var-info.h"
23 #include <data/variable.h>
24 #include <data/format.h>
25 #include <data/value-labels.h>
26 #include <libpspp/i18n.h>
28 #include "var-display.h"
30 #include "psppire-var-view.h"
31 #include "psppire-dictview.h"
33 #include "psppire-dialog.h"
34 #include "builder-wrapper.h"
35 #include "psppire-data-window.h"
37 static void psppire_dialog_action_var_info_init (PsppireDialogActionVarInfo *act);
38 static void psppire_dialog_action_var_info_class_init (PsppireDialogActionVarInfoClass *class);
40 G_DEFINE_TYPE (PsppireDialogActionVarInfo, psppire_dialog_action_var_info, PSPPIRE_TYPE_DIALOG_ACTION);
43 #define _(msgid) gettext (msgid)
44 #define N_(msgid) msgid
47 static const gchar none[] = N_("None");
51 label_to_string (const struct variable *var)
53 const char *label = var_get_label (var);
55 if (NULL == label) return g_strdup (none);
62 treeview_item_selected (gpointer data)
64 PsppireDialogAction *pda = data;
65 GtkTreeView *tv = GTK_TREE_VIEW (pda->source);
66 GtkTreeModel *model = gtk_tree_view_get_model (tv);
68 gint n_rows = gtk_tree_model_iter_n_children (model, NULL);
77 generate_syntax (PsppireDialogAction *act)
80 const struct variable *var =
81 psppire_dict_view_get_selected_variable (PSPPIRE_DICT_VIEW (act->source));
86 return g_strdup (var_get_name (var));
92 populate_text (PsppireDictView *treeview, gpointer data)
98 GtkTextBuffer *textbuffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (data));
99 const struct variable *var =
100 psppire_dict_view_get_selected_variable (treeview);
105 g_object_get (treeview, "model", &dict,
108 gstring = g_string_sized_new (200);
109 g_string_assign (gstring, var_get_name (var));
110 g_string_append (gstring, "\n");
113 g_string_append_printf (gstring, _("Label: %s\n"), label_to_string (var));
115 const struct fmt_spec *fmt = var_get_print_format (var);
116 char buffer[FMT_STRING_LEN_MAX + 1];
118 fmt_to_string (fmt, buffer);
119 /* No conversion necessary. buffer will always be ascii */
120 g_string_append_printf (gstring, _("Type: %s\n"), buffer);
123 text = missing_values_to_string (dict, var, NULL);
124 g_string_append_printf (gstring, _("Missing Values: %s\n"),
128 g_string_append_printf (gstring, _("Measurement Level: %s\n"),
129 measure_to_string (var_get_measure (var)));
133 if ( var_has_value_labels (var))
135 const struct val_labs *vls = var_get_value_labels (var);
136 const struct val_lab **labels;
140 g_string_append (gstring, "\n");
141 g_string_append (gstring, _("Value Labels:\n"));
143 labels = val_labs_sorted (vls);
144 n_labels = val_labs_count (vls);
145 for (i = 0; i < n_labels; i++)
147 const struct val_lab *vl = labels[i];
148 gchar *const vstr = value_to_text (vl->value, var);
150 g_string_append_printf (gstring, _("%s %s\n"),
151 vstr, val_lab_get_escaped_label (vl));
158 gtk_text_buffer_set_text (textbuffer, gstring->str, gstring->len);
160 g_string_free (gstring, TRUE);
165 jump_to (PsppireDialog *d, gint response, gpointer data)
167 PsppireDataWindow *dw;
168 PsppireDialogAction *pda = PSPPIRE_DIALOG_ACTION (data);
169 const struct variable *var;
171 if (response != PSPPIRE_RESPONSE_GOTO)
174 var = psppire_dict_view_get_selected_variable (PSPPIRE_DICT_VIEW (pda->source));
179 g_object_get (pda, "top-level", &dw, NULL);
181 g_object_set (dw->data_editor,
182 "current-variable", var_get_dict_index (var),
187 psppire_dialog_action_var_info_activate (GtkAction *a)
189 PsppireDialogAction *pda = PSPPIRE_DIALOG_ACTION (a);
191 GtkBuilder *xml = builder_new ("variable-info.ui");
192 GtkWidget *textview = get_widget_assert (xml, "textview1");
194 pda->dialog = get_widget_assert (xml, "variable-info-dialog");
195 pda->source = get_widget_assert (xml, "treeview2");
197 g_object_set (pda->source,
198 "selection-mode", GTK_SELECTION_SINGLE,
201 g_signal_connect (pda->source, "cursor-changed", G_CALLBACK (populate_text),
205 g_signal_connect (pda->dialog, "response", G_CALLBACK (jump_to),
208 psppire_dialog_action_set_valid_predicate (pda,
209 treeview_item_selected);
211 g_object_unref (xml);
213 if (PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_var_info_parent_class)->activate)
214 PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_var_info_parent_class)->activate (pda);
218 psppire_dialog_action_var_info_class_init (PsppireDialogActionVarInfoClass *class)
220 GtkActionClass *action_class = GTK_ACTION_CLASS (class);
222 action_class->activate = psppire_dialog_action_var_info_activate;
223 PSPPIRE_DIALOG_ACTION_CLASS (class)->generate_syntax = generate_syntax;
228 psppire_dialog_action_var_info_init (PsppireDialogActionVarInfo *act)