Move column count from seperators into assist
authorJohn Darrington <john@darrington.wattle.id.au>
Thu, 24 Jan 2013 17:58:30 +0000 (18:58 +0100)
committerJohn Darrington <john@darrington.wattle.id.au>
Sat, 16 Feb 2013 14:03:23 +0000 (15:03 +0100)
src/ui/gui/page-formats.c
src/ui/gui/page-separators.c
src/ui/gui/page-sheet-spec.c
src/ui/gui/text-data-import-dialog.c
src/ui/gui/text-data-import-dialog.h

index 25d070276b75d67bc8e9239a73e889823ca665b6..3edb9e1439c2ae386089c6e61ea83aa15da3116b 100644 (file)
@@ -114,8 +114,7 @@ prepare_formats_page (struct import_assistant *ia)
 
   dict = dict_create (get_default_encoding ());
   fg = fmt_guesser_create ();
-  printf ("%s:%d Column count %d\n", __FILE__, __LINE__, seps->column_cnt);
-  for (column_idx = 0; column_idx < seps->column_cnt; column_idx++)
+  for (column_idx = 0; column_idx < ia->column_cnt; column_idx++)
     {
       struct variable *modified_var;
 
@@ -123,7 +122,7 @@ prepare_formats_page (struct import_assistant *ia)
                       ? p->modified_vars[column_idx] : NULL);
       if (modified_var == NULL)
         {
-          struct column *column = &seps->columns[column_idx];
+          struct column *column = &ia->columns[column_idx];
           struct variable *var;
           struct fmt_spec format;
           char *name;
index 40a6e71959a33d49d2ac8fe3409f47f3da8ca523..d16f0fe3d21c20992e481f7220b2dca889abed36 100644 (file)
@@ -199,9 +199,7 @@ reset_separators_page (struct import_assistant *ia)
 static void
 clear_fields (struct import_assistant *ia)
 {
-  struct separators_page *s = ia->separators;
-
-  if (s->column_cnt > 0)
+  if (ia->column_cnt > 0)
     {
       struct column *col;
       size_t row;
@@ -212,7 +210,7 @@ clear_fields (struct import_assistant *ia)
           const char *line_start = ds_data (line);
           const char *line_end = ds_end (line);
 
-          for (col = s->columns; col < &s->columns[s->column_cnt]; col++)
+          for (col = ia->columns; col < &ia->columns[ia->column_cnt]; col++)
             {
               char *s = ss_data (col->contents[row]);
               if (!(s >= line_start && s <= line_end))
@@ -220,15 +218,15 @@ clear_fields (struct import_assistant *ia)
             }
         }
 
-      for (col = s->columns; col < &s->columns[s->column_cnt]; col++)
+      for (col = ia->columns; col < &ia->columns[ia->column_cnt]; col++)
         {
           free (col->name);
           free (col->contents);
         }
 
-      free (s->columns);
-      s->columns = NULL;
-      s->column_cnt = 0;
+      free (ia->columns);
+      ia->columns = NULL;
+      ia->column_cnt = 0;
     }
 }
 
@@ -297,20 +295,20 @@ split_fields (struct import_assistant *ia)
             ss_get_bytes (&text, ss_cspan (text, ds_ss (&s->separators)),
                           &field);
 
-          if (column_idx >= s->column_cnt)
+          if (column_idx >= ia->column_cnt)
             {
               struct column *column;
 
-              if (s->column_cnt >= columns_allocated)
-                s->columns = x2nrealloc (s->columns, &columns_allocated,
-                                         sizeof *s->columns);
-              column = &s->columns[s->column_cnt++];
+              if (ia->column_cnt >= columns_allocated)
+                ia->columns = x2nrealloc (ia->columns, &columns_allocated,
+                                         sizeof *ia->columns);
+              column = &ia->columns[ia->column_cnt++];
               column->name = NULL;
               column->width = 0;
               column->contents = xcalloc (ia->file.line_cnt,
                                           sizeof *column->contents);
             }
-          column = &s->columns[column_idx];
+          column = &ia->columns[column_idx];
           column->contents[row] = field;
           if (ss_length (field) > column->width)
             column->width = ss_length (field);
@@ -339,7 +337,7 @@ choose_column_names (struct import_assistant *ia)
 
   dict = dict_create (get_default_encoding ());
   name_row = f->variable_names && f->skip_lines ? f->skip_lines : 0;
-  for (col = s->columns; col < &s->columns[s->column_cnt]; col++)
+  for (col = ia->columns; col < &ia->columns[ia->column_cnt]; col++)
     {
       char *hint, *name;
 
index 74593f2523112619a9a1482b2401543fa2f4c8fa..6f6695f51b7f06bda51292ea0fc44b99be721b5a 100644 (file)
@@ -207,7 +207,6 @@ update_assistant (struct import_assistant *ia)
 {
   struct sheet_spec_page *ssp = ia->sheet_spec;
   //  struct file *file = &ia->file;
-  struct separators_page *sepp = ia->separators;
   int rows = 0;
 
 
@@ -216,30 +215,30 @@ update_assistant (struct import_assistant *ia)
       struct ccase *c;
       int col;
 
-      sepp->column_cnt = dict_get_var_cnt (ssp->dict);
-      sepp->columns = xcalloc (sepp->column_cnt, sizeof (*sepp->columns));
-      for (col = 0; col < sepp->column_cnt ; ++col)
+      ia->column_cnt = dict_get_var_cnt (ssp->dict);
+      ia->columns = xcalloc (ia->column_cnt, sizeof (*ia->columns));
+      for (col = 0; col < ia->column_cnt ; ++col)
        {
          const struct variable *var = dict_get_var (ssp->dict, col);
-         sepp->columns[col].name = xstrdup (var_get_name (var));
-         sepp->columns[col].contents = NULL;
+         ia->columns[col].name = xstrdup (var_get_name (var));
+         ia->columns[col].contents = NULL;
        }
 
       for (; (c = casereader_read (ssp->reader)) != NULL; case_unref (c))
        {
          rows++;
-         for (col = 0; col < sepp->column_cnt ; ++col)
+         for (col = 0; col < ia->column_cnt ; ++col)
            {
              char *ss;
              const struct variable *var = dict_get_var (ssp->dict, col);
 
-             sepp->columns[col].contents = xrealloc (sepp->columns[col].contents,
+             ia->columns[col].contents = xrealloc (ia->columns[col].contents,
                                                      sizeof (struct substring) * rows);
 
              ss = data_out (case_data (c, var), dict_get_encoding (ssp->dict), 
                             var_get_print_format (var));
 
-             sepp->columns[col].contents[rows - 1] = ss_cstr (ss);
+             ia->columns[col].contents[rows - 1] = ss_cstr (ss);
            }
 
          if (rows > MAX_PREVIEW_LINES)
index c9cee751915f773f0b291fc285f23eee1eef5cfc..fc1485ff8abfb161be681747b91c8d7fa508af39 100644 (file)
@@ -200,8 +200,6 @@ apply_dict (const struct dictionary *dict, struct string *s)
 static char *
 generate_syntax (const struct import_assistant *ia)
 {
-  struct sheet_spec_page *ssp = ia->sheet_spec;
-
   struct string s = DS_EMPTY_INITIALIZER;
 
 #if 0
@@ -323,7 +321,7 @@ render_input_cell (GtkTreeViewColumn *tree_column, GtkCellRenderer *cell,
   column = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (tree_column),
                                                "column-number"));
   row = empty_list_store_iter_to_row (iter) + ia->first_line->skip_lines;
-  field = ia->separators->columns[column].contents[row];
+  field = ia->columns[column].contents[row];
   if (field.string != NULL)
     {
       GValue text = {0, };
@@ -359,7 +357,7 @@ on_query_input_tooltip (GtkWidget *widget, gint wx, gint wy,
   if (!get_tooltip_location (widget, wx, wy, ia, &row, &column))
     return FALSE;
 
-  if (ia->separators->columns[column].contents[row].string != NULL)
+  if (ia->columns[column].contents[row].string != NULL)
     return FALSE;
 
   gtk_tooltip_set_text (tooltip,
@@ -389,7 +387,7 @@ parse_field (struct import_assistant *ia,
   char *tooltip;
   bool ok;
 
-  field = ia->separators->columns[column].contents[row];
+  field = ia->columns[column].contents[row];
   var = dict_get_var (ia->formats->dict, column);
   value_init (&val, var_get_width (var));
   in = var_get_print_format (var);
@@ -625,7 +623,7 @@ make_data_column (struct import_assistant *ia, GtkTreeView *tree_view,
   char *name;
 
   if (input)
-    column = &ia->separators->columns[dict_idx];
+    column = &ia->columns[dict_idx];
   else
     var = dict_get_var (ia->formats->dict, dict_idx);
 
@@ -665,7 +663,7 @@ create_data_tree_view (bool input, GtkContainer *parent,
   gtk_tree_selection_set_mode (gtk_tree_view_get_selection (tree_view),
                                GTK_SELECTION_NONE);
 
-  for (i = 0; i < ia->separators->column_cnt; i++)
+  for (i = 0; i < ia->column_cnt; i++)
     gtk_tree_view_append_column (tree_view,
                                  make_data_column (ia, tree_view, input, i));
 
index be8c46e92d13b94ef1f05551d7044f5c4057e364..29d4ab9bd30dc24c568c98c27ebac6967c4c9ae8 100644 (file)
@@ -54,6 +54,7 @@ struct assistant
 
     GtkCellRenderer *prop_renderer;
     GtkCellRenderer *fixed_renderer;
+
   };
 
 
@@ -78,10 +79,6 @@ struct separators_page
     struct string quotes;       /* Quote characters. */
     bool escape;                /* Doubled quotes yield a quote mark? */
 
-    /* The columns produced thereby. */
-    struct column *columns;     /* Information about each column. */
-    size_t column_cnt;          /* Number of columns. */
-
     GtkWidget *page;
     GtkWidget *custom_cb;
     GtkWidget *custom_entry;
@@ -115,6 +112,10 @@ struct import_assistant
     struct first_line_page *first_line;
     struct separators_page *separators;
     struct formats_page *formats;
+
+    /* The columns produced. */
+    struct column *columns;     /* Information about each column. */
+    size_t column_cnt;          /* Number of columns. */
   };