1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2007 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/>. */
19 #include "transpose-dialog.h"
20 #include "psppire-selector.h"
21 #include "psppire-dialog.h"
23 #include "psppire-data-window.h"
24 #include "dict-display.h"
25 #include <language/syntax-string-source.h>
28 #include "dialog-common.h"
34 #define _(msgid) gettext (msgid)
35 #define N_(msgid) msgid
38 /* FIXME: These shouldn't be here */
39 #include "psppire-var-store.h"
42 static gchar * generate_syntax (PsppireDict *dict, GtkBuilder *xml);
45 refresh (PsppireDialog *dialog, gpointer data)
47 GtkBuilder *xml = data;
48 GtkWidget *dest = get_widget_assert (xml, "variables-treeview");
49 GtkWidget *entry = get_widget_assert (xml, "new-name-entry");
50 GtkTreeModel *dmodel = gtk_tree_view_get_model (GTK_TREE_VIEW (dest));
52 gtk_list_store_clear (GTK_LIST_STORE (dmodel));
53 gtk_entry_set_text (GTK_ENTRY (entry), "");
57 dialog_state_valid (gpointer data)
59 GtkBuilder *xml = data;
61 GtkWidget *tv = get_widget_assert (xml, "variables-treeview");
62 GtkWidget *entry = get_widget_assert (xml, "new-name-entry");
64 GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (tv));
66 gint n_rows = gtk_tree_model_iter_n_children (model, NULL);
71 if ( 0 == strcmp ("", gtk_entry_get_text (GTK_ENTRY (entry))))
79 transpose_dialog (GObject *o, gpointer data)
82 PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (data);
84 GtkBuilder *xml = builder_new ("psppire.ui");
86 PsppireVarStore *vs = NULL;
88 GtkWidget *dialog = get_widget_assert (xml, "transpose-dialog");
89 GtkWidget *source = get_widget_assert (xml, "source-treeview");
90 GtkWidget *dest = get_widget_assert (xml, "variables-treeview");
91 GtkWidget *selector1 = get_widget_assert (xml, "psppire-selector2");
92 GtkWidget *selector2 = get_widget_assert (xml, "psppire-selector3");
93 GtkWidget *new_name_entry = get_widget_assert (xml, "new-name-entry");
95 g_object_get (de->data_editor, "var-store", &vs, NULL);
97 g_object_set (source, "dictionary", vs->dict, NULL);
99 set_dest_model (GTK_TREE_VIEW (dest), vs->dict);
101 psppire_selector_set_subjects (PSPPIRE_SELECTOR (selector1),
103 insert_source_row_into_tree_view,
108 psppire_selector_set_subjects (PSPPIRE_SELECTOR (selector2),
109 source, new_name_entry,
110 insert_source_row_into_entry,
111 is_currently_in_entry,
115 g_signal_connect (dialog, "refresh", G_CALLBACK (refresh), xml);
117 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (de));
119 psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (dialog),
120 dialog_state_valid, xml);
122 response = psppire_dialog_run (PSPPIRE_DIALOG (dialog));
126 case GTK_RESPONSE_OK:
128 gchar *syntax = generate_syntax (vs->dict, xml);
130 struct getl_interface *sss = create_syntax_string_source (syntax);
131 execute_syntax (sss);
136 case PSPPIRE_RESPONSE_PASTE:
138 gchar *syntax = generate_syntax (vs->dict, xml);
139 paste_syntax_in_new_window (syntax);
148 g_object_unref (xml);
153 FLIP /VARIABLES=var_list /NEWNAMES=var_name.
156 generate_syntax (PsppireDict *dict, GtkBuilder *xml)
159 GString *string = g_string_new ("FLIP");
162 GtkWidget *dest = get_widget_assert (xml, "variables-treeview");
163 GtkWidget *entry = get_widget_assert (xml, "new-name-entry");
165 g_string_append (string, " /VARIABLES = ");
167 append_variable_names (string, dict, GTK_TREE_VIEW (dest), 0);
169 text = gtk_entry_get_text (GTK_ENTRY (entry));
172 g_string_append_printf (string, " /NEWNAME = %s", text);
174 g_string_append (string, ".");
176 syntax = string->str;
178 g_string_free (string, FALSE);