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 "data-editor.h"
24 #include "dict-display.h"
25 #include <language/syntax-string-source.h>
26 #include "syntax-editor.h"
28 #include "dialog-common.h"
31 #include <glade/glade.h>
35 #define _(msgid) gettext (msgid)
36 #define N_(msgid) msgid
39 /* FIXME: These shouldn't be here */
40 #include "psppire-var-store.h"
43 static gchar * generate_syntax (PsppireDict *dict, GladeXML *xml);
46 refresh (PsppireDialog *dialog, gpointer data)
49 GtkWidget *dest = get_widget_assert (xml, "variables-treeview");
50 GtkWidget *entry = get_widget_assert (xml, "new-name-entry");
51 GtkTreeModel *dmodel = gtk_tree_view_get_model (GTK_TREE_VIEW (dest));
53 gtk_list_store_clear (GTK_LIST_STORE (dmodel));
54 gtk_entry_set_text (GTK_ENTRY (entry), "");
58 dialog_state_valid (gpointer data)
62 GtkWidget *tv = get_widget_assert (xml, "variables-treeview");
63 GtkWidget *entry = get_widget_assert (xml, "new-name-entry");
65 GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (tv));
67 gint n_rows = gtk_tree_model_iter_n_children (model, NULL);
72 if ( 0 == strcmp ("", gtk_entry_get_text (GTK_ENTRY (entry))))
80 transpose_dialog (GObject *o, gpointer data)
83 struct data_editor *de = data;
85 GladeXML *xml = XML_NEW ("psppire.glade");
87 PsppireVarStore *vs = NULL;
89 GtkWidget *dialog = get_widget_assert (xml, "transpose-dialog");
90 GtkWidget *source = get_widget_assert (xml, "source-treeview");
91 GtkWidget *dest = get_widget_assert (xml, "variables-treeview");
92 GtkWidget *selector1 = get_widget_assert (xml, "psppire-selector2");
93 GtkWidget *selector2 = get_widget_assert (xml, "psppire-selector3");
94 GtkWidget *new_name_entry = get_widget_assert (xml, "new-name-entry");
96 g_object_get (de->data_editor, "var-store", &vs, NULL);
98 attach_dictionary_to_treeview (GTK_TREE_VIEW (source),
100 GTK_SELECTION_MULTIPLE, NULL);
102 set_dest_model (GTK_TREE_VIEW (dest), vs->dict);
104 psppire_selector_set_subjects (PSPPIRE_SELECTOR (selector1),
106 insert_source_row_into_tree_view,
111 psppire_selector_set_subjects (PSPPIRE_SELECTOR (selector2),
112 source, new_name_entry,
113 insert_source_row_into_entry,
114 is_currently_in_entry,
118 g_signal_connect (dialog, "refresh", G_CALLBACK (refresh), xml);
120 gtk_window_set_transient_for (GTK_WINDOW (dialog), de->parent.window);
122 psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (dialog),
123 dialog_state_valid, xml);
125 response = psppire_dialog_run (PSPPIRE_DIALOG (dialog));
129 case GTK_RESPONSE_OK:
131 gchar *syntax = generate_syntax (vs->dict, xml);
132 struct getl_interface *sss = create_syntax_string_source (syntax);
133 execute_syntax (sss);
138 case PSPPIRE_RESPONSE_PASTE:
140 gchar *syntax = generate_syntax (vs->dict, xml);
142 struct syntax_editor *se =
143 (struct syntax_editor *) window_create (WINDOW_SYNTAX, NULL);
145 gtk_text_buffer_insert_at_cursor (se->buffer, syntax, -1);
154 g_object_unref (xml);
159 FLIP /VARIABLES=var_list /NEWNAMES=var_name.
162 generate_syntax (PsppireDict *dict, GladeXML *xml)
165 GString *string = g_string_new ("FLIP");
168 GtkWidget *dest = get_widget_assert (xml, "variables-treeview");
169 GtkWidget *entry = get_widget_assert (xml, "new-name-entry");
171 g_string_append (string, " /VARIABLES = ");
173 append_variable_names (string, dict, GTK_TREE_VIEW (dest), 0);
175 text = gtk_entry_get_text (GTK_ENTRY (entry));
178 g_string_append_printf (string, " /NEWNAME = %s", text);
180 g_string_append (string, ".");
182 syntax = string->str;
184 g_string_free (string, FALSE);