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-runs.h"
22 #include "psppire-var-view.h"
24 #include "psppire-dialog.h"
25 #include "builder-wrapper.h"
27 static void psppire_dialog_action_runs_init (PsppireDialogActionRuns *act);
28 static void psppire_dialog_action_runs_class_init (PsppireDialogActionRunsClass *class);
30 G_DEFINE_TYPE (PsppireDialogActionRuns, psppire_dialog_action_runs, PSPPIRE_TYPE_DIALOG_ACTION);
42 append_fragment (GString *string, const gchar *cut, PsppireVarView *vv)
44 g_string_append (string, "\n\t/RUNS");
46 g_string_append (string, " (");
47 g_string_append (string, cut);
48 g_string_append (string, ") = ");
50 psppire_var_view_append_names (vv, 0, string);
54 generate_syntax (const PsppireDialogAction *act)
56 PsppireDialogActionRuns *rd = PSPPIRE_DIALOG_ACTION_RUNS (act);
59 GString *string = g_string_new ("NPAR TEST");
61 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->cb[CB_MEAN])))
62 append_fragment (string, "MEAN", PSPPIRE_VAR_VIEW (rd->variables));
64 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->cb[CB_MEDIAN])))
65 append_fragment (string, "MEDIAN", PSPPIRE_VAR_VIEW (rd->variables));
67 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->cb[CB_MODE])))
68 append_fragment (string, "MODE", PSPPIRE_VAR_VIEW (rd->variables));
70 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->cb[CB_CUSTOM])))
72 const char *text = gtk_entry_get_text (GTK_ENTRY (rd->entry));
73 append_fragment (string, text, PSPPIRE_VAR_VIEW (rd->variables));
76 g_string_append (string, ".\n");
80 g_string_free (string, FALSE);
87 dialog_state_valid (gpointer data)
90 PsppireDialogActionRuns *fd = PSPPIRE_DIALOG_ACTION_RUNS (data);
92 GtkTreeModel *liststore = gtk_tree_view_get_model (GTK_TREE_VIEW (fd->variables));
94 if (gtk_tree_model_iter_n_children (liststore, NULL) < 1)
97 for (i = 0; i < 4; ++i)
99 if (TRUE == gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (fd->cb[i])))
106 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (fd->cb[CB_CUSTOM])))
108 if (0 == strcmp ("", gtk_entry_get_text (GTK_ENTRY (fd->entry))))
116 refresh (PsppireDialogAction *rd_)
118 PsppireDialogActionRuns *rd = PSPPIRE_DIALOG_ACTION_RUNS (rd_);
120 GtkTreeModel *liststore =
121 gtk_tree_view_get_model (GTK_TREE_VIEW (rd->variables));
122 gtk_list_store_clear (GTK_LIST_STORE (liststore));
124 gtk_entry_set_text (GTK_ENTRY (rd->entry), "");
126 for (i = 0; i < 4; ++i)
127 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (rd->cb[i]), FALSE);
131 psppire_dialog_action_runs_activate (PsppireDialogAction *a, GVariant *param)
133 PsppireDialogAction *pda = PSPPIRE_DIALOG_ACTION (a);
134 PsppireDialogActionRuns *act = PSPPIRE_DIALOG_ACTION_RUNS (a);
136 GtkBuilder *xml = builder_new ("runs.ui");
138 pda->dialog = get_widget_assert (xml, "runs-dialog");
139 pda->source = get_widget_assert (xml, "dict-view");
141 act->entry = get_widget_assert (xml, "entry1");
142 act->cb[CB_MEDIAN] = get_widget_assert (xml, "checkbutton1");
143 act->cb[CB_MEAN] = get_widget_assert (xml, "checkbutton2");
144 act->cb[CB_MODE] = get_widget_assert (xml, "checkbutton4");
145 act->cb[CB_CUSTOM] = get_widget_assert (xml, "checkbutton3");
146 act->variables = get_widget_assert (xml, "psppire-var-view1");
148 psppire_dialog_action_set_valid_predicate (pda, dialog_state_valid);
149 psppire_dialog_action_set_refresh (pda, refresh);
154 psppire_dialog_action_runs_class_init (PsppireDialogActionRunsClass *class)
156 PSPPIRE_DIALOG_ACTION_CLASS (class)->initial_activate = psppire_dialog_action_runs_activate;
157 PSPPIRE_DIALOG_ACTION_CLASS (class)->generate_syntax = generate_syntax;
162 psppire_dialog_action_runs_init (PsppireDialogActionRuns *act)