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 "split-file-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"
27 #include <data/dictionary.h>
30 #include <glade/glade.h>
33 #include "dialog-common.h"
35 /* FIXME: These shouldn't be here */
36 #include <gtksheet/gtksheet.h>
37 #include "psppire-var-store.h"
40 struct split_file_dialog
42 /* The XML that created the dialog */
45 /* The dictionary to which this dialog pertains */
48 /* The treeview widget containing the list of variables
49 upon which the file should be split */
53 PsppireSelector *selector;
58 generate_syntax (const struct split_file_dialog *sfd)
61 GtkWidget *off = get_widget_assert (sfd->xml, "split-radiobutton0");
64 get_widget_assert (sfd->xml, "split-file-grouping-vars");
66 GString *string = g_string_new ("SPLIT FILE OFF.");
68 if ( ! gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (off)))
70 GString * varlist = g_string_sized_new (80);
71 GtkWidget *sort = get_widget_assert (sfd->xml, "split-radiobutton3");
72 GtkWidget *layered = get_widget_assert (sfd->xml, "split-radiobutton1");
73 gint n_vars = append_variable_names (varlist,
74 sfd->dict, GTK_TREE_VIEW (vars));
78 g_string_assign (string, "");
80 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(sort)))
82 g_string_append (string, "SORT CASES BY");
83 g_string_append (string, varlist->str);
84 g_string_append (string, ".\n");
87 g_string_append (string, "SPLIT FILE ");
89 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (layered)))
90 g_string_append (string, "LAYERED ");
92 g_string_append (string, "SEPARATE ");
94 g_string_append (string, "BY ");
95 g_string_append (string, varlist->str);
96 g_string_append (string, ".");
98 g_string_free (varlist, TRUE);
103 g_string_free (string, FALSE);
110 on_off_toggled (GtkToggleButton *togglebutton,
113 GladeXML *xml = user_data;
114 GtkWidget *dest = get_widget_assert (xml, "split-file-grouping-vars");
115 GtkWidget *selector = get_widget_assert (xml, "split-file-selector");
116 GtkWidget *source = get_widget_assert (xml, "split-file-dict-treeview");
117 GtkWidget *button3 = get_widget_assert (xml, "split-radiobutton3");
118 GtkWidget *button4 = get_widget_assert (xml, "split-radiobutton4");
120 gboolean state = !gtk_toggle_button_get_active (togglebutton);
122 gtk_widget_set_sensitive (dest, state);
123 gtk_widget_set_sensitive (selector, state);
124 gtk_widget_set_sensitive (source, state);
125 gtk_widget_set_sensitive (button3, state);
126 gtk_widget_set_sensitive (button4, state);
130 refresh (PsppireDialog *dialog, struct split_file_dialog *d)
132 GtkWidget *off = get_widget_assert (d->xml, "split-radiobutton0");
133 GtkWidget *on = get_widget_assert (d->xml, "split-radiobutton1");
135 GtkTreeModel *liststore = gtk_tree_view_get_model (d->tv);
137 gint n_vars = dict_get_split_cnt (d->dict->dict);
140 gtk_list_store_clear (GTK_LIST_STORE (liststore));
143 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(off), TRUE);
148 const struct variable *const *vars = dict_get_split_vars (d->dict->dict);
150 for (i = 0 ; i < n_vars; ++i )
152 gint idx = var_get_dict_index (vars[i]);
154 gtk_list_store_append (GTK_LIST_STORE (liststore), &iter);
155 gtk_list_store_set (GTK_LIST_STORE (liststore), &iter, 0, idx, -1);
158 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(on), TRUE);
161 gtk_toggle_button_toggled (GTK_TOGGLE_BUTTON(off));
166 /* Pops up the Split File dialog box */
168 split_file_dialog (GObject *o, gpointer data)
171 struct data_editor *de = data;
172 struct split_file_dialog sfd;
173 PsppireVarStore *vs ;
178 GtkWidget *selector ;
181 GtkSheet *var_sheet ;
183 sfd.xml = XML_NEW ("psppire.glade");
185 dialog = get_widget_assert (sfd.xml, "split-file-dialog");
186 source = get_widget_assert (sfd.xml, "split-file-dict-treeview");
187 dest = get_widget_assert (sfd.xml, "split-file-grouping-vars");
188 selector = get_widget_assert (sfd.xml, "split-file-selector");
189 on_off = get_widget_assert (sfd.xml, "split-radiobutton0");
191 var_sheet = GTK_SHEET (get_widget_assert (de->xml, "variable_sheet"));
193 vs = PSPPIRE_VAR_STORE (gtk_sheet_get_model (var_sheet));
196 sfd.tv = GTK_TREE_VIEW (dest);
197 sfd.selector = PSPPIRE_SELECTOR (
198 get_widget_assert (sfd.xml, "split-file-selector"));
200 attach_dictionary_to_treeview (GTK_TREE_VIEW (source),
202 GTK_SELECTION_MULTIPLE, NULL);
205 g_signal_connect (on_off, "toggled", G_CALLBACK(on_off_toggled), sfd.xml);
208 set_dest_model (GTK_TREE_VIEW (dest), vs->dict);
210 psppire_selector_set_subjects (PSPPIRE_SELECTOR (selector),
213 insert_source_row_into_tree_view,
216 g_signal_connect (dialog, "refresh", G_CALLBACK (refresh), &sfd);
218 response = psppire_dialog_run (PSPPIRE_DIALOG (dialog));
223 case GTK_RESPONSE_OK:
225 gchar *syntax = generate_syntax (&sfd);
226 struct getl_interface *sss = create_syntax_string_source (syntax);
227 execute_syntax (sss);
232 case PSPPIRE_RESPONSE_PASTE:
234 gchar *syntax = generate_syntax (&sfd);
236 struct syntax_editor *se =
237 (struct syntax_editor *) window_create (WINDOW_SYNTAX, NULL);
239 gtk_text_buffer_insert_at_cursor (se->buffer, syntax, -1);
248 g_object_unref (sfd.xml);