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 "split-file-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"
30 #include <data/dictionary.h>
33 #include <glade/glade.h>
36 #include "dialog-common.h"
38 /* FIXME: These shouldn't be here */
39 #include <gtksheet/gtksheet.h>
40 #include "psppire-var-store.h"
43 struct split_file_dialog
45 /* The XML that created the dialog */
48 /* The dictionary to which this dialog pertains */
51 /* The treeview widget containing the list of variables
52 upon which the file should be split */
56 PsppireSelector *selector;
61 generate_syntax (const struct split_file_dialog *sfd)
64 GtkWidget *off = get_widget_assert (sfd->xml, "split-radiobutton0");
67 get_widget_assert (sfd->xml, "split-file-grouping-vars");
69 GString *string = g_string_new ("SPLIT FILE OFF.");
71 if ( ! gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (off)))
73 GString * varlist = g_string_sized_new (80);
74 GtkWidget *sort = get_widget_assert (sfd->xml, "split-radiobutton3");
75 GtkWidget *layered = get_widget_assert (sfd->xml, "split-radiobutton1");
76 gint n_vars = append_variable_names (varlist,
77 sfd->dict, GTK_TREE_VIEW (vars));
81 g_string_assign (string, "");
83 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(sort)))
85 g_string_append (string, "SORT CASES BY");
86 g_string_append (string, varlist->str);
87 g_string_append (string, ".\n");
90 g_string_append (string, "SPLIT FILE ");
92 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (layered)))
93 g_string_append (string, "LAYERED ");
95 g_string_append (string, "SEPARATE ");
97 g_string_append (string, "BY ");
98 g_string_append (string, varlist->str);
99 g_string_append (string, ".");
101 g_string_free (varlist, TRUE);
106 g_string_free (string, FALSE);
113 on_off_toggled (GtkToggleButton *togglebutton,
116 GladeXML *xml = user_data;
117 GtkWidget *dest = get_widget_assert (xml, "split-file-grouping-vars");
118 GtkWidget *selector = get_widget_assert (xml, "split-file-selector");
119 GtkWidget *source = get_widget_assert (xml, "split-file-dict-treeview");
120 GtkWidget *button3 = get_widget_assert (xml, "split-radiobutton3");
121 GtkWidget *button4 = get_widget_assert (xml, "split-radiobutton4");
123 gboolean state = !gtk_toggle_button_get_active (togglebutton);
125 gtk_widget_set_sensitive (dest, state);
126 gtk_widget_set_sensitive (selector, state);
127 gtk_widget_set_sensitive (source, state);
128 gtk_widget_set_sensitive (button3, state);
129 gtk_widget_set_sensitive (button4, state);
133 refresh (PsppireDialog *dialog, struct split_file_dialog *d)
135 GtkWidget *off = get_widget_assert (d->xml, "split-radiobutton0");
136 GtkWidget *on = get_widget_assert (d->xml, "split-radiobutton1");
138 GtkTreeModel *liststore = gtk_tree_view_get_model (d->tv);
140 gint n_vars = dict_get_split_cnt (d->dict->dict);
143 gtk_list_store_clear (GTK_LIST_STORE (liststore));
146 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(off), TRUE);
151 const struct variable *const *vars = dict_get_split_vars (d->dict->dict);
153 for (i = 0 ; i < n_vars; ++i )
155 gint idx = var_get_dict_index (vars[i]);
157 gtk_list_store_append (GTK_LIST_STORE (liststore), &iter);
158 gtk_list_store_set (GTK_LIST_STORE (liststore), &iter, 0, idx, -1);
161 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(on), TRUE);
164 gtk_toggle_button_toggled (GTK_TOGGLE_BUTTON(off));
169 /* Pops up the Split File dialog box */
171 split_file_dialog (GObject *o, gpointer data)
174 struct data_editor *de = data;
175 struct split_file_dialog sfd;
176 PsppireVarStore *vs ;
181 GtkWidget *selector ;
184 GtkSheet *var_sheet ;
186 sfd.xml = XML_NEW ("psppire.glade");
188 dialog = get_widget_assert (sfd.xml, "split-file-dialog");
189 source = get_widget_assert (sfd.xml, "split-file-dict-treeview");
190 dest = get_widget_assert (sfd.xml, "split-file-grouping-vars");
191 selector = get_widget_assert (sfd.xml, "split-file-selector");
192 on_off = get_widget_assert (sfd.xml, "split-radiobutton0");
194 var_sheet = GTK_SHEET (get_widget_assert (de->xml, "variable_sheet"));
196 vs = PSPPIRE_VAR_STORE (gtk_sheet_get_model (var_sheet));
199 sfd.tv = GTK_TREE_VIEW (dest);
200 sfd.selector = PSPPIRE_SELECTOR (
201 get_widget_assert (sfd.xml, "split-file-selector"));
203 attach_dictionary_to_treeview (GTK_TREE_VIEW (source),
205 GTK_SELECTION_MULTIPLE, NULL);
208 g_signal_connect (on_off, "toggled", G_CALLBACK(on_off_toggled), sfd.xml);
211 set_dest_model (GTK_TREE_VIEW (dest), vs->dict);
213 psppire_selector_set_subjects (PSPPIRE_SELECTOR (selector),
216 insert_source_row_into_tree_view,
219 g_signal_connect (dialog, "refresh", G_CALLBACK (refresh), &sfd);
221 response = psppire_dialog_run (PSPPIRE_DIALOG (dialog));
226 case GTK_RESPONSE_OK:
228 gchar *syntax = generate_syntax (&sfd);
229 struct getl_interface *sss = create_syntax_string_source (syntax);
230 execute_syntax (sss);
235 case PSPPIRE_RESPONSE_PASTE:
237 gchar *syntax = generate_syntax (&sfd);
239 struct syntax_editor *se =
240 (struct syntax_editor *) window_create (WINDOW_SYNTAX, NULL);
242 gtk_text_buffer_insert_at_cursor (se->buffer, syntax, -1);
251 g_object_unref (sfd.xml);