Import Assistant: Fix generation of /DELIMITERS subcommand
authorJohn Darrington <john@darrington.wattle.id.au>
Sat, 20 May 2017 13:24:38 +0000 (15:24 +0200)
committerJohn Darrington <john@darrington.wattle.id.au>
Sat, 20 May 2017 13:24:38 +0000 (15:24 +0200)
src/ui/gui/psppire-import-assistant.c
src/ui/gui/psppire-import-assistant.h

index 9bdac0009f6d76c900e17d8b0d0694aecb190875..51eae36241e49ebe6f1d164e13aad433a32d749c 100644 (file)
@@ -141,7 +141,6 @@ psppire_import_assistant_finalize (GObject *object)
   if (ia->spreadsheet)
     spreadsheet_unref (ia->spreadsheet);
 
-  ds_destroy (&ia->separators);
   ds_destroy (&ia->quotes);
 
   g_object_unref (ia->builder);
@@ -195,13 +194,16 @@ revise_fields_preview (PsppireImportAssistant *ia)
 {
   push_watch_cursor (ia);
 
-  get_separators (ia);
+  //  get_separators (ia);
   //  split_fields (ia);
   choose_column_names (ia);
 
   pop_watch_cursor (ia);
 }
 
+
+#if SHEET_MERGE
+
 /* Chooses the most common character among those in TARGETS,
    based on the frequency data in HISTOGRAM, and stores it in
    RESULT.  If there is a tie for the most common character among
@@ -264,6 +266,7 @@ choose_likely_separators (PsppireImportAssistant *ia)
   find_commonest_chars (histogram, ",;:/|!\t-", ",", &ia->separators);
 }
 
+#endif
 
 static void set_separators (PsppireImportAssistant *ia);
 
@@ -347,8 +350,8 @@ prepare_separators_page (PsppireImportAssistant *ia, GtkWidget *page)
   repopulate_delimiter_columns (ia);
 
   revise_fields_preview (ia);
-  choose_likely_separators (ia);
-  set_separators (ia);
+  //  choose_likely_separators (ia);
+  //  set_separators (ia);
 }
 
 struct separator
@@ -373,6 +376,7 @@ static const struct separator separators[] =
 #define SEPARATOR_CNT (sizeof separators / sizeof *separators)
 
 
+#if SHEET_MERGE
 
 /* Sets the widgets to match IA's separators substructure. */
 static void
@@ -428,6 +432,7 @@ set_separators (PsppireImportAssistant *ia)
   gtk_widget_set_sensitive (ia->quote_combo, any_quotes);
 }
 
+#endif
 
 /* Resets IA's intro page to its initial state. */
 static void
@@ -1466,7 +1471,7 @@ set_quote_list (GtkComboBox *cb)
 }
 
 
-
+#if SHEET_MERGE
 
 /* Sets IA's separators substructure to match the widgets. */
 static void
@@ -1499,7 +1504,7 @@ get_separators (PsppireImportAssistant *ia)
 
 
 
-#if SHEET_MERGE
+
 
 /* Breaks the file data in IA into columns based on the
    separators set in IA's separators substructure. */
@@ -1991,25 +1996,28 @@ static void
 separators_append_syntax (const PsppireImportAssistant *ia, struct string *s)
 {
   int i;
+
   ds_put_cstr (s, "  /DELIMITERS=\"");
-  if (ds_find_byte (&ia->separators, '\t') != SIZE_MAX)
+
+  if (gtk_toggle_button_get_active (get_widget_assert (ia->builder, "tab")))
     ds_put_cstr (s, "\\t");
-  if (ds_find_byte (&ia->separators, '\\') != SIZE_MAX)
-    ds_put_cstr (s, "\\\\");
-  for (i = 0; i < ds_length (&ia->separators); i++)
+  for (i = 0; i < SEPARATOR_CNT; i++)
     {
-      char c = ds_at (&ia->separators, i);
-      if (c == '"')
-       ds_put_cstr (s, "\"\"");
-      else if (c != '\t' && c != '\\')
-       ds_put_byte (s, c);
+      const struct separator *seps = &separators[i];
+      GtkWidget *button = get_widget_assert (ia->builder, seps->name);
+      if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
+       {
+         if (seps->c == '\t')
+           continue;
+
+         ds_put_byte (s, seps->c);
+       }
     }
   ds_put_cstr (s, "\"\n");
   if (!ds_is_empty (&ia->quotes))
     syntax_gen_pspp (s, "  /QUALIFIER=%sq\n", ds_cstr (&ia->quotes));
 }
 
-
 static void
 formats_append_syntax (const PsppireImportAssistant *ia, struct string *s)
 {
index 853db8eb458abb062e013ea6a1946706bc3fcd7a..60a771dbc4cf933cfc0e10fbecb461b7a28d15e9 100644 (file)
@@ -89,13 +89,14 @@ struct _PsppireImportAssistant
 /* START Page where the user chooses field separators. */
 
   /* How to break lines into columns. */
-  struct string separators;   /* Field separators. */
+  //  struct string separators;   /* Field separators. */
   struct string quotes;       /* Quote characters. */
 
   GtkWidget *custom_cb;
   GtkWidget *custom_entry;
   GtkWidget *quote_cb;
   GtkWidget *quote_combo;
+
   GtkEntry *quote_entry;
   GtkWidget *fields_tree_view;