1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2012 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-sort.h"
22 #include "psppire-var-view.h"
24 #include "psppire-dialog.h"
25 #include "builder-wrapper.h"
27 static void psppire_dialog_action_sort_init (PsppireDialogActionSort *act);
28 static void psppire_dialog_action_sort_class_init (PsppireDialogActionSortClass *class);
30 G_DEFINE_TYPE (PsppireDialogActionSort, psppire_dialog_action_sort, PSPPIRE_TYPE_DIALOG_ACTION);
33 generate_syntax (PsppireDialogAction *act)
35 PsppireDialogActionSort *scd = PSPPIRE_DIALOG_ACTION_SORT (act);
37 GString *string = g_string_new ("SORT CASES BY ");
39 PsppireVarView *var_view = PSPPIRE_VAR_VIEW (scd->variables);
40 gint n_vars = psppire_var_view_append_names (var_view, 0, string);
44 g_string_assign (string, "");
49 (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (scd->ascending))
51 g_string_append_printf (string, "(%c)", up_down);
52 g_string_append (string, ".");
57 g_string_free (string, FALSE);
63 reset (PsppireDialogAction *act)
65 PsppireDialogActionSort *scd = PSPPIRE_DIALOG_ACTION_SORT (act);
67 GtkTreeModel *liststore = gtk_tree_view_get_model (GTK_TREE_VIEW (scd->variables));
69 gtk_list_store_clear (GTK_LIST_STORE (liststore));
71 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (scd->ascending), TRUE);
78 dialog_state_valid (gpointer act)
80 PsppireDialogActionSort *scd = PSPPIRE_DIALOG_ACTION_SORT (act);
81 GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (scd->variables));
83 gint n_rows = gtk_tree_model_iter_n_children (model, NULL);
93 psppire_dialog_action_sort_activate (GtkAction *a)
95 PsppireDialogAction *pda = PSPPIRE_DIALOG_ACTION (a);
96 PsppireDialogActionSort *act = PSPPIRE_DIALOG_ACTION_SORT (a);
98 GHashTable *thing = psppire_dialog_action_get_pointer (pda);
99 GtkBuilder *xml = g_hash_table_lookup (thing, a);
102 xml = builder_new ("sort.ui");
103 g_hash_table_insert (thing, a, xml);
106 pda->dialog = get_widget_assert (xml, "sort-cases-dialog");
107 pda->source = get_widget_assert (xml, "sort-cases-treeview1");
109 act->variables = get_widget_assert (xml, "sort-cases-treeview2");
110 act->ascending = get_widget_assert (xml, "sort-cases-radiobutton0");
112 psppire_dialog_action_set_refresh (pda, reset);
114 psppire_dialog_action_set_valid_predicate (pda,
117 if (PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_sort_parent_class)->activate)
118 PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_sort_parent_class)->activate (pda);
122 psppire_dialog_action_sort_class_init (PsppireDialogActionSortClass *class)
124 PsppireDialogActionClass *pdac = PSPPIRE_DIALOG_ACTION_CLASS (class);
125 psppire_dialog_action_set_activation (class, psppire_dialog_action_sort_activate);
127 pdac->generate_syntax = generate_syntax;
132 psppire_dialog_action_sort_init (PsppireDialogActionSort *act)