e3f7017fffc9ca05045b03a736a5a6d2ec05ac03
[pspp] / src / ui / gui / psppire-dialog-action-correlation.c
1 /* PSPPIRE - a graphical user interface for PSPP.
2    Copyright (C) 2012  Free Software Foundation
3
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.
8
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.
13
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/>. */
16
17
18 #include <config.h>
19
20 #include "psppire-dialog-action-correlation.h"
21
22 #include "psppire-var-view.h"
23
24 #include "psppire-dialog.h"
25 #include "builder-wrapper.h"
26
27 static void psppire_dialog_action_correlation_init            (PsppireDialogActionCorrelation      *act);
28 static void psppire_dialog_action_correlation_class_init      (PsppireDialogActionCorrelationClass *class);
29
30 G_DEFINE_TYPE (PsppireDialogActionCorrelation, psppire_dialog_action_correlation, PSPPIRE_TYPE_DIALOG_ACTION);
31
32 static char *
33 generate_syntax (PsppireDialogAction *act)
34 {
35   PsppireDialogActionCorrelation *rd = PSPPIRE_DIALOG_ACTION_CORRELATION (act);
36   gchar *text;
37   GString *string = g_string_new ("CORRELATION");
38   g_string_append (string, "\n\t/VARIABLES = ");
39
40   psppire_var_view_append_names (PSPPIRE_VAR_VIEW (rd->variables), 0, string);
41
42
43   g_string_append (string, "\n\t/PRINT =");
44
45   if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->two_tailed)))
46     g_string_append (string, " TWOTAIL");
47   else
48     g_string_append (string, " ONETAIL");
49
50
51   if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->significant)))
52     g_string_append (string, " NOSIG");
53   else
54     g_string_append (string, " SIG");
55
56
57   g_string_append (string, ".\n");
58
59   text = string->str;
60
61   g_string_free (string, FALSE);
62
63   return text;
64 }
65
66
67 static gboolean
68 dialog_state_valid (gpointer user_data)
69 {
70   PsppireDialogActionCorrelation *corr = user_data;
71   GtkTreeModel *liststore =
72     gtk_tree_view_get_model (GTK_TREE_VIEW (corr->variables));
73
74   if  (gtk_tree_model_iter_n_children (liststore, NULL) > 1)
75     return TRUE;
76
77   return FALSE;
78 }
79
80 static void
81 refresh (PsppireDialogAction *rd_)
82 {
83   PsppireDialogActionCorrelation *rd =
84     PSPPIRE_DIALOG_ACTION_CORRELATION (rd_);
85   GtkTreeModel *liststore =
86     gtk_tree_view_get_model (GTK_TREE_VIEW (rd->variables));
87   gtk_list_store_clear (GTK_LIST_STORE (liststore));
88
89   gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (rd->significant), FALSE);
90
91   gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (rd->two_tailed), TRUE);
92 }
93
94 static void
95 psppire_dialog_action_correlation_activate (GtkAction *a)
96 {
97   PsppireDialogAction *pda = PSPPIRE_DIALOG_ACTION (a);
98   PsppireDialogActionCorrelation *act = PSPPIRE_DIALOG_ACTION_CORRELATION (a);
99
100   GHashTable *thing = psppire_dialog_action_get_hash_table (pda);
101   GtkBuilder *xml = g_hash_table_lookup (thing, a);
102   if (!xml)
103     {
104       xml = builder_new ("correlation.ui");
105       g_hash_table_insert (thing, a, xml);
106     }
107
108   pda->dialog = get_widget_assert (xml, "correlation-dialog");
109   pda->source = get_widget_assert (xml, "dict-view");
110
111   act->variables = get_widget_assert (xml, "psppire-var-view1");
112   act->significant = get_widget_assert (xml, "button-flag-significants");
113   act->two_tailed = get_widget_assert (xml, "button-two-tailed");
114
115   psppire_dialog_action_set_valid_predicate (pda, dialog_state_valid);
116   psppire_dialog_action_set_refresh (pda, refresh);
117
118   if (PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_correlation_parent_class)->activate)
119     PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_correlation_parent_class)->activate (pda);
120 }
121
122 static void
123 psppire_dialog_action_correlation_class_init (PsppireDialogActionCorrelationClass *class)
124 {
125   psppire_dialog_action_set_activation (class, psppire_dialog_action_correlation_activate);
126
127   PSPPIRE_DIALOG_ACTION_CLASS (class)->generate_syntax = generate_syntax;
128 }
129
130
131 static void
132 psppire_dialog_action_correlation_init (PsppireDialogActionCorrelation *act)
133 {
134 }
135