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 gint n_vars = psppire_var_view_append_names (scd->variables, 0, string);
43 g_string_assign (string, "");
48 gtk_toggle_button_get_active (scd->ascending) ? 'A' : 'D';
49 g_string_append_printf (string, "(%c)", up_down);
50 g_string_append (string, ".");
55 g_string_free (string, FALSE);
61 reset (PsppireDialogAction *act)
63 PsppireDialogActionSort *scd = PSPPIRE_DIALOG_ACTION_SORT (act);
65 GtkTreeModel *liststore = gtk_tree_view_get_model (GTK_TREE_VIEW (scd->variables));
67 gtk_list_store_clear (GTK_LIST_STORE (liststore));
69 gtk_toggle_button_set_active (scd->ascending, TRUE);
76 dialog_state_valid (PsppireDialogAction *act)
78 PsppireDialogActionSort *scd = PSPPIRE_DIALOG_ACTION_SORT (act);
79 GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (scd->variables));
81 gint n_rows = gtk_tree_model_iter_n_children (model, NULL);
91 psppire_dialog_action_sort_activate (GtkAction *a)
93 PsppireDialogAction *pda = PSPPIRE_DIALOG_ACTION (a);
94 PsppireDialogActionSort *act = PSPPIRE_DIALOG_ACTION_SORT (a);
96 GtkBuilder *xml = builder_new ("sort.ui");
97 pda->dialog = get_widget_assert (xml, "sort-cases-dialog");
98 pda->source = get_widget_assert (xml, "sort-cases-treeview1");
100 act->variables = get_widget_assert (xml, "sort-cases-treeview2");
101 act->ascending = get_widget_assert (xml, "sort-cases-radiobutton0");
103 psppire_dialog_action_set_refresh (pda, reset);
105 psppire_dialog_action_set_valid_predicate (pda,
108 if (PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_sort_parent_class)->activate)
109 PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_sort_parent_class)->activate (pda);
113 psppire_dialog_action_sort_class_init (PsppireDialogActionSortClass *class)
115 GtkActionClass *action_class = GTK_ACTION_CLASS (class);
116 PsppireDialogActionClass *pdac = PSPPIRE_DIALOG_ACTION_CLASS (class);
118 action_class->activate = psppire_dialog_action_sort_activate;
120 pdac->generate_syntax = generate_syntax;
125 psppire_dialog_action_sort_init (PsppireDialogActionSort *act)