1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2011, 2012 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 "dialog-common.h"
20 #include <ui/syntax-gen.h>
21 #include <libpspp/str.h>
23 #include "runs-dialog.h"
24 #include "psppire-selector.h"
25 #include "psppire-dictview.h"
26 #include "psppire-dialog.h"
28 #include "psppire-data-window.h"
29 #include "psppire-var-view.h"
32 #include "builder-wrapper.h"
38 #define _(msgid) gettext (msgid)
39 #define N_(msgid) msgid
56 PsppireDataWindow *de ;
62 static char * generate_syntax (const struct runs *rd);
65 refresh (struct runs *fd)
68 GtkTreeModel *liststore =
69 gtk_tree_view_get_model (GTK_TREE_VIEW (fd->variables));
70 gtk_list_store_clear (GTK_LIST_STORE (liststore));
72 gtk_entry_set_text (GTK_ENTRY (fd->entry), "");
74 for (i = 0; i < 4; ++i)
75 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (fd->cb[i]), FALSE);
80 dialog_state_valid (gpointer data)
83 struct runs *fd = data;
85 GtkTreeModel *liststore = gtk_tree_view_get_model (GTK_TREE_VIEW (fd->variables));
87 if (gtk_tree_model_iter_n_children (liststore, NULL) < 1)
90 for (i = 0; i < 4; ++i)
92 if ( TRUE == gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (fd->cb[i])))
99 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (fd->cb[CB_CUSTOM])))
101 if (0 == strcmp ("", gtk_entry_get_text (GTK_ENTRY (fd->entry))))
109 /* Pops up the Runs dialog box */
111 runs_dialog (PsppireDataWindow *dw)
119 fd.xml = builder_new ("runs.ui");
121 dialog = get_widget_assert (fd.xml, "runs-dialog");
122 source = get_widget_assert (fd.xml, "dict-view");
124 fd.entry = get_widget_assert (fd.xml, "entry1");
125 fd.cb[CB_MEDIAN] = get_widget_assert (fd.xml, "checkbutton1");
126 fd.cb[CB_MEAN] = get_widget_assert (fd.xml, "checkbutton2");
127 fd.cb[CB_MODE] = get_widget_assert (fd.xml, "checkbutton4");
128 fd.cb[CB_CUSTOM] = get_widget_assert (fd.xml, "checkbutton3");
132 g_signal_connect_swapped (dialog, "refresh", G_CALLBACK (refresh), &fd);
135 fd.variables = get_widget_assert (fd.xml, "psppire-var-view1");
137 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (fd.de));
139 g_object_get (fd.de->data_editor, "dictionary", &fd.dict, NULL);
140 g_object_set (source, "model", fd.dict,
141 "predicate", var_is_numeric,
144 g_signal_connect (fd.cb[CB_CUSTOM], "toggled",
145 G_CALLBACK (set_sensitivity_from_toggle), fd.entry);
147 psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (dialog),
148 dialog_state_valid, &fd);
150 response = psppire_dialog_run (PSPPIRE_DIALOG (dialog));
154 case GTK_RESPONSE_OK:
155 g_free (execute_syntax_string (dw, generate_syntax (&fd)));
157 case PSPPIRE_RESPONSE_PASTE:
158 g_free (paste_syntax_to_window (generate_syntax (&fd)));
164 g_object_unref (fd.xml);
170 append_fragment (GString *string, const gchar *cut, PsppireVarView *vv)
172 g_string_append (string, "\n\t/RUNS");
174 g_string_append (string, " ( ");
175 g_string_append (string, cut);
176 g_string_append (string, " ) = ");
178 psppire_var_view_append_names (vv, 0, string);
183 generate_syntax (const struct runs *rd)
187 GString *string = g_string_new ("NPAR TEST");
189 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->cb[CB_MEAN])))
190 append_fragment (string, "MEAN", PSPPIRE_VAR_VIEW (rd->variables));
192 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->cb[CB_MEDIAN])))
193 append_fragment (string, "MEDIAN", PSPPIRE_VAR_VIEW (rd->variables));
195 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->cb[CB_MODE])))
196 append_fragment (string, "MODE", PSPPIRE_VAR_VIEW (rd->variables));
198 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->cb[CB_CUSTOM])))
200 const char *text = gtk_entry_get_text (GTK_ENTRY (rd->entry));
201 append_fragment (string, text, PSPPIRE_VAR_VIEW (rd->variables));
204 g_string_append (string, ".\n");
208 g_string_free (string, FALSE);