2 PSPPIRE --- A Graphical User Interface for PSPP
3 Copyright (C) 2007 Free Software Foundation
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 #include "weight-cases-dialog.h"
23 #include "psppire-selector.h"
24 #include "psppire-dialog.h"
26 #include "data-editor.h"
27 #include "dict-display.h"
28 #include <language/syntax-string-source.h>
29 #include "syntax-editor.h"
32 #include <glade/glade.h>
35 #define _(msgid) gettext (msgid)
36 #define N_(msgid) msgid
39 /* FIXME: These shouldn't be here */
40 #include <gtksheet/gtksheet.h>
41 #include "psppire-var-store.h"
44 on_select (PsppireSelector *sel, gpointer data)
46 GtkRadioButton *radiobutton2 = data;
48 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radiobutton2), TRUE);
52 on_deselect (PsppireSelector *sel, gpointer data)
54 GtkRadioButton *radiobutton1 = data;
56 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radiobutton1), TRUE);
61 on_toggle (GtkToggleButton *button, gpointer data)
63 GtkEntry *entry = data;
64 if ( gtk_toggle_button_get_active (button))
65 gtk_entry_set_text (entry, "");
68 struct weight_cases_dialog
78 refresh (PsppireDialog *dialog, const struct weight_cases_dialog *wcd)
80 const struct variable *var = dict_get_weight (wcd->dict->dict);
84 gtk_entry_set_text (wcd->entry, "");
85 gtk_label_set_text (wcd->status, _("Do not weight cases"));
86 gtk_toggle_button_set_active (wcd->off, TRUE);
91 g_strdup_printf (_("Weight cases by %s"), var_get_name (var));
93 gtk_entry_set_text (wcd->entry, var_get_name (var));
94 gtk_label_set_text (wcd->status, text);
97 gtk_toggle_button_set_active (wcd->on, TRUE);
100 g_signal_emit_by_name (wcd->entry, "activate");
104 static gchar * generate_syntax (const struct weight_cases_dialog *wcd);
107 /* Pops up the Weight Cases dialog box */
109 weight_cases_dialog (GObject *o, gpointer data)
112 struct data_editor *de = data;
113 struct weight_cases_dialog wcd;
115 GladeXML *xml = XML_NEW ("psppire.glade");
117 GtkWidget *dialog = get_widget_assert (xml, "weight-cases-dialog");
118 GtkWidget *source = get_widget_assert (xml, "weight-cases-treeview");
119 GtkWidget *entry = get_widget_assert (xml, "weight-cases-entry");
120 GtkWidget *selector = get_widget_assert (xml, "weight-cases-selector");
121 GtkWidget *radiobutton1 = get_widget_assert (xml,
122 "weight-cases-radiobutton1");
123 GtkWidget *radiobutton2 = get_widget_assert (xml, "radiobutton2");
124 GtkWidget *status = get_widget_assert (xml, "weight-status-label");
126 GtkSheet *var_sheet =
127 GTK_SHEET (get_widget_assert (de->xml, "variable_sheet"));
129 PsppireVarStore *vs = PSPPIRE_VAR_STORE (gtk_sheet_get_model (var_sheet));
131 gtk_window_set_transient_for (GTK_WINDOW (dialog), de->parent.window);
133 g_signal_connect (radiobutton1, "toggled", G_CALLBACK (on_toggle), entry);
134 g_signal_connect (selector, "selected", G_CALLBACK (on_select),
137 g_signal_connect (selector, "de-selected", G_CALLBACK (on_deselect),
140 attach_dictionary_to_treeview (GTK_TREE_VIEW (source),
142 GTK_SELECTION_SINGLE,
146 psppire_selector_set_subjects (PSPPIRE_SELECTOR (selector),
149 insert_source_row_into_entry,
150 is_currently_in_entry
155 wcd.entry = GTK_ENTRY (entry);
156 wcd.status = GTK_LABEL (status);
157 wcd.off = GTK_TOGGLE_BUTTON (radiobutton1);
158 wcd.on = GTK_TOGGLE_BUTTON (radiobutton2);
160 g_signal_connect (dialog, "refresh", G_CALLBACK (refresh), &wcd);
162 response = psppire_dialog_run (PSPPIRE_DIALOG (dialog));
164 g_object_unref (xml);
168 case GTK_RESPONSE_OK:
170 gchar *syntax = generate_syntax (&wcd);
171 struct getl_interface *sss = create_syntax_string_source (syntax);
172 execute_syntax (sss);
177 case PSPPIRE_RESPONSE_PASTE:
179 gchar *syntax = generate_syntax (&wcd);
181 struct syntax_editor *se =
182 (struct syntax_editor *) window_create (WINDOW_SYNTAX, NULL);
184 gtk_text_buffer_insert_at_cursor (se->buffer, syntax, -1);
196 generate_syntax (const struct weight_cases_dialog *wcd)
200 const gchar *text = gtk_entry_get_text (wcd->entry);
202 struct variable *var = psppire_dict_lookup_var (wcd->dict, text);
205 syntax = g_strdup ("WEIGHT OFF.");
207 syntax = g_strdup_printf ("WEIGHT BY %s.\n",