Added the proper quotation marks in the syntax generator when the groups
[pspp-builds.git] / src / ui / gui / t-test-independent-samples-dialog.c
index 1468bd01b363d954bb72218fb90a49fc823a1b46..5b3d98f7855139e0d231d34873331d46838e216a 100644 (file)
@@ -16,6 +16,7 @@
 */
 
 
+#include <config.h>
 #include <glade/glade.h>
 #include <gtk/gtk.h>
 #include "t-test-independent-samples-dialog.h"
@@ -28,6 +29,8 @@
 #include "dialog-common.h"
 #include "dict-display.h"
 #include "widget-io.h"
+#include "t-test-options.h"
+#include <libpspp/syntax-gen.h>
 
 #include <language/syntax-string-source.h>
 #include "syntax-editor.h"
@@ -43,14 +46,15 @@ struct tt_indep_samples_dialog
   GtkWidget *dialog;
   PsppireDict *dict;
   gboolean groups_defined;
-  gboolean non_default_options;
-  gdouble confidence_interval;
+
+  struct tt_options_dialog *opts;
 };
 
 
 static gchar *
 generate_syntax (const struct tt_indep_samples_dialog *d)
 {
+  struct variable *group_variable;
   gchar *text;
   GtkWidget *entry =
     get_widget_assert (d->xml, "indep-samples-t-test-entry");
@@ -64,35 +68,50 @@ generate_syntax (const struct tt_indep_samples_dialog *d)
 
   g_string_append (str, "\n\t/GROUPS=");
 
-  g_string_append (str, gtk_entry_get_text (GTK_ENTRY (entry)));
+  group_variable =
+    psppire_dict_lookup_var (d->dict, gtk_entry_get_text (GTK_ENTRY (entry)));
+
+  g_string_append (str, var_get_name (group_variable));
 
   if ( d->groups_defined )
     {
       GtkWidget *entry1 = get_widget_assert (d->xml, "group1-entry");
       GtkWidget *entry2 = get_widget_assert (d->xml, "group2-entry");
 
+      const gchar *val1 = gtk_entry_get_text (GTK_ENTRY (entry1));
+      const gchar *val2 = gtk_entry_get_text (GTK_ENTRY (entry2));
+
       g_string_append (str, "(");
-      g_string_append (str, gtk_entry_get_text (GTK_ENTRY (entry1)));
+      if ( var_is_alpha (group_variable))
+       {
+         struct string s;
+         ds_init_cstr (&s, val1);
+         gen_quoted_string (&s);
+         g_string_append (str, ds_cstr (&s));
+         ds_destroy (&s);
+       }
+      else
+       {
+         g_string_append (str, val1);
+       }
       g_string_append (str, ",");
-      g_string_append (str, gtk_entry_get_text (GTK_ENTRY (entry2)));
+      if ( var_is_alpha (group_variable))
+       {
+         struct string s;
+         ds_init_cstr (&s, val2);
+         gen_quoted_string (&s);
+         g_string_append (str, ds_cstr (&s));
+         ds_destroy (&s);
+       }
+      else
+       {
+         g_string_append (str, val2);
+       }
       g_string_append (str, ")");
     }
 
-  if ( d->non_default_options )
-    {
-      GtkToggleButton *analysis =
-       GTK_TOGGLE_BUTTON (get_widget_assert (d->xml, "radiobutton1"));
-
-      g_string_append (str, "\n\t");
-      g_string_append_printf (str, "/CRITERIA=CIN(%g)",
-                             d->confidence_interval/100.0);
-
 
-      g_string_append (str, "\n\t");
-      g_string_append_printf (str, "/MISSING=%s",
-                      gtk_toggle_button_get_active (analysis) ?
-                      "ANALYSIS" : "LISTWISE");
-    }
+  tt_options_dialog_append_syntax (d->opts, str);
 
   g_string_append (str, ".\n");
 
@@ -158,43 +177,6 @@ run_define_groups (struct tt_indep_samples_dialog *ttd)
 }
 
 
-static void
-run_options (struct tt_indep_samples_dialog *ttd)
-{
-  gint response;
-  GtkWidget *dialog =
-    get_widget_assert (ttd->xml, "options-dialog");
-
-  GtkWidget *box =
-    get_widget_assert (ttd->xml, "vbox1");
-
-  GtkSpinButton *conf_percent = NULL;
-
-  GtkWidget *confidence =
-    widget_scanf (_("Confidence Interval: %2d %%"),
-                 &conf_percent);
-
-  gtk_spin_button_set_value (conf_percent, ttd->confidence_interval);
-
-  gtk_widget_show (confidence);
-
-  gtk_box_pack_start_defaults (GTK_BOX (box), confidence);
-
-  gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (ttd->dialog));
-
-  response = psppire_dialog_run (PSPPIRE_DIALOG (dialog));
-
-  if ( response == PSPPIRE_RESPONSE_CONTINUE)
-    {
-      ttd->non_default_options = TRUE;
-      ttd->confidence_interval = gtk_spin_button_get_value (conf_percent);
-    }
-
-  gtk_container_remove (GTK_CONTAINER (box), confidence);
-}
-
-
-
 
 static gboolean
 dialog_state_valid (gpointer data)
@@ -234,9 +216,6 @@ t_test_independent_samples_dialog (GObject *o, gpointer data)
 
   GladeXML *xml = XML_NEW ("t-test.glade");
 
-  tt_d.dialog = get_widget_assert (xml,
-                                        "t-test-independent-samples-dialog");
-
   GtkSheet *var_sheet =
     GTK_SHEET (get_widget_assert (de->xml, "variable_sheet"));
 
@@ -252,7 +231,6 @@ t_test_independent_samples_dialog (GObject *o, gpointer data)
   GtkWidget *selector1 =
     get_widget_assert (xml, "indep-samples-t-test-selector1");
 
-
   GtkWidget *entry =
     get_widget_assert (xml, "indep-samples-t-test-entry");
 
@@ -264,11 +242,11 @@ t_test_independent_samples_dialog (GObject *o, gpointer data)
 
   vs = PSPPIRE_VAR_STORE (gtk_sheet_get_model (var_sheet));
 
+  tt_d.dialog = get_widget_assert (xml, "t-test-independent-samples-dialog");
   tt_d.xml = xml;
   tt_d.dict = vs->dict;
   tt_d.groups_defined = FALSE;
-  tt_d.non_default_options = FALSE;
-  tt_d.confidence_interval = 95.0;
+  tt_d.opts = tt_options_dialog_create (xml, de->parent.window);
 
   gtk_window_set_transient_for (GTK_WINDOW (tt_d.dialog), de->parent.window);
 
@@ -295,7 +273,7 @@ t_test_independent_samples_dialog (GObject *o, gpointer data)
 
 
   g_signal_connect_swapped (options_button, "clicked",
-                           G_CALLBACK (run_options), &tt_d);
+                           G_CALLBACK (tt_options_dialog_run), tt_d.opts);
 
 
   g_signal_connect_swapped (tt_d.dialog, "refresh", G_CALLBACK (refresh),  xml);
@@ -333,7 +311,7 @@ t_test_independent_samples_dialog (GObject *o, gpointer data)
       break;
     }
 
-
+  tt_options_dialog_destroy (tt_d.opts);
   g_object_unref (xml);
 }