X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fui%2Fgui%2Fdata-editor.c;h=33d5a3e4c883840f6989c3a9e2fb981eb555e809;hb=09a1109ddc398f36fe720208e1d38053850cbd2a;hp=7e320bbdfd1603826225a7a972f576510b737384;hpb=cda91450a687e3f520ec4614dcc2d09f6f7c82bb;p=pspp-builds.git diff --git a/src/ui/gui/data-editor.c b/src/ui/gui/data-editor.c index 7e320bbd..33d5a3e4 100644 --- a/src/ui/gui/data-editor.c +++ b/src/ui/gui/data-editor.c @@ -1,6 +1,6 @@ /* PSPPIRE --- A Graphical User Interface for PSPP - Copyright (C) 2006 Free Software Foundation + Copyright (C) 2006, 2007 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 @@ -29,6 +29,8 @@ #include "helper.h" #include "about.h" +#include "psppire-dialog.h" +#include "psppire-var-select.h" #define _(msgid) gettext (msgid) #define N_(msgid) msgid @@ -40,6 +42,8 @@ #include "psppire-data-store.h" #include "psppire-var-store.h" +#include "weight-cases-dialog.h" + static void insert_variable (GtkCheckMenuItem *m, gpointer data); @@ -55,6 +59,9 @@ static gboolean click2row (GtkWidget *w, gint row, gpointer data); static void select_sheet (struct data_editor *de, guint page_num); +/* Callback for when the dictionary changes its weights */ +static void on_weight_change (GObject *, gint, gpointer); + static void data_var_select (GtkNotebook *notebook, GtkNotebookPage *page, guint page_num, @@ -100,37 +107,7 @@ disable_edit_clear (GtkWidget *w, gint x, gint y, gpointer data) return FALSE; } - -/* Callback for when the dictionary changes its weights */ -static void -on_weight_change (GObject *o, gint weight_index, gpointer data) -{ - struct data_editor *de = data; - GtkWidget *weight_status_area = - get_widget_assert (de->xml, "weight-status-area"); - - if ( weight_index == -1 ) - { - gtk_label_set_text (GTK_LABEL (weight_status_area), _("Weights off")); - } - else - { - GtkSheet *var_sheet = - GTK_SHEET (get_widget_assert (de->xml, "variable_sheet")); - - PsppireVarStore *vs = PSPPIRE_VAR_STORE - (gtk_sheet_get_model (var_sheet) ); - - struct variable *var = psppire_dict_get_variable (vs->dict, - weight_index); - - gchar *text = g_strdup_printf (_("Weight by %s"), var_get_name (var)); - - gtk_label_set_text (GTK_LABEL (weight_status_area), text); - - g_free (text); - } -} +static void weight_cases_dialog (GObject *o, gpointer data); /* @@ -161,6 +138,16 @@ new_data_editor (void) connect_help (de->xml); + de->invoke_weight_cases_dialog = + gtk_action_new ("weight-cases-dialog", + _("Weights"), + _("Weight cases by variable"), + "pspp-weight-cases"); + + + g_signal_connect (de->invoke_weight_cases_dialog, "activate", + G_CALLBACK (weight_cases_dialog), de); + e->window = GTK_WINDOW (get_widget_assert (de->xml, "data_editor")); g_signal_connect (get_widget_assert (de->xml,"file_new_data"), @@ -195,6 +182,17 @@ new_data_editor (void) G_CALLBACK (insert_variable), de); + gtk_action_connect_proxy (de->invoke_weight_cases_dialog, + get_widget_assert (de->xml, "data_weight-cases") + ); + + /* + g_signal_connect (get_widget_assert (de->xml,"data_weight-cases"), + "activate", + G_CALLBACK (weight_cases_dialog), + de); + */ + g_signal_connect (get_widget_assert (de->xml,"help_about"), "activate", @@ -275,6 +273,10 @@ new_data_editor (void) G_CALLBACK (value_labels_toggled), de); + gtk_action_connect_proxy (de->invoke_weight_cases_dialog, + get_widget_assert (de->xml, "button-weight-cases") + ); + g_signal_connect (get_widget_assert (de->xml, "file_quit"), "activate", G_CALLBACK (file_quit), de); @@ -644,12 +646,9 @@ insert_variable (GtkCheckMenuItem *m, gpointer data) GtkSheet *var_sheet = GTK_SHEET (get_widget_assert (de->xml, "variable_sheet")); - - PsppireVarStore *vs = PSPPIRE_VAR_STORE (gtk_sheet_get_model (var_sheet) ); - switch ( gtk_notebook_get_current_page ( GTK_NOTEBOOK (notebook)) ) { case PAGE_VAR_SHEET: @@ -671,7 +670,85 @@ insert_variable (GtkCheckMenuItem *m, gpointer data) } psppire_dict_insert_variable (vs->dict, posn, NULL); +} + + +/* Callback for when the dictionary changes its weights */ +static void +on_weight_change (GObject *o, gint weight_index, gpointer data) +{ + struct data_editor *de = data; + GtkWidget *weight_status_area = + get_widget_assert (de->xml, "weight-status-area"); + + if ( weight_index == -1 ) + { + gtk_label_set_text (GTK_LABEL (weight_status_area), _("Weights off")); + } + else + { + GtkSheet *var_sheet = + GTK_SHEET (get_widget_assert (de->xml, "variable_sheet")); + + PsppireVarStore *vs = PSPPIRE_VAR_STORE + (gtk_sheet_get_model (var_sheet) ); + + struct variable *var = psppire_dict_get_variable (vs->dict, + weight_index); + gchar *text = g_strdup_printf (_("Weight by %s"), var_get_name (var)); + + gtk_label_set_text (GTK_LABEL (weight_status_area), text); + + g_free (text); + } +} + + +static void +weight_cases_dialog (GObject *o, gpointer data) +{ + gint response; + struct data_editor *de = data; + GtkSheet *var_sheet = + GTK_SHEET (get_widget_assert (de->xml, "variable_sheet")); + + + GladeXML *xml = glade_xml_new (PKGDATADIR "/psppire.glade", + "weight-cases-dialog", NULL); + + + GtkWidget *treeview = get_widget_assert (xml, "treeview"); + GtkWidget *entry = get_widget_assert (xml, "entry1"); + + + PsppireVarStore *vs = PSPPIRE_VAR_STORE (gtk_sheet_get_model (var_sheet)); + + PsppireVarSelect *select = psppire_var_select_new (treeview, + entry, vs->dict); + + + PsppireDialog *dialog = create_weight_dialog (select, xml); + + response = psppire_dialog_run (dialog); + + g_object_unref (xml); + + if (response == GTK_RESPONSE_OK) + { + const GList *list = psppire_var_select_get_variables (select); + + g_assert ( g_list_length (list) <= 1 ); + + if ( list == NULL) + psppire_dict_set_weight_variable (select->dict, NULL); + else + { + struct variable *var = list->data; + + psppire_dict_set_weight_variable (select->dict, var); + } + } }