X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=src%2Fui%2Fgui%2Fweight-cases-dialog.c;h=066c5e54e1b27d9a2e5d2278d56f4cd7a82a5cf3;hb=a2979bf95f3eb83e88a3bd723c09f22548775de5;hp=50294de7fb72e039d1eab73760c583378a9d86c5;hpb=09a1109ddc398f36fe720208e1d38053850cbd2a;p=pspp
diff --git a/src/ui/gui/weight-cases-dialog.c b/src/ui/gui/weight-cases-dialog.c
index 50294de7fb..066c5e54e1 100644
--- a/src/ui/gui/weight-cases-dialog.c
+++ b/src/ui/gui/weight-cases-dialog.c
@@ -1,127 +1,182 @@
-/*
- PSPPIRE --- A Graphical User Interface for PSPP
- Copyright (C) 2007 Free Software Foundation
+/* PSPPIRE - a graphical user interface for PSPP.
+ Copyright (C) 2007, 2010 Free Software Foundation
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- 02110-1301, USA. */
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see . */
#include
-#include "psppire-var-select.h"
-#include
-#include "helper.h"
-#include
-
-#include "psppire-var-store.h"
#include "weight-cases-dialog.h"
-
+#include "psppire-selector.h"
#include "psppire-dialog.h"
+#include "executor.h"
+#include "psppire-data-window.h"
+#include "dict-display.h"
+#include "helper.h"
+
+#include
+#include
#define _(msgid) gettext (msgid)
#define N_(msgid) msgid
+
+#include "psppire-var-store.h"
+
+struct weight_cases_dialog
+{
+ PsppireDict *dict;
+ GtkEntry *entry;
+ GtkLabel *status;
+ GtkToggleButton *off;
+ GtkToggleButton *on;
+};
+
static void
-refresh_var_select (PsppireVarSelect *vs)
+on_select (PsppireSelector *sel, gpointer data)
{
- struct variable *weight;
+ struct weight_cases_dialog *wcd = data;
- psppire_var_select_deselect_all (vs);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (wcd->on), TRUE);
+ gtk_widget_set_sensitive (GTK_WIDGET (wcd->on), TRUE);
+}
- weight = psppire_dict_get_weight_variable (vs->dict);
+static void
+on_deselect (PsppireSelector *sel, gpointer data)
+{
+ struct weight_cases_dialog *wcd = data;
- if ( weight )
- psppire_var_select_set_variable (vs, weight);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (wcd->off), TRUE);
+ gtk_widget_set_sensitive (GTK_WIDGET (wcd->on), FALSE);
}
static void
-on_refresh (GtkWidget *dialog, gpointer data)
+on_toggle (GtkToggleButton *button, gpointer data)
{
- refresh_var_select (data);
+ GtkEntry *entry = data;
+ if ( gtk_toggle_button_get_active (button))
+ gtk_entry_set_text (entry, "");
}
-
static void
-on_radiobutton_toggle (GtkToggleButton *button, gpointer data)
+refresh (PsppireDialog *dialog, const struct weight_cases_dialog *wcd)
{
- PsppireVarSelect *vs = data;
- if ( gtk_toggle_button_get_active (button) )
+ const struct variable *var = dict_get_weight (wcd->dict->dict);
+
+ if ( ! var )
{
- psppire_var_select_deselect_all (vs);
+ gtk_entry_set_text (wcd->entry, "");
+ gtk_label_set_text (wcd->status, _("Do not weight cases"));
+ gtk_toggle_button_set_active (wcd->off, TRUE);
}
+ else
+ {
+ gchar *text =
+ g_strdup_printf (_("Weight cases by %s"), var_get_name (var));
+
+ gtk_entry_set_text (wcd->entry, var_get_name (var));
+ gtk_label_set_text (wcd->status, text);
+
+ g_free (text);
+ gtk_toggle_button_set_active (wcd->on, TRUE);
+ }
+
+ g_signal_emit_by_name (wcd->entry, "activate");
}
-/* Callback for when new variable is selected.
- IDX is the dict index of the variable selected.
- Updates the label and toggle buttons in the dialog box
- to reflect this new selection. */
-static void
-select_var_callback (PsppireVarSelect *vs, gint idx, gpointer data)
-{
- GladeXML * xml = data;
+static gchar * generate_syntax (const struct weight_cases_dialog *wcd);
- GtkWidget *label = get_widget_assert (xml, "weight-status-label");
- GtkWidget *radiobutton2 = get_widget_assert (xml, "radiobutton2");
+/* Pops up the Weight Cases dialog box */
+void
+weight_cases_dialog (PsppireDataWindow *de)
+{
+ gint response;
+ struct weight_cases_dialog wcd;
- struct variable *var = psppire_dict_get_variable (vs->dict, idx);
+ GtkBuilder *xml = builder_new ("psppire.ui");
- gtk_label_set_text (GTK_LABEL (label), var_get_name(var));
+ GtkWidget *dialog = get_widget_assert (xml, "weight-cases-dialog");
+ GtkWidget *source = get_widget_assert (xml, "weight-cases-treeview");
+ GtkWidget *entry = get_widget_assert (xml, "weight-cases-entry");
+ GtkWidget *radiobutton1 = get_widget_assert (xml,
+ "weight-cases-radiobutton1");
+ GtkWidget *radiobutton2 = get_widget_assert (xml, "radiobutton2");
+ GtkWidget *status = get_widget_assert (xml, "weight-status-label");
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radiobutton2), TRUE);
-}
+ GtkWidget *selector = get_widget_assert (xml, "weight-cases-selector");
+ PsppireVarStore *vs = NULL;
+ g_object_get (de->data_editor, "var-store", &vs, NULL);
+ g_object_get (vs, "dictionary", &wcd.dict, NULL);
-static void
-deselect_all (PsppireVarSelect *vs, gpointer data)
-{
- GladeXML * xml = data;
+ gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (de));
- GtkWidget *label = get_widget_assert (xml, "weight-status-label");
+ g_signal_connect (radiobutton1, "toggled", G_CALLBACK (on_toggle), entry);
- GtkWidget *radiobutton1 = get_widget_assert (xml, "radiobutton1");
+ g_signal_connect (selector, "selected", G_CALLBACK (on_select), &wcd);
+ g_signal_connect (selector, "de-selected", G_CALLBACK (on_deselect), &wcd);
+
+ g_object_set (source, "model", wcd.dict,
+ "selection-mode", GTK_SELECTION_SINGLE,
+ "predicate", var_is_numeric,
+ NULL);
- gtk_label_set_text (GTK_LABEL (label), _("Do not weight cases"));
+ psppire_selector_set_filter_func (PSPPIRE_SELECTOR (selector),
+ is_currently_in_entry);
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radiobutton1), TRUE);
-}
+ wcd.entry = GTK_ENTRY (entry);
+ wcd.status = GTK_LABEL (status);
+ wcd.off = GTK_TOGGLE_BUTTON (radiobutton1);
+ wcd.on = GTK_TOGGLE_BUTTON (radiobutton2);
+ g_signal_connect (dialog, "refresh", G_CALLBACK (refresh), &wcd);
+ response = psppire_dialog_run (PSPPIRE_DIALOG (dialog));
-PsppireDialog *
-create_weight_dialog (PsppireVarSelect *select, GladeXML *xml)
-{
- GtkWidget *dialog = get_widget_assert (xml, "weight-cases-dialog");
- GtkWidget *radiobutton1 = get_widget_assert (xml, "radiobutton1");
+ g_object_unref (xml);
- g_signal_connect (dialog, "refresh", G_CALLBACK (on_refresh), select);
+ switch (response)
+ {
+ case GTK_RESPONSE_OK:
+ g_free (execute_syntax_string (generate_syntax (&wcd)));
+ break;
+ case PSPPIRE_RESPONSE_PASTE:
+ g_free (paste_syntax_to_window (generate_syntax (&wcd)));
+ break;
+ default:
+ break;
+ }
+}
- g_signal_connect (select, "variable-selected",
- G_CALLBACK (select_var_callback), xml);
- g_signal_connect (select, "deselect-all",
- G_CALLBACK (deselect_all), xml);
+static gchar *
+generate_syntax (const struct weight_cases_dialog *wcd)
+{
+ gchar *syntax;
+
+ const gchar *text = gtk_entry_get_text (wcd->entry);
- g_signal_connect (radiobutton1, "toggled",
- G_CALLBACK (on_radiobutton_toggle),
- select);
+ struct variable *var = psppire_dict_lookup_var (wcd->dict, text);
- refresh_var_select (select);
+ if ( var == NULL)
+ syntax = g_strdup ("WEIGHT OFF.");
+ else
+ syntax = g_strdup_printf ("WEIGHT BY %s.\n",
+ var_get_name (var));
- return PSPPIRE_DIALOG (dialog);
+ return syntax;
}