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 <gtksheet/gtksheet.h>
41 #include "psppire-var-store.h"
44 static gchar * generate_syntax (PsppireDict *dict, GladeXML *xml);
47 refresh (PsppireDialog *dialog, gpointer data)
50 GtkWidget *dest = get_widget_assert (xml, "variables-treeview");
51 GtkWidget *entry = get_widget_assert (xml, "new-name-entry");
52 GtkTreeModel *dmodel = gtk_tree_view_get_model (GTK_TREE_VIEW (dest));
54 gtk_list_store_clear (GTK_LIST_STORE (dmodel));
55 gtk_entry_set_text (GTK_ENTRY (entry), "");
59 transpose_dialog (GObject *o, gpointer data)
62 struct data_editor *de = data;
64 GladeXML *xml = XML_NEW ("psppire.glade");
67 GTK_SHEET (get_widget_assert (de->xml, "variable_sheet"));
69 PsppireVarStore *vs = PSPPIRE_VAR_STORE (gtk_sheet_get_model (var_sheet));
71 GtkWidget *dialog = get_widget_assert (xml, "transpose-dialog");
72 GtkWidget *source = get_widget_assert (xml, "source-treeview");
73 GtkWidget *dest = get_widget_assert (xml, "variables-treeview");
74 GtkWidget *selector1 = get_widget_assert (xml, "psppire-selector2");
75 GtkWidget *selector2 = get_widget_assert (xml, "psppire-selector3");
76 GtkWidget *new_name_entry = get_widget_assert (xml, "new-name-entry");
78 attach_dictionary_to_treeview (GTK_TREE_VIEW (source),
80 GTK_SELECTION_MULTIPLE, NULL);
82 set_dest_model (GTK_TREE_VIEW (dest), vs->dict);
84 psppire_selector_set_subjects (PSPPIRE_SELECTOR (selector1),
86 insert_source_row_into_tree_view,
90 psppire_selector_set_subjects (PSPPIRE_SELECTOR (selector2),
91 source, new_name_entry,
92 insert_source_row_into_entry,
93 is_currently_in_entry);
96 g_signal_connect (dialog, "refresh", G_CALLBACK (refresh), xml);
98 response = psppire_dialog_run (PSPPIRE_DIALOG (dialog));
102 case GTK_RESPONSE_OK:
104 gchar *syntax = generate_syntax (vs->dict, xml);
105 struct getl_interface *sss = create_syntax_string_source (syntax);
106 execute_syntax (sss);
111 case PSPPIRE_RESPONSE_PASTE:
113 gchar *syntax = generate_syntax (vs->dict, xml);
115 struct syntax_editor *se =
116 (struct syntax_editor *) window_create (WINDOW_SYNTAX, NULL);
118 gtk_text_buffer_insert_at_cursor (se->buffer, syntax, -1);
127 g_object_unref (xml);
132 FLIP /VARIABLES=var_list /NEWNAMES=var_name.
135 generate_syntax (PsppireDict *dict, GladeXML *xml)
138 GString *string = g_string_new ("FLIP");
141 GtkWidget *dest = get_widget_assert (xml, "variables-treeview");
142 GtkWidget *entry = get_widget_assert (xml, "new-name-entry");
144 g_string_append (string, " /VARIABLES = ");
146 append_variable_names (string, dict, GTK_TREE_VIEW (dest));
148 text = gtk_entry_get_text (GTK_ENTRY (entry));
151 g_string_append_printf (string, " /NEWNAME = %s", text);
153 g_string_append (string, ".");
155 syntax = string->str;
157 g_string_free (string, FALSE);