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"
44 generate_syntax (GladeXML *xml, PsppireDict *dict)
47 GtkWidget *off = get_widget_assert (xml, "split-radiobutton0");
50 get_widget_assert (xml, "split-file-grouping-vars");
52 GString *string = g_string_new ("SPLIT FILE OFF.");
54 if ( ! gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (off)))
56 GString * varlist = g_string_sized_new (80);
57 GtkWidget *sort = get_widget_assert (xml, "split-radiobutton3");
58 GtkWidget *layered = get_widget_assert (xml, "split-radiobutton1");
59 gint n_vars = append_variable_names (varlist,
60 dict, GTK_TREE_VIEW (vars));
64 g_string_assign (string, "");
66 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(sort)))
68 g_string_append (string, "SORT CASES BY");
69 g_string_append (string, varlist->str);
70 g_string_append (string, ".\n");
73 g_string_append (string, "SPLIT FILE ");
75 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (layered)))
76 g_string_append (string, "LAYERED ");
78 g_string_append (string, "SEPARATE ");
80 g_string_append (string, "BY ");
81 g_string_append (string, varlist->str);
82 g_string_append (string, ".");
84 g_string_free (varlist, TRUE);
89 g_string_free (string, FALSE);
96 on_off_toggled (GtkToggleButton *togglebutton,
99 GladeXML *xml = user_data;
100 GtkWidget *dest = get_widget_assert (xml, "split-file-grouping-vars");
101 GtkWidget *selector = get_widget_assert (xml, "split-file-selector");
102 GtkWidget *source = get_widget_assert (xml, "split-file-dict-treeview");
103 GtkWidget *button3 = get_widget_assert (xml, "split-radiobutton3");
104 GtkWidget *button4 = get_widget_assert (xml, "split-radiobutton4");
106 gboolean state = !gtk_toggle_button_get_active (togglebutton);
108 gtk_widget_set_sensitive (dest, state);
109 gtk_widget_set_sensitive (selector, state);
110 gtk_widget_set_sensitive (source, state);
111 gtk_widget_set_sensitive (button3, state);
112 gtk_widget_set_sensitive (button4, state);
116 refresh (GladeXML *xml)
118 GtkWidget *off = get_widget_assert (xml, "split-radiobutton0");
120 g_print ("%s\n", __FUNCTION__);
122 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(off), TRUE);
123 gtk_toggle_button_toggled (GTK_TOGGLE_BUTTON(off));
128 /* Pops up the Weight Cases dialog box */
130 split_file_dialog (GObject *o, gpointer data)
133 struct data_editor *de = data;
136 GladeXML *xml = XML_NEW ("psppire.glade");
138 GtkWidget *dialog = get_widget_assert (xml, "split-file-dialog");
139 GtkWidget *source = get_widget_assert (xml, "split-file-dict-treeview");
140 GtkWidget *dest = get_widget_assert (xml, "split-file-grouping-vars");
141 GtkWidget *selector = get_widget_assert (xml, "split-file-selector");
142 GtkWidget *on_off = get_widget_assert (xml, "split-radiobutton0");
144 GtkSheet *var_sheet =
145 GTK_SHEET (get_widget_assert (de->xml, "variable_sheet"));
147 PsppireVarStore *vs = PSPPIRE_VAR_STORE (gtk_sheet_get_model (var_sheet));
151 attach_dictionary_to_treeview (GTK_TREE_VIEW (source),
153 GTK_SELECTION_MULTIPLE, NULL);
156 g_signal_connect (on_off, "toggled", G_CALLBACK(on_off_toggled), xml);
159 set_dest_model (GTK_TREE_VIEW (dest), vs->dict);
161 psppire_selector_set_subjects (PSPPIRE_SELECTOR (selector),
164 insert_source_row_into_tree_view,
169 response = psppire_dialog_run (PSPPIRE_DIALOG (dialog));
174 case GTK_RESPONSE_OK:
176 gchar *syntax = generate_syntax (xml, dict);
177 struct getl_interface *sss = create_syntax_string_source (syntax);
178 execute_syntax (sss);
183 case PSPPIRE_RESPONSE_PASTE:
185 gchar *syntax = generate_syntax (xml, dict);
187 struct syntax_editor *se =
188 (struct syntax_editor *) window_create (WINDOW_SYNTAX, NULL);
190 gtk_text_buffer_insert_at_cursor (se->buffer, syntax, -1);
199 g_object_unref (xml);