1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2007 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/>. */
19 #include "sort-cases-dialog.h"
21 #include "psppire-dialog.h"
22 #include "psppire-data-window.h"
23 #include "psppire-var-store.h"
24 #include "dialog-common.h"
25 #include "psppire-selector.h"
26 #include "dict-display.h"
28 #include <language/syntax-string-source.h>
32 refresh (PsppireDialog *dialog, GtkTreeView *dest)
34 GtkTreeModel *liststore = gtk_tree_view_get_model (dest);
37 gtk_list_store_clear (GTK_LIST_STORE (liststore));
41 struct sort_cases_dialog
45 GtkToggleButton *ascending;
50 dialog_state_valid (gpointer data)
52 struct sort_cases_dialog *scd = data;
53 GtkTreeModel *model = gtk_tree_view_get_model (scd->tv);
55 gint n_rows = gtk_tree_model_iter_n_children (model, NULL);
64 generate_syntax (const struct sort_cases_dialog *scd)
67 GString *string = g_string_new ("SORT CASES BY ");
68 gint n_vars = append_variable_names (string,
69 scd->dict, GTK_TREE_VIEW (scd->tv), 0);
72 g_string_assign (string, "");
76 gtk_toggle_button_get_active (scd->ascending) ? 'A' : 'D';
77 g_string_append_printf (string, "(%c)", up_down);
78 g_string_append (string, ".");
84 g_string_free (string, FALSE);
90 /* Pops up the Sort Cases dialog box */
92 sort_cases_dialog (GObject *o, gpointer data)
95 PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (data);
97 struct sort_cases_dialog scd;
99 GtkBuilder *xml = builder_new ("psppire.ui");
101 GtkWidget *dialog = get_widget_assert (xml, "sort-cases-dialog");
104 GtkWidget *source = get_widget_assert (xml, "sort-cases-treeview1");
105 GtkWidget *selector = get_widget_assert (xml, "sort-cases-selector");
106 GtkWidget *dest = get_widget_assert (xml, "sort-cases-treeview2");
108 PsppireVarStore *vs = NULL;
110 g_object_get (de->data_editor, "var-store", &vs, NULL);
112 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (de));
114 g_object_set (source, "dictionary", vs->dict, NULL);
116 set_dest_model (GTK_TREE_VIEW (dest), vs->dict);
118 psppire_selector_set_subjects (PSPPIRE_SELECTOR (selector),
121 insert_source_row_into_tree_view,
125 g_signal_connect (dialog, "refresh", G_CALLBACK (refresh), dest);
127 scd.tv = GTK_TREE_VIEW (dest);
130 GTK_TOGGLE_BUTTON (get_widget_assert (xml, "sort-cases-radiobutton0"));
133 psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (dialog),
134 dialog_state_valid, &scd);
137 response = psppire_dialog_run (PSPPIRE_DIALOG (dialog));
142 case GTK_RESPONSE_OK:
144 gchar *syntax = generate_syntax (&scd);
146 struct getl_interface *sss = create_syntax_string_source (syntax);
147 execute_syntax (sss);
152 case PSPPIRE_RESPONSE_PASTE:
154 gchar *syntax = generate_syntax (&scd);
155 paste_syntax_in_new_window (syntax);
164 g_object_unref (xml);