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 "transpose-dialog.h"
23 #include "psppire-selector.h"
24 #include "psppire-dialog.h"
26 #include "data-editor.h"
27 #include "dict-display.h"
28 #include <language/syntax-string-source.h>
29 #include "syntax-editor.h"
32 #include <glade/glade.h>
36 #define _(msgid) gettext (msgid)
37 #define N_(msgid) msgid
40 /* FIXME: These shouldn't be here */
41 #include <gtksheet/gtksheet.h>
42 #include "psppire-var-store.h"
46 static struct variable *
47 get_selected_variable (GtkTreeModel *treemodel,
54 GtkTreePath *path = gtk_tree_model_get_path (treemodel, iter);
56 gtk_tree_model_get_value (treemodel, iter, 0, &value);
58 gtk_tree_path_free (path);
60 var = psppire_dict_get_variable (dict, g_value_get_int (&value));
62 g_value_unset (&value);
68 /* A (*GtkTreeCellDataFunc) function.
69 This function expects TREEMODEL to hold G_TYPE_INT. The ints it holds
70 are the indices of the variables in the dictionary, which DATA points to.
71 It renders the name of the variable into CELL.
74 cell_var_name (GtkTreeViewColumn *tree_column,
75 GtkCellRenderer *cell,
76 GtkTreeModel *tree_model,
80 PsppireDict *dict = data;
84 var = get_selected_variable (tree_model, iter, dict);
86 name = pspp_locale_to_utf8 (var_get_name (var), -1, NULL);
87 g_object_set (cell, "text", name, NULL);
91 static gchar * generate_syntax (PsppireDict *dict, GladeXML *xml);
94 transpose_dialog (GObject *o, gpointer data)
97 struct data_editor *de = data;
99 GladeXML *xml = glade_xml_new (PKGDATADIR "/psppire.glade",
100 "transpose-dialog", NULL);
102 GtkSheet *var_sheet =
103 GTK_SHEET (get_widget_assert (de->xml, "variable_sheet"));
105 PsppireVarStore *vs = PSPPIRE_VAR_STORE (gtk_sheet_get_model (var_sheet));
107 GtkWidget *dialog = get_widget_assert (xml, "transpose-dialog");
108 GtkWidget *source = get_widget_assert (xml, "source-treeview");
109 GtkWidget *dest = get_widget_assert (xml, "variables-treeview");
110 GtkWidget *selector1 = get_widget_assert (xml, "psppire-selector2");
111 GtkWidget *selector2 = get_widget_assert (xml, "psppire-selector3");
112 GtkWidget *new_name_entry = get_widget_assert (xml, "new-name-entry");
114 attach_dictionary_to_treeview (GTK_TREE_VIEW (source),
116 GTK_SELECTION_MULTIPLE, NULL);
118 GtkTreeViewColumn *col;
119 GtkListStore *dest_list = gtk_list_store_new (1, G_TYPE_INT);
120 GtkCellRenderer *renderer = gtk_cell_renderer_text_new ();
122 gtk_tree_view_set_model (GTK_TREE_VIEW (dest), GTK_TREE_MODEL (dest_list));
124 col = gtk_tree_view_column_new_with_attributes (_("Var"),
130 gtk_tree_view_column_set_cell_data_func (col, renderer,
134 /* FIXME: make this a value in terms of character widths */
135 g_object_set (col, "min-width", 100, NULL);
137 gtk_tree_view_column_set_sizing (col, GTK_TREE_VIEW_COLUMN_FIXED);
139 gtk_tree_view_append_column (GTK_TREE_VIEW(dest), col);
143 psppire_selector_set_subjects (PSPPIRE_SELECTOR (selector1),
145 insert_source_row_into_tree_view,
149 psppire_selector_set_subjects (PSPPIRE_SELECTOR (selector2),
150 source, new_name_entry,
151 insert_source_row_into_entry,
152 is_currently_in_entry);
155 response = psppire_dialog_run (PSPPIRE_DIALOG (dialog));
159 case GTK_RESPONSE_OK:
161 gchar *syntax = generate_syntax (vs->dict, xml);
162 struct getl_interface *sss = create_syntax_string_source (syntax);
163 execute_syntax (sss);
168 case PSPPIRE_RESPONSE_PASTE:
170 gchar *syntax = generate_syntax (vs->dict, xml);
172 struct syntax_editor *se =
173 (struct syntax_editor *) window_create (WINDOW_SYNTAX, NULL);
175 gtk_text_buffer_insert_at_cursor (se->buffer, syntax, -1);
184 g_object_unref (xml);
189 FLIP /VARIABLES=var_list /NEWNAMES=var_name.
192 generate_syntax (PsppireDict *dict, GladeXML *xml)
196 GString *string = g_string_new ("FLIP");
199 GtkWidget *dest = get_widget_assert (xml, "variables-treeview");
200 GtkWidget *entry = get_widget_assert (xml, "new-name-entry");
202 GtkTreeModel *list_store = gtk_tree_view_get_model (GTK_TREE_VIEW (dest));
204 if ( gtk_tree_model_get_iter_first (list_store, &iter) )
206 g_string_append (string, " /VARIABLES =");
210 struct variable *var;
211 GtkTreePath *path = gtk_tree_model_get_path (list_store, &iter);
213 gtk_tree_model_get_value (list_store, &iter, 0, &value);
215 var = psppire_dict_get_variable (dict, g_value_get_int (&value));
216 g_value_unset (&value);
218 g_string_append (string, " ");
219 g_string_append (string, var_get_name (var));
221 gtk_tree_path_free (path);
223 while (gtk_tree_model_iter_next (list_store, &iter));
226 text = gtk_entry_get_text (GTK_ENTRY (entry));
229 g_string_append_printf (string, " /NEWNAME = %s", text);
231 g_string_append (string, ".");
233 syntax = string->str;
235 g_string_free (string, FALSE);