1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2007, 2009 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/>. */
20 #include "var-display.h"
21 #include <data/variable.h>
22 #include <data/format.h>
23 #include <data/value-labels.h>
24 #include "psppire-data-window.h"
25 #include "psppire-dialog.h"
26 #include "psppire-var-store.h"
27 #include "psppire-dictview.h"
30 #include <language/syntax-string-source.h>
31 #include <libpspp/i18n.h>
36 #define _(msgid) gettext (msgid)
37 #define N_(msgid) msgid
40 static const gchar none[] = N_("None");
44 name_to_string (const struct variable *var, PsppireDict *dict)
46 const char *name = var_get_name (var);
49 return recode_string (UTF8, psppire_dict_encoding (dict),
55 label_to_string (const struct variable *var, PsppireDict *dict)
57 const char *label = var_get_label (var);
59 if (! label) return g_strdup (none);
61 return recode_string (UTF8, psppire_dict_encoding (dict),
67 populate_text (PsppireDictView *treeview, gpointer data)
73 GtkTextBuffer *textbuffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (data));
74 const struct variable *var =
75 psppire_dict_view_get_selected_variable (treeview);
80 g_object_get (treeview,
84 gstring = g_string_sized_new (200);
85 text = name_to_string (var, dict);
86 g_string_assign (gstring, text);
88 g_string_append (gstring, "\n");
91 text = label_to_string (var, dict);
92 g_string_append_printf (gstring, _("Label: %s\n"), text);
96 const struct fmt_spec *fmt = var_get_print_format (var);
97 char buffer[FMT_STRING_LEN_MAX + 1];
99 fmt_to_string (fmt, buffer);
100 /* No conversion necessary. buffer will always be ascii */
101 g_string_append_printf (gstring, _("Type: %s\n"), buffer);
104 text = missing_values_to_string (dict, var, NULL);
105 g_string_append_printf (gstring, _("Missing Values: %s\n"),
109 text = measure_to_string (var, NULL);
110 g_string_append_printf (gstring, _("Measurement Level: %s\n"),
117 if ( var_has_value_labels (var))
119 const struct val_labs *vls = var_get_value_labels (var);
120 const struct val_lab **labels;
124 g_string_append (gstring, "\n");
125 g_string_append (gstring, _("Value Labels:\n"));
127 labels = val_labs_sorted (vls);
128 n_labels = val_labs_count (vls);
129 for (i = 0; i < n_labels; i++)
131 const struct val_lab *vl = labels[i];
133 value_to_text (vl->value, *var_get_print_format (var));
135 text = recode_string (UTF8, psppire_dict_encoding (dict),
136 val_lab_get_label (vl), -1);
138 g_string_append_printf (gstring, _("%s %s\n"), vstr, text);
146 gtk_text_buffer_set_text (textbuffer, gstring->str, gstring->len);
148 g_string_free (gstring, TRUE);
152 treeview_item_selected (gpointer data)
154 GtkTreeView *tv = GTK_TREE_VIEW (data);
155 GtkTreeModel *model = gtk_tree_view_get_model (tv);
157 gint n_rows = gtk_tree_model_iter_n_children (model, NULL);
166 static gchar * generate_syntax (PsppireDictView *treeview);
170 variable_info_dialog (GObject *o, gpointer data)
172 PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (data);
176 GtkBuilder *xml = builder_new ("variable-info-dialog.ui");
178 GtkWidget *dialog = get_widget_assert (xml, "variable-info-dialog");
179 GtkWidget *treeview = get_widget_assert (xml, "treeview2");
180 GtkWidget *textview = get_widget_assert (xml, "textview1");
182 PsppireVarStore *vs = NULL;
184 g_object_get (de->data_editor, "var-store", &vs, NULL);
186 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (de));
188 g_object_set (treeview,
189 "dictionary", vs->dict,
190 "selection-mode", GTK_SELECTION_SINGLE,
193 g_signal_connect (treeview, "cursor-changed", G_CALLBACK (populate_text),
197 gtk_text_view_set_indent (GTK_TEXT_VIEW (textview), -5);
199 psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (dialog),
200 treeview_item_selected, treeview);
202 response = psppire_dialog_run (PSPPIRE_DIALOG (dialog));
206 case PSPPIRE_RESPONSE_GOTO:
208 const struct variable *var =
209 psppire_dict_view_get_selected_variable (PSPPIRE_DICT_VIEW (treeview));
214 g_object_set (de->data_editor,
215 "current-variable", var_get_dict_index (var),
220 case PSPPIRE_RESPONSE_PASTE:
222 gchar *syntax = generate_syntax (PSPPIRE_DICT_VIEW (treeview));
223 paste_syntax_in_new_window (syntax);
233 g_object_unref (xml);
237 generate_syntax (PsppireDictView *treeview)
239 const struct variable *var =
240 psppire_dict_view_get_selected_variable (treeview);
243 return g_strdup ("");
245 return g_strdup (var_get_name (var));