X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fui%2Fgui%2Fpsppire-dialog-action-select.c;h=a524de63d933003697664c10b0ad51fbf7935eb4;hb=128192d98c77ce9399f90483f8a100942af68205;hp=d3eee6570dcf242ff19516122ce52d9c597c0956;hpb=469b69a6df92b30f18a4a5c7262d9290601a0a88;p=pspp diff --git a/src/ui/gui/psppire-dialog-action-select.c b/src/ui/gui/psppire-dialog-action-select.c index d3eee6570d..a524de63d9 100644 --- a/src/ui/gui/psppire-dialog-action-select.c +++ b/src/ui/gui/psppire-dialog-action-select.c @@ -47,6 +47,18 @@ G_DEFINE_TYPE (PsppireDialogActionSelect, psppire_dialog_action_select, PSPPIRE_ static gboolean dialog_state_valid (gpointer data) { + PsppireDialogActionSelect *act = PSPPIRE_DIALOG_ACTION_SELECT (data); + if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (act->radiobutton_all))) + { + return TRUE; + } + else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (act->radiobutton_filter_variable))) + { + const gchar *text = gtk_entry_get_text (GTK_ENTRY (act->entry)); + if (!psppire_dict_lookup_var (PSPPIRE_DIALOG_ACTION (act)->dict, text)) + return FALSE; + } + return TRUE; } @@ -77,6 +89,23 @@ static const gchar label1[] = N_("Approximately %3d%% of all cases."); static const gchar label2[] = N_("Exactly %3d cases from the first %3d cases."); +/* Ensure that the range "first" and "last" spinbuttons are self consistent */ +static void +sample_consistent (GtkSpinButton *spin, PsppireDialogActionSelect *act) +{ + gdouble size = gtk_spin_button_get_value (GTK_SPIN_BUTTON (act->spin_sample_size)); + gdouble limit = gtk_spin_button_get_value (GTK_SPIN_BUTTON (act->spin_sample_limit)); + + if (limit < size) + { + if (spin == GTK_SPIN_BUTTON (act->spin_sample_size)) + gtk_spin_button_set_value (GTK_SPIN_BUTTON (act->spin_sample_limit), size); + if (spin == GTK_SPIN_BUTTON (act->spin_sample_limit)) + gtk_spin_button_set_value (GTK_SPIN_BUTTON (act->spin_sample_size), limit); + } +} + + static void sample_subdialog (GtkButton *b, gpointer data) { @@ -112,14 +141,18 @@ sample_subdialog (GtkButton *b, gpointer data) if (!scd->hbox2) { scd->hbox2 = - psppire_scanf_new (gettext (label2), &scd->spinbutton1, &scd->spinbutton2); + psppire_scanf_new (gettext (label2), &scd->spin_sample_size, &scd->spin_sample_limit); - gtk_spin_button_set_range (GTK_SPIN_BUTTON (scd->spinbutton1), + gtk_spin_button_set_range (GTK_SPIN_BUTTON (scd->spin_sample_size), 1, case_count); - gtk_spin_button_set_range (GTK_SPIN_BUTTON (scd->spinbutton2), + gtk_spin_button_set_range (GTK_SPIN_BUTTON (scd->spin_sample_limit), 1, case_count); + g_signal_connect (scd->spin_sample_size, "value-changed", G_CALLBACK (sample_consistent), scd); + g_signal_connect (scd->spin_sample_limit, "value-changed", G_CALLBACK (sample_consistent), scd); + + gtk_widget_show (scd->hbox2); gtk_widget_set_sensitive (scd->hbox2, FALSE); @@ -167,7 +200,7 @@ sample_subdialog (GtkButton *b, gpointer data) else { text = - widget_printf (gettext(label2), scd->spinbutton1, scd->spinbutton2); + widget_printf (gettext(label2), scd->spin_sample_size, scd->spin_sample_limit); gtk_label_set_text (GTK_LABEL (scd->l0), text); } @@ -206,6 +239,21 @@ range_subdialog (GtkButton *b, gpointer data) } } +/* Ensure that the range "first" and "last" spinbuttons are self consistent */ +static void +consistency (GtkSpinButton *spin, PsppireDialogActionSelect *act) +{ + gdouble first = gtk_spin_button_get_value (GTK_SPIN_BUTTON (act->first)); + gdouble last = gtk_spin_button_get_value (GTK_SPIN_BUTTON (act->last)); + + if (last < first) + { + if (spin == GTK_SPIN_BUTTON (act->first)) + gtk_spin_button_set_value (GTK_SPIN_BUTTON (act->last), first); + if (spin == GTK_SPIN_BUTTON (act->last)) + gtk_spin_button_set_value (GTK_SPIN_BUTTON (act->first), last); + } +} static void psppire_dialog_action_select_activate (PsppireDialogAction *a) @@ -224,10 +272,10 @@ psppire_dialog_action_select_activate (PsppireDialogAction *a) pda->dialog = get_widget_assert (xml, "select-cases-dialog"); pda->source = get_widget_assert (xml, "select-cases-treeview"); - g_object_set (pda->source, + g_object_set (pda->source, "selection-mode", GTK_SELECTION_SINGLE, NULL); - + act->entry = get_widget_assert (xml, "filter-variable-entry"); GtkWidget *selector = get_widget_assert (xml, "psppire-selector-filter"); @@ -247,6 +295,9 @@ psppire_dialog_action_select_activate (PsppireDialogAction *a) act->first = get_widget_assert (xml, "range-dialog-first"); act->last = get_widget_assert (xml, "range-dialog-last"); + g_signal_connect (act->first, "value-changed", G_CALLBACK (consistency), act); + g_signal_connect (act->last, "value-changed", G_CALLBACK (consistency), act); + act->l1 = get_widget_assert (xml, "range-sample-label"); act->radiobutton_sample = get_widget_assert (xml, "radiobutton-sample"); @@ -309,13 +360,11 @@ psppire_dialog_action_select_activate (PsppireDialogAction *a) psppire_dialog_action_set_valid_predicate (pda, dialog_state_valid); - if (PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_select_parent_class)->activate) - PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_select_parent_class)->activate (pda); } static char * -generate_syntax_filter (PsppireDialogAction *a) +generate_syntax_filter (const PsppireDialogAction *a) { PsppireDialogActionSelect *scd = PSPPIRE_DIALOG_ACTION_SELECT (a); @@ -354,9 +403,9 @@ generate_syntax_filter (PsppireDialogAction *a) else { const gint n_cases = - gtk_spin_button_get_value (GTK_SPIN_BUTTON (scd->spinbutton1)); + gtk_spin_button_get_value (GTK_SPIN_BUTTON (scd->spin_sample_size)); const gint from_n_cases = - gtk_spin_button_get_value (GTK_SPIN_BUTTON (scd->spinbutton2)); + gtk_spin_button_get_value (GTK_SPIN_BUTTON (scd->spin_sample_limit)); const gchar ranvar[]="rv_$"; @@ -377,7 +426,7 @@ generate_syntax_filter (PsppireDialogAction *a) filter, ranvar); ds_put_cstr (&dss, "EXECUTE.\n"); - + ds_put_c_format (&dss, "COMPUTE %s = $CASENUM.\n", @@ -419,7 +468,7 @@ generate_syntax_filter (PsppireDialogAction *a) static gchar * -generate_syntax_delete (PsppireDialogAction *a) +generate_syntax_delete (const PsppireDialogAction *a) { PsppireDialogActionSelect *scd = PSPPIRE_DIALOG_ACTION_SELECT (a); gchar *text = NULL; @@ -437,7 +486,7 @@ generate_syntax_delete (PsppireDialogAction *a) (GTK_TOGGLE_BUTTON (scd->radiobutton_sample))) { ds_put_cstr (&dss, "SAMPLE "); - + if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (scd->percent))) { const double percentage = @@ -447,13 +496,13 @@ generate_syntax_delete (PsppireDialogAction *a) else { const gint n_cases = - gtk_spin_button_get_value (GTK_SPIN_BUTTON (scd->spinbutton1)); + gtk_spin_button_get_value (GTK_SPIN_BUTTON (scd->spin_sample_size)); const gint from_n_cases = - gtk_spin_button_get_value (GTK_SPIN_BUTTON (scd->spinbutton2)); - + gtk_spin_button_get_value (GTK_SPIN_BUTTON (scd->spin_sample_limit)); + ds_put_c_format (&dss, "%d FROM %d .", n_cases, from_n_cases); } - + } else if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (scd->radiobutton_range))) @@ -486,7 +535,7 @@ generate_syntax_delete (PsppireDialogAction *a) static gchar * -generate_syntax (PsppireDialogAction *a) +generate_syntax (const PsppireDialogAction *a) { PsppireDialogActionSelect *scd = PSPPIRE_DIALOG_ACTION_SELECT (a); @@ -495,7 +544,7 @@ generate_syntax (PsppireDialogAction *a) { return g_strdup ("FILTER OFF.\n"); } - + /* Are we filtering or deleting ? */ if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (scd->radiobutton_delete))) {