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/>. */
20 #include <ui/gui/builder-wrapper.h>
21 #include "psppire-dialog.h"
22 #include "dict-display.h"
24 #include "psppire-var-view.h"
25 #include "psppire-selector.h"
26 #include "psppire-dictview.h"
27 #include <ui/gui/dialog-common.h>
32 #include "univariate-dialog.h"
36 struct dictionary *dict;
38 /* Entry box for the dependent variable */
41 GtkWidget *factor_list;
45 /* Dialog is valid iff at least one variable has been selected in both
46 the dependent variable box and the factor list. */
48 dialog_state_valid (gpointer data)
50 struct uni_dialog *uv_d = data;
54 if ( 0 == strcmp ("", gtk_entry_get_text (GTK_ENTRY (uv_d->dep_entry))))
58 gtk_tree_view_get_model (GTK_TREE_VIEW (uv_d->factor_list));
60 return gtk_tree_model_get_iter_first (vars, ¬used);
63 /* Reset the dialog to its default state */
65 refresh (PsppireDialog *dialog, struct uni_dialog *uv_d)
67 GtkTreeModel *liststore ;
69 gtk_entry_set_text (GTK_ENTRY (uv_d->dep_entry), "");
71 liststore = gtk_tree_view_get_model (GTK_TREE_VIEW (uv_d->factor_list));
73 gtk_list_store_clear (GTK_LIST_STORE (liststore));
78 generate_syntax (const struct uni_dialog *uvd)
81 GString *str = g_string_new ("GLM ");
84 g_string_append (str, gtk_entry_get_text (GTK_ENTRY (uvd->dep_entry)));
87 g_string_append (str, " BY ");
89 psppire_var_view_append_names (PSPPIRE_VAR_VIEW (uvd->factor_list), 0, str);
92 g_string_append (str, ".");
96 g_string_free (str, FALSE);
102 univariate_dialog (PsppireDataWindow * de)
104 struct uni_dialog uv_d;
108 GtkBuilder *xml = builder_new ("univariate.ui");
110 GtkWidget *dialog = get_widget_assert (xml, "univariate-dialog");
111 GtkWidget *source = get_widget_assert (xml, "dict-view");
113 GtkWidget *dep_selector = get_widget_assert (xml, "dep-selector");
114 GtkWidget *factor_selector = get_widget_assert (xml, "factor-selector");
117 PsppireVarStore *vs = NULL;
119 uv_d.dep_entry = get_widget_assert (xml, "dep-entry");
120 uv_d.factor_list = get_widget_assert (xml, "factors-view");
122 g_object_get (de->data_editor, "var-store", &vs, NULL);
124 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (de));
125 g_signal_connect (dialog, "refresh", G_CALLBACK (refresh), &uv_d);
127 psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (dialog),
128 dialog_state_valid, &uv_d);
131 g_object_get (vs, "dictionary", &uv_d.dict, NULL);
132 g_object_set (source, "model", uv_d.dict, NULL);
134 psppire_selector_set_allow (PSPPIRE_SELECTOR (dep_selector),
137 psppire_selector_set_filter_func (PSPPIRE_SELECTOR (dep_selector),
138 is_currently_in_entry);
141 psppire_selector_set_filter_func (PSPPIRE_SELECTOR (factor_selector),
142 is_currently_in_varview);
144 response = psppire_dialog_run (PSPPIRE_DIALOG (dialog));
149 case GTK_RESPONSE_OK:
150 g_free (execute_syntax_string (de, generate_syntax (&uv_d)));
152 case PSPPIRE_RESPONSE_PASTE:
153 g_free (paste_syntax_to_window (generate_syntax (&uv_d)));
159 g_object_unref (xml);