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"
32 #include <glade/glade.h>
35 #include "dialog-common.h"
37 /* FIXME: These shouldn't be here */
38 #include <gtksheet/gtksheet.h>
39 #include "psppire-var-store.h"
42 struct split_file_dialog
44 /* The XML that created the dialog */
47 /* The dictionary to which this dialog pertains */
50 /* The treeview widget containing the list of variables
51 upon which the file should be split */
55 PsppireSelector *selector;
60 generate_syntax (const struct split_file_dialog *sfd)
63 GtkWidget *off = get_widget_assert (sfd->xml, "split-radiobutton0");
66 get_widget_assert (sfd->xml, "split-file-grouping-vars");
68 GString *string = g_string_new ("SPLIT FILE OFF.");
70 if ( ! gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (off)))
72 GString * varlist = g_string_sized_new (80);
73 GtkWidget *sort = get_widget_assert (sfd->xml, "split-radiobutton3");
74 GtkWidget *layered = get_widget_assert (sfd->xml, "split-radiobutton1");
75 gint n_vars = append_variable_names (varlist,
76 sfd->dict, GTK_TREE_VIEW (vars));
80 g_string_assign (string, "");
82 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(sort)))
84 g_string_append (string, "SORT CASES BY");
85 g_string_append (string, varlist->str);
86 g_string_append (string, ".\n");
89 g_string_append (string, "SPLIT FILE ");
91 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (layered)))
92 g_string_append (string, "LAYERED ");
94 g_string_append (string, "SEPARATE ");
96 g_string_append (string, "BY ");
97 g_string_append (string, varlist->str);
98 g_string_append (string, ".");
100 g_string_free (varlist, TRUE);
105 g_string_free (string, FALSE);
112 on_off_toggled (GtkToggleButton *togglebutton,
115 GladeXML *xml = user_data;
116 GtkWidget *dest = get_widget_assert (xml, "split-file-grouping-vars");
117 GtkWidget *selector = get_widget_assert (xml, "split-file-selector");
118 GtkWidget *source = get_widget_assert (xml, "split-file-dict-treeview");
119 GtkWidget *button3 = get_widget_assert (xml, "split-radiobutton3");
120 GtkWidget *button4 = get_widget_assert (xml, "split-radiobutton4");
122 gboolean state = !gtk_toggle_button_get_active (togglebutton);
124 gtk_widget_set_sensitive (dest, state);
125 gtk_widget_set_sensitive (selector, state);
126 gtk_widget_set_sensitive (source, state);
127 gtk_widget_set_sensitive (button3, state);
128 gtk_widget_set_sensitive (button4, state);
132 refresh (PsppireDialog *dialog, struct split_file_dialog *d)
134 GtkWidget *off = get_widget_assert (d->xml, "split-radiobutton0");
135 GtkWidget *on = get_widget_assert (d->xml, "split-radiobutton1");
137 GtkTreeModel *liststore = gtk_tree_view_get_model (d->tv);
139 gint n_vars = dict_get_split_cnt (d->dict->dict);
142 gtk_list_store_clear (GTK_LIST_STORE (liststore));
145 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(off), TRUE);
150 struct variable *const *vars = dict_get_split_vars (d->dict->dict);
152 for (i = 0 ; i < n_vars; ++i )
154 gint idx = var_get_dict_index (vars[i]);
156 gtk_list_store_append (GTK_LIST_STORE (liststore), &iter);
157 gtk_list_store_set (GTK_LIST_STORE (liststore), &iter, 0, idx, -1);
160 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(on), TRUE);
163 gtk_toggle_button_toggled (GTK_TOGGLE_BUTTON(off));
168 /* Pops up the Split File dialog box */
170 split_file_dialog (GObject *o, gpointer data)
173 struct data_editor *de = data;
174 struct split_file_dialog sfd;
179 GtkWidget *selector ;
182 GtkSheet *var_sheet ;
184 sfd.xml = XML_NEW ("psppire.glade");
186 dialog = get_widget_assert (sfd.xml, "split-file-dialog");
187 source = get_widget_assert (sfd.xml, "split-file-dict-treeview");
188 dest = get_widget_assert (sfd.xml, "split-file-grouping-vars");
189 selector = get_widget_assert (sfd.xml, "split-file-selector");
190 on_off = get_widget_assert (sfd.xml, "split-radiobutton0");
192 var_sheet = GTK_SHEET (get_widget_assert (de->xml, "variable_sheet"));
194 PsppireVarStore *vs = PSPPIRE_VAR_STORE (gtk_sheet_get_model (var_sheet));
197 sfd.tv = GTK_TREE_VIEW (dest);
198 sfd.selector = PSPPIRE_SELECTOR (
199 get_widget_assert (sfd.xml, "split-file-selector"));
201 attach_dictionary_to_treeview (GTK_TREE_VIEW (source),
203 GTK_SELECTION_MULTIPLE, NULL);
206 g_signal_connect (on_off, "toggled", G_CALLBACK(on_off_toggled), sfd.xml);
209 set_dest_model (GTK_TREE_VIEW (dest), vs->dict);
211 psppire_selector_set_subjects (PSPPIRE_SELECTOR (selector),
214 insert_source_row_into_tree_view,
217 g_signal_connect (dialog, "refresh", G_CALLBACK (refresh), &sfd);
219 response = psppire_dialog_run (PSPPIRE_DIALOG (dialog));
224 case GTK_RESPONSE_OK:
226 gchar *syntax = generate_syntax (&sfd);
227 struct getl_interface *sss = create_syntax_string_source (syntax);
228 execute_syntax (sss);
233 case PSPPIRE_RESPONSE_PASTE:
235 gchar *syntax = generate_syntax (&sfd);
237 struct syntax_editor *se =
238 (struct syntax_editor *) window_create (WINDOW_SYNTAX, NULL);
240 gtk_text_buffer_insert_at_cursor (se->buffer, syntax, -1);
249 g_object_unref (sfd.xml);