1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2007, 2010, 2011, 2012, 2015 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-split.h"
21 #include "psppire-selector.h"
22 #include "psppire-var-view.h"
23 #include "dict-display.h"
25 #include "psppire-dialog.h"
26 #include "builder-wrapper.h"
29 #define _(msgid) gettext (msgid)
30 #define N_(msgid) msgid
32 static void psppire_dialog_action_split_init (PsppireDialogActionSplit *act);
33 static void psppire_dialog_action_split_class_init (PsppireDialogActionSplitClass *class);
35 G_DEFINE_TYPE (PsppireDialogActionSplit, psppire_dialog_action_split, PSPPIRE_TYPE_DIALOG_ACTION);
39 generate_syntax (const PsppireDialogAction *pda)
41 PsppireDialogActionSplit *act = PSPPIRE_DIALOG_ACTION_SPLIT (pda);
44 GString *string = g_string_new ("SPLIT FILE OFF.");
46 if ( ! gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (act->off)))
48 GString * varlist = g_string_sized_new (80);
49 gint n_vars = psppire_var_view_append_names (PSPPIRE_VAR_VIEW (act->tv), 0, varlist);
53 g_string_assign (string, "");
55 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(act->sort)))
57 g_string_append (string, "SORT CASES BY");
58 g_string_append (string, varlist->str);
59 g_string_append (string, ".\n");
62 g_string_append (string, "SPLIT FILE ");
64 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (act->layered)))
65 g_string_append (string, "LAYERED ");
67 g_string_append (string, "SEPARATE ");
69 g_string_append (string, "BY ");
70 g_string_append (string, varlist->str);
71 g_string_append (string, ".");
73 g_string_free (varlist, TRUE);
78 g_string_free (string, FALSE);
85 dialog_state_valid (gpointer data)
91 refresh (PsppireDialogAction *pda)
93 PsppireDialogActionSplit *act = PSPPIRE_DIALOG_ACTION_SPLIT (pda);
95 GtkTreeModel *liststore = gtk_tree_view_get_model (GTK_TREE_VIEW (act->tv));
97 gint n_vars = dict_get_split_cnt (pda->dict->dict);
99 gtk_list_store_clear (GTK_LIST_STORE (liststore));
102 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (act->off), TRUE);
107 const struct variable *const *vars = dict_get_split_vars (pda->dict->dict);
109 for (i = 0 ; i < n_vars; ++i )
111 gtk_list_store_append (GTK_LIST_STORE (liststore), &iter);
113 gtk_list_store_set (GTK_LIST_STORE (liststore), &iter,
118 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (act->layered), TRUE);
121 gtk_toggle_button_toggled (GTK_TOGGLE_BUTTON (act->off));
123 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (act->sort), TRUE);
127 on_off_toggled (GtkToggleButton *togglebutton,
130 PsppireDialogActionSplit *act = PSPPIRE_DIALOG_ACTION_SPLIT (user_data);
132 gboolean state = !gtk_toggle_button_get_active (togglebutton);
134 gtk_widget_set_sensitive (act->dest, state);
135 gtk_widget_set_sensitive (act->selector, state);
136 gtk_widget_set_sensitive (act->source, state);
140 psppire_dialog_action_split_activate (PsppireDialogAction *pda)
142 PsppireDialogActionSplit *act = PSPPIRE_DIALOG_ACTION_SPLIT (pda);
144 GHashTable *thing = psppire_dialog_action_get_hash_table (pda);
145 GtkBuilder *xml = g_hash_table_lookup (thing, pda);
148 xml = builder_new ("split-file.ui");
149 g_hash_table_insert (thing, pda, xml);
151 pda->dialog = get_widget_assert (xml, "split-file-dialog");
152 pda->source = get_widget_assert (xml, "split-file-dict-treeview");
153 act->selector = get_widget_assert (xml, "split-file-selector");
155 act->dest = get_widget_assert (xml, "split-file-grouping-vars");
156 act->source = get_widget_assert (xml, "split-file-dict-treeview");
157 act->sort = get_widget_assert (xml, "split-sort");
159 act->off = get_widget_assert (xml, "split-off");
160 act->layered = get_widget_assert (xml, "split-layered");
162 act->tv = get_widget_assert (xml, "split-file-grouping-vars");
164 g_signal_connect (act->off, "toggled", G_CALLBACK (on_off_toggled), pda);
165 g_signal_connect_swapped (pda->dialog, "show", G_CALLBACK (refresh), pda);
168 psppire_dialog_action_set_valid_predicate (pda, dialog_state_valid);
169 psppire_dialog_action_set_refresh (pda, refresh);
174 psppire_dialog_action_split_class_init (PsppireDialogActionSplitClass *class)
176 psppire_dialog_action_set_activation (class, psppire_dialog_action_split_activate);
177 PSPPIRE_DIALOG_ACTION_CLASS (class)->generate_syntax = generate_syntax;
182 psppire_dialog_action_split_init (PsppireDialogActionSplit *act)