1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2011 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/helper.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>
31 #include "univariate-dialog.h"
35 struct dictionary *dict;
37 /* Entry box for the dependent variable */
40 GtkWidget *factor_list;
44 /* Dialog is valid iff at least one variable has been selected in both
45 the dependent variable box and the factor list. */
47 dialog_state_valid (gpointer data)
49 struct uni_dialog *uv_d = data;
53 if ( 0 == strcmp ("", gtk_entry_get_text (GTK_ENTRY (uv_d->dep_entry))))
57 gtk_tree_view_get_model (GTK_TREE_VIEW (uv_d->factor_list));
59 return gtk_tree_model_get_iter_first (vars, ¬used);
62 /* Reset the dialog to its default state */
64 refresh (PsppireDialog *dialog, struct uni_dialog *uv_d)
66 GtkTreeModel *liststore ;
68 gtk_entry_set_text (GTK_ENTRY (uv_d->dep_entry), "");
70 liststore = gtk_tree_view_get_model (GTK_TREE_VIEW (uv_d->factor_list));
72 gtk_list_store_clear (GTK_LIST_STORE (liststore));
77 generate_syntax (const struct uni_dialog *uvd)
80 GString *str = g_string_new ("GLM ");
83 g_string_append (str, gtk_entry_get_text (GTK_ENTRY (uvd->dep_entry)));
86 g_string_append (str, " BY ");
88 psppire_var_view_append_names (PSPPIRE_VAR_VIEW (uvd->factor_list), 0, str);
91 g_string_append (str, ".");
95 g_string_free (str, FALSE);
101 univariate_dialog (PsppireDataWindow * de)
103 struct uni_dialog uv_d;
107 GtkBuilder *xml = builder_new ("univariate.ui");
109 GtkWidget *dialog = get_widget_assert (xml, "univariate-dialog");
110 GtkWidget *source = get_widget_assert (xml, "dict-view");
112 GtkWidget *dep_selector = get_widget_assert (xml, "dep-selector");
113 GtkWidget *factor_selector = get_widget_assert (xml, "factor-selector");
116 PsppireVarStore *vs = NULL;
118 uv_d.dep_entry = get_widget_assert (xml, "dep-entry");
119 uv_d.factor_list = get_widget_assert (xml, "factors-view");
121 g_object_get (de->data_editor, "var-store", &vs, NULL);
123 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (de));
124 g_signal_connect (dialog, "refresh", G_CALLBACK (refresh), &uv_d);
126 psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (dialog),
127 dialog_state_valid, &uv_d);
130 g_object_get (vs, "dictionary", &uv_d.dict, NULL);
131 g_object_set (source, "model", uv_d.dict, NULL);
133 psppire_selector_set_allow (PSPPIRE_SELECTOR (dep_selector),
136 psppire_selector_set_filter_func (PSPPIRE_SELECTOR (dep_selector),
137 is_currently_in_entry);
140 psppire_selector_set_filter_func (PSPPIRE_SELECTOR (factor_selector),
141 is_currently_in_varview);
143 response = psppire_dialog_run (PSPPIRE_DIALOG (dialog));
148 case GTK_RESPONSE_OK:
149 g_free (execute_syntax_string (de, generate_syntax (&uv_d)));
151 case PSPPIRE_RESPONSE_PASTE:
152 g_free (paste_syntax_to_window (generate_syntax (&uv_d)));
158 g_object_unref (xml);