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>
34 /* FIXME: These shouldn't be here */
35 #include <gtksheet/gtksheet.h>
36 #include "psppire-var-store.h"
39 on_select (PsppireSelector *sel, gpointer data)
41 GtkRadioButton *radiobutton2 = data;
43 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radiobutton2), TRUE);
47 on_deselect (PsppireSelector *sel, gpointer data)
49 GtkRadioButton *radiobutton1 = data;
51 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radiobutton1), TRUE);
56 on_toggle (GtkToggleButton *button, gpointer data)
58 GtkEntry *entry = data;
59 if ( gtk_toggle_button_get_active (button))
60 gtk_entry_set_text (entry, "");
66 static gchar * generate_syntax (PsppireDict *, GtkEntry *);
69 /* Pops up the Weight Cases dialog box */
71 weight_cases_dialog (GObject *o, gpointer data)
74 struct data_editor *de = data;
78 GladeXML *xml = glade_xml_new (PKGDATADIR "/psppire.glade",
79 "weight-cases-dialog", NULL);
81 GtkWidget *dialog = get_widget_assert (xml, "weight-cases-dialog");
82 GtkWidget *source = get_widget_assert (xml, "weight-cases-treeview");
83 GtkWidget *entry = get_widget_assert (xml, "weight-cases-entry");
84 GtkWidget *selector = get_widget_assert (xml, "weight-cases-selector");
85 GtkWidget *radiobutton1 = get_widget_assert (xml,
86 "weight-cases-radiobutton1");
87 GtkWidget *radiobutton2 = get_widget_assert (xml, "radiobutton2");
90 GTK_SHEET (get_widget_assert (de->xml, "variable_sheet"));
92 PsppireVarStore *vs = PSPPIRE_VAR_STORE (gtk_sheet_get_model (var_sheet));
96 g_signal_connect (radiobutton1, "toggled", G_CALLBACK (on_toggle), entry);
97 g_signal_connect (selector, "selected", G_CALLBACK (on_select),
100 g_signal_connect (selector, "de-selected", G_CALLBACK (on_deselect),
103 attach_dictionary_to_treeview (GTK_TREE_VIEW (source),
105 GTK_SELECTION_SINGLE,
109 psppire_selector_set_subjects (PSPPIRE_SELECTOR (selector),
112 insert_source_row_into_entry,
113 is_currently_in_entry
116 var = dict_get_weight (dict->dict);
118 gtk_entry_set_text (GTK_ENTRY (entry), "");
120 gtk_entry_set_text (GTK_ENTRY (entry), var_get_name (var));
122 g_signal_emit_by_name (entry, "activate");
124 response = psppire_dialog_run (PSPPIRE_DIALOG (dialog));
126 g_object_unref (xml);
130 case GTK_RESPONSE_OK:
132 gchar *syntax = generate_syntax (dict, GTK_ENTRY (entry));
133 struct getl_interface *sss = create_syntax_string_source (syntax);
134 execute_syntax (sss);
139 case PSPPIRE_RESPONSE_PASTE:
141 gchar *syntax = generate_syntax (dict, GTK_ENTRY (entry));
143 struct syntax_editor *se =
144 (struct syntax_editor *) window_create (WINDOW_SYNTAX, NULL);
146 gtk_text_buffer_insert_at_cursor (se->buffer, syntax, -1);
158 generate_syntax (PsppireDict *dict, GtkEntry *entry)
162 const gchar *text = gtk_entry_get_text (entry);
164 struct variable *var = psppire_dict_lookup_var (dict, text);
167 syntax = g_strdup ("WEIGHT OFF.");
169 syntax = g_strdup_printf ("WEIGHT BY %s.\n",