1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2012, 2013 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 "psppire-dialog-action-univariate.h"
22 #include "psppire-var-view.h"
24 #include "psppire-dialog.h"
25 #include "builder-wrapper.h"
27 static void psppire_dialog_action_univariate_init (PsppireDialogActionUnivariate *act);
28 static void psppire_dialog_action_univariate_class_init (PsppireDialogActionUnivariateClass *class);
30 G_DEFINE_TYPE (PsppireDialogActionUnivariate, psppire_dialog_action_univariate, PSPPIRE_TYPE_DIALOG_ACTION);
33 generate_syntax (const PsppireDialogAction *act)
35 PsppireDialogActionUnivariate *uvd = PSPPIRE_DIALOG_ACTION_UNIVARIATE (act);
38 GString *str = g_string_new ("GLM ");
40 g_string_append (str, gtk_entry_get_text (GTK_ENTRY (uvd->dep_entry)));
42 g_string_append (str, " BY ");
44 psppire_var_view_append_names (PSPPIRE_VAR_VIEW (uvd->factor_list), 0, str);
46 g_string_append (str, ".\n");
50 g_string_free (str, FALSE);
57 dialog_state_valid (gpointer data)
59 PsppireDialogActionUnivariate *ud = PSPPIRE_DIALOG_ACTION_UNIVARIATE (data);
63 if ( 0 == strcmp ("", gtk_entry_get_text (GTK_ENTRY (ud->dep_entry))))
67 gtk_tree_view_get_model (GTK_TREE_VIEW (ud->factor_list));
69 return gtk_tree_model_get_iter_first (vars, ¬used);
73 refresh (PsppireDialogAction *rd_)
75 PsppireDialogActionUnivariate *uv = PSPPIRE_DIALOG_ACTION_UNIVARIATE (rd_);
76 GtkTreeModel *liststore ;
78 gtk_entry_set_text (GTK_ENTRY (uv->dep_entry), "");
80 liststore = gtk_tree_view_get_model (GTK_TREE_VIEW (uv->factor_list));
82 gtk_list_store_clear (GTK_LIST_STORE (liststore));
86 psppire_dialog_action_univariate_activate (PsppireDialogAction *a)
88 PsppireDialogAction *pda = PSPPIRE_DIALOG_ACTION (a);
89 PsppireDialogActionUnivariate *act = PSPPIRE_DIALOG_ACTION_UNIVARIATE (a);
91 GHashTable *thing = psppire_dialog_action_get_hash_table (pda);
92 GtkBuilder *xml = g_hash_table_lookup (thing, a);
95 xml = builder_new ("univariate.ui");
96 g_hash_table_insert (thing, a, xml);
99 pda->dialog = get_widget_assert (xml, "univariate-dialog");
100 pda->source = get_widget_assert (xml, "dict-view");
102 act->dep_entry = get_widget_assert (xml, "dep-entry");
103 act->factor_list = get_widget_assert (xml, "factors-view");
105 psppire_dialog_action_set_valid_predicate (pda, dialog_state_valid);
106 psppire_dialog_action_set_refresh (pda, refresh);
111 psppire_dialog_action_univariate_class_init (PsppireDialogActionUnivariateClass *class)
113 psppire_dialog_action_set_activation (class, psppire_dialog_action_univariate_activate);
114 PSPPIRE_DIALOG_ACTION_CLASS (class)->generate_syntax = generate_syntax;
119 psppire_dialog_action_univariate_init (PsppireDialogActionUnivariate *act)