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 "psppire-var-store.h"
39 struct split_file_dialog
41 /* The XML that created the dialog */
44 /* The dictionary to which this dialog pertains */
47 /* The treeview widget containing the list of variables
48 upon which the file should be split */
52 PsppireSelector *selector;
57 generate_syntax (const struct split_file_dialog *sfd)
60 GtkWidget *off = get_widget_assert (sfd->xml, "split-radiobutton0");
63 get_widget_assert (sfd->xml, "split-file-grouping-vars");
65 GString *string = g_string_new ("SPLIT FILE OFF.");
67 if ( ! gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (off)))
69 GString * varlist = g_string_sized_new (80);
70 GtkWidget *sort = get_widget_assert (sfd->xml, "split-radiobutton3");
71 GtkWidget *layered = get_widget_assert (sfd->xml, "split-radiobutton1");
72 gint n_vars = append_variable_names (varlist,
73 sfd->dict, GTK_TREE_VIEW (vars), 0);
77 g_string_assign (string, "");
79 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(sort)))
81 g_string_append (string, "SORT CASES BY");
82 g_string_append (string, varlist->str);
83 g_string_append (string, ".\n");
86 g_string_append (string, "SPLIT FILE ");
88 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (layered)))
89 g_string_append (string, "LAYERED ");
91 g_string_append (string, "SEPARATE ");
93 g_string_append (string, "BY ");
94 g_string_append (string, varlist->str);
95 g_string_append (string, ".");
97 g_string_free (varlist, TRUE);
102 g_string_free (string, FALSE);
109 on_off_toggled (GtkToggleButton *togglebutton,
112 GladeXML *xml = user_data;
113 GtkWidget *dest = get_widget_assert (xml, "split-file-grouping-vars");
114 GtkWidget *selector = get_widget_assert (xml, "split-file-selector");
115 GtkWidget *source = get_widget_assert (xml, "split-file-dict-treeview");
116 GtkWidget *button3 = get_widget_assert (xml, "split-radiobutton3");
117 GtkWidget *button4 = get_widget_assert (xml, "split-radiobutton4");
119 gboolean state = !gtk_toggle_button_get_active (togglebutton);
121 gtk_widget_set_sensitive (dest, state);
122 gtk_widget_set_sensitive (selector, state);
123 gtk_widget_set_sensitive (source, state);
124 gtk_widget_set_sensitive (button3, state);
125 gtk_widget_set_sensitive (button4, state);
129 refresh (PsppireDialog *dialog, struct split_file_dialog *d)
131 GtkWidget *off = get_widget_assert (d->xml, "split-radiobutton0");
132 GtkWidget *on = get_widget_assert (d->xml, "split-radiobutton1");
134 GtkTreeModel *liststore = gtk_tree_view_get_model (d->tv);
136 gint n_vars = dict_get_split_cnt (d->dict->dict);
139 gtk_list_store_clear (GTK_LIST_STORE (liststore));
142 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(off), TRUE);
147 const struct variable *const *vars = dict_get_split_vars (d->dict->dict);
149 for (i = 0 ; i < n_vars; ++i )
151 gint idx = var_get_dict_index (vars[i]);
153 gtk_list_store_append (GTK_LIST_STORE (liststore), &iter);
154 gtk_list_store_set (GTK_LIST_STORE (liststore), &iter, 0, idx, -1);
157 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(on), TRUE);
160 gtk_toggle_button_toggled (GTK_TOGGLE_BUTTON(off));
165 /* Pops up the Split File dialog box */
167 split_file_dialog (GObject *o, gpointer data)
170 struct data_editor *de = data;
171 struct split_file_dialog sfd;
172 PsppireVarStore *vs ;
177 GtkWidget *selector ;
180 sfd.xml = XML_NEW ("psppire.glade");
182 dialog = get_widget_assert (sfd.xml, "split-file-dialog");
183 source = get_widget_assert (sfd.xml, "split-file-dict-treeview");
184 dest = get_widget_assert (sfd.xml, "split-file-grouping-vars");
185 selector = get_widget_assert (sfd.xml, "split-file-selector");
186 on_off = get_widget_assert (sfd.xml, "split-radiobutton0");
188 g_object_get (de->data_editor, "var-store", &vs, NULL);
191 sfd.tv = GTK_TREE_VIEW (dest);
192 sfd.selector = PSPPIRE_SELECTOR (
193 get_widget_assert (sfd.xml, "split-file-selector"));
195 attach_dictionary_to_treeview (GTK_TREE_VIEW (source),
197 GTK_SELECTION_MULTIPLE, NULL);
200 g_signal_connect (on_off, "toggled", G_CALLBACK(on_off_toggled), sfd.xml);
203 set_dest_model (GTK_TREE_VIEW (dest), vs->dict);
205 psppire_selector_set_subjects (PSPPIRE_SELECTOR (selector),
208 insert_source_row_into_tree_view,
212 g_signal_connect (dialog, "refresh", G_CALLBACK (refresh), &sfd);
214 gtk_window_set_transient_for (GTK_WINDOW (dialog), de->parent.window);
216 response = psppire_dialog_run (PSPPIRE_DIALOG (dialog));
221 case GTK_RESPONSE_OK:
223 gchar *syntax = generate_syntax (&sfd);
224 struct getl_interface *sss = create_syntax_string_source (syntax);
225 execute_syntax (sss);
230 case PSPPIRE_RESPONSE_PASTE:
232 gchar *syntax = generate_syntax (&sfd);
234 struct syntax_editor *se =
235 (struct syntax_editor *) window_create (WINDOW_SYNTAX, NULL);
237 gtk_text_buffer_insert_at_cursor (se->buffer, syntax, -1);
246 g_object_unref (sfd.xml);