2 PSPPIRE --- A Graphical User Interface for PSPP
3 Copyright (C) 2007 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 2 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, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 #include <glade/glade.h>
23 #include <gtksheet/gtksheet.h>
25 #include "dict-display.h"
26 #include "var-display.h"
27 #include <data/variable.h>
28 #include <data/value-labels.h>
29 #include "data-editor.h"
30 #include "psppire-dialog.h"
31 #include "psppire-var-store.h"
33 #include <gtksheet/gtksheet.h>
35 #include <language/syntax-string-source.h>
36 #include "syntax-editor.h"
40 #define _(msgid) gettext (msgid)
41 #define N_(msgid) msgid
44 static struct variable *
45 get_selected_variable (GtkTreeView *treeview)
48 GtkTreeModel *top_model;
54 GtkTreeSelection *selection = gtk_tree_view_get_selection (treeview);
56 if (! gtk_tree_selection_get_selected (selection,
57 &top_model, &top_iter))
62 get_base_model (top_model, &top_iter, &model, &iter);
64 g_assert (PSPPIRE_IS_DICT (model));
66 gtk_tree_model_get (model,
67 &iter, DICT_TVM_COL_VAR, &var, -1);
75 populate_text (GtkTreeView *treeview, gpointer data)
80 GtkTextBuffer *textbuffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW(data));
81 const struct variable *var = get_selected_variable (treeview);
83 gstring = g_string_sized_new (200);
84 text = name_to_string (var, NULL);
85 g_string_assign (gstring, text);
87 g_string_append (gstring, "\n");
90 text = label_to_string (var, NULL);
91 g_string_append_printf (gstring, _("Label: %s\n"), text);
95 const struct fmt_spec *fmt = var_get_print_format (var);
96 char buffer[FMT_STRING_LEN_MAX + 1];
98 fmt_to_string (fmt, buffer);
99 /* No conversion necessary. buffer will always be ascii */
100 g_string_append_printf (gstring, _("Type: %s\n"), buffer);
103 text = missing_values_to_string (var, NULL);
104 g_string_append_printf (gstring, _("Missing Values: %s\n"),
108 text = measure_to_string (var, NULL);
109 g_string_append_printf (gstring, _("Measurement Level: %s\n"),
116 if ( var_has_value_labels (var))
118 struct val_labs_iterator *vli = 0;
120 const struct val_labs *labs = var_get_value_labels (var);
122 g_string_append (gstring, "\n");
123 g_string_append (gstring, _("Value Labels:\n"));
126 for (vl = val_labs_first_sorted (labs, &vli);
128 vl = val_labs_next (labs, &vli))
131 value_to_text (vl->value, *var_get_print_format (var));
133 text = pspp_locale_to_utf8 (vl->label, -1, NULL);
135 g_string_append_printf (gstring, _("%s %s\n"), vstr, text);
143 gtk_text_buffer_set_text (textbuffer, gstring->str, gstring->len);
145 g_string_free (gstring, TRUE);
148 static gchar * generate_syntax (GtkTreeView *treeview);
152 variable_info_dialog (GObject *o, gpointer data)
154 struct data_editor *de = data;
158 GladeXML *xml = XML_NEW ("psppire.glade");
160 GtkWidget *dialog = get_widget_assert (xml, "variable-info-dialog");
161 GtkWidget *treeview = get_widget_assert (xml, "treeview2");
162 GtkWidget *textview = get_widget_assert (xml, "textview1");
164 GtkSheet *var_sheet =
165 GTK_SHEET (get_widget_assert (de->xml, "variable_sheet"));
168 PsppireVarStore *vs = PSPPIRE_VAR_STORE (gtk_sheet_get_model (var_sheet));
170 gtk_window_set_transient_for (GTK_WINDOW (dialog), de->parent.window);
172 attach_dictionary_to_treeview (GTK_TREE_VIEW (treeview),
174 GTK_SELECTION_SINGLE,
178 g_signal_connect (treeview, "cursor-changed", G_CALLBACK (populate_text),
182 gtk_text_view_set_indent (GTK_TEXT_VIEW (textview), -5);
184 response = psppire_dialog_run (PSPPIRE_DIALOG (dialog));
188 case PSPPIRE_RESPONSE_GOTO:
191 GtkNotebook *notebook = GTK_NOTEBOOK
192 (get_widget_assert (de->xml,"notebook"));
194 const struct variable *var =
195 get_selected_variable (GTK_TREE_VIEW (treeview));
198 if (PAGE_VAR_SHEET == gtk_notebook_get_current_page (notebook))
200 GtkSheet *var_sheet =
201 GTK_SHEET (get_widget_assert (de->xml, "variable_sheet"));
203 gtk_sheet_get_active_cell (var_sheet, &row, &col);
204 row = var_get_dict_index (var);
205 gtk_sheet_set_active_cell (var_sheet, row, col);
209 GtkSheet *data_sheet =
210 GTK_SHEET (get_widget_assert (de->xml, "data_sheet"));
212 gtk_sheet_get_active_cell (data_sheet, &row, &col);
213 col = var_get_dict_index (var);
214 gtk_sheet_set_active_cell (data_sheet, row, col);
218 case PSPPIRE_RESPONSE_PASTE:
220 gchar *syntax = generate_syntax (GTK_TREE_VIEW (treeview));
222 struct syntax_editor *se =
223 (struct syntax_editor *) window_create (WINDOW_SYNTAX, NULL);
225 gtk_text_buffer_insert_at_cursor (se->buffer, syntax, -1);
234 g_object_unref (xml);
239 generate_syntax (GtkTreeView *treeview)
241 const struct variable *var = get_selected_variable (treeview);
244 return g_strdup ("");
246 return g_strdup (var_get_name (var));