First line page construction is initialisation
authorJohn Darrington <john@darrington.wattle.id.au>
Thu, 24 Jan 2013 18:33:59 +0000 (19:33 +0100)
committerJohn Darrington <john@darrington.wattle.id.au>
Sat, 16 Feb 2013 14:03:27 +0000 (15:03 +0100)
src/ui/gui/page-assistant.c
src/ui/gui/page-first-line.c
src/ui/gui/page-formats.c
src/ui/gui/page-separators.c
src/ui/gui/text-data-import-dialog.c
src/ui/gui/text-data-import-dialog.h

index f6ca9e8d10a57dcd003b7c1e62c05133349e7dea..480133046e63897d5b9564289276ceadc33928ac 100644 (file)
@@ -82,10 +82,21 @@ init_assistant (GtkWindow *parent_window)
   ia->intro = intro_page_create (ia);
   ia->separators = separators_page_create (ia);
 
-  ia->first_line = xzalloc (sizeof *ia->first_line);
+
+  a->prop_renderer = gtk_cell_renderer_text_new ();
+  g_object_ref_sink (a->prop_renderer);
+  a->fixed_renderer = gtk_cell_renderer_text_new ();
+  g_object_ref_sink (a->fixed_renderer);
+  g_object_set (G_OBJECT (a->fixed_renderer),
+                "family", "Monospace",
+                (void *) NULL);
+
+  ia->first_line = first_line_page_create (ia);
+
   ia->formats = xzalloc (sizeof *ia->formats);
 
 
+
   g_signal_connect (a->assistant, "prepare", G_CALLBACK (on_prepare), ia);
   g_signal_connect (a->assistant, "cancel", G_CALLBACK (on_cancel), ia);
   g_signal_connect (a->assistant, "close", G_CALLBACK (on_close), ia);
@@ -100,14 +111,6 @@ init_assistant (GtkWindow *parent_window)
   gtk_window_set_transient_for (GTK_WINDOW (a->assistant), parent_window);
   gtk_window_set_icon_name (GTK_WINDOW (a->assistant), "pspp");
 
-  a->prop_renderer = gtk_cell_renderer_text_new ();
-  g_object_ref_sink (a->prop_renderer);
-  a->fixed_renderer = gtk_cell_renderer_text_new ();
-  g_object_ref_sink (a->fixed_renderer);
-  g_object_set (G_OBJECT (a->fixed_renderer),
-                "family", "Monospace",
-                (void *) NULL);
-
   return ia;
 }
 
index 8f61b2efda530eb71e0850e7b04d7e29c759676a..9865d90c38c71b04b30dce202bf34e0f2df87d35 100644 (file)
 #define N_(msgid) msgid
 
 
+
 /* The "first line" page of the assistant. */
 
+/* Page where the user chooses the first line of data. */
+struct first_line_page
+  {
+    GtkWidget *page;
+    GtkTreeView *tree_view;
+    GtkWidget *variable_names_cb;
+  };
+
 static GtkTreeView *create_lines_tree_view (GtkContainer *parent_window,
                                             struct import_assistant *);
 static void on_first_line_change (GtkTreeSelection *,
@@ -71,10 +80,11 @@ static void set_first_line (struct import_assistant *);
 static void get_first_line (struct import_assistant *);
 
 /* Initializes IA's first_line substructure. */
-void
-init_first_line_page (struct import_assistant *ia)
+struct first_line_page *
+first_line_page_create (struct import_assistant *ia)
 {
-  struct first_line_page *p = ia->first_line;
+  struct first_line_page *p = xzalloc (sizeof *p);
+
   GtkBuilder *builder = ia->asst.builder;
 
   p->page = add_page_to_assistant (ia, get_widget_assert (builder, "FirstLine"),
@@ -86,19 +96,19 @@ init_first_line_page (struct import_assistant *ia)
   gtk_tree_selection_set_mode (
     gtk_tree_view_get_selection (GTK_TREE_VIEW (p->tree_view)),
     GTK_SELECTION_BROWSE);
-  set_first_line (ia);
   g_signal_connect (gtk_tree_view_get_selection (GTK_TREE_VIEW (p->tree_view)),
                     "changed", G_CALLBACK (on_first_line_change), ia);
   g_signal_connect (p->variable_names_cb, "toggled",
                     G_CALLBACK (on_variable_names_cb_toggle), ia);
+  return p;
 }
 
 /* Resets the first_line page to its initial content. */
 void
 reset_first_line_page (struct import_assistant *ia)
 {
-  ia->first_line->skip_lines = 0;
-  ia->first_line->variable_names = false;
+  ia->skip_lines = 0;
+  ia->variable_names = false;
   set_first_line (ia);
 }
 
@@ -124,7 +134,7 @@ render_line (GtkTreeViewColumn *tree_column,
 static GtkTreeView *
 create_lines_tree_view (GtkContainer *parent, struct import_assistant *ia)
 {
-  GtkTreeView *tree_view;
+  GtkTreeView *tree_view = NULL;
   GtkTreeViewColumn *column;
   size_t max_line_length;
   gint content_width, header_width;
@@ -185,16 +195,16 @@ set_first_line (struct import_assistant *ia)
 {
   GtkTreePath *path;
 
-  path = gtk_tree_path_new_from_indices (ia->first_line->skip_lines, -1);
+  path = gtk_tree_path_new_from_indices (ia->skip_lines, -1);
   gtk_tree_view_set_cursor (GTK_TREE_VIEW (ia->first_line->tree_view),
                             path, NULL, false);
   gtk_tree_path_free (path);
 
   gtk_toggle_button_set_active (
     GTK_TOGGLE_BUTTON (ia->first_line->variable_names_cb),
-    ia->first_line->variable_names);
+    ia->variable_names);
   gtk_widget_set_sensitive (ia->first_line->variable_names_cb,
-                            ia->first_line->skip_lines > 0);
+                            ia->skip_lines > 0);
 }
 
 /* Sets IA's first_line substructure to match the widgets. */
@@ -212,12 +222,12 @@ get_first_line (struct import_assistant *ia)
       int row = gtk_tree_path_get_indices (path)[0];
       gtk_tree_path_free (path);
 
-      ia->first_line->skip_lines = row;
-      ia->first_line->variable_names =
-        (ia->first_line->skip_lines > 0
+      ia->skip_lines = row;
+      ia->variable_names =
+        (ia->skip_lines > 0
          && gtk_toggle_button_get_active (
            GTK_TOGGLE_BUTTON (ia->first_line->variable_names_cb)));
     }
   gtk_widget_set_sensitive (ia->first_line->variable_names_cb,
-                            ia->first_line->skip_lines > 0);
+                            ia->skip_lines > 0);
 }
index 3edb9e1439c2ae386089c6e61ea83aa15da3116b..3a3df83a043dc560f5229fa799ff75babc1a92b3 100644 (file)
@@ -133,7 +133,7 @@ prepare_formats_page (struct import_assistant *ia)
 
           /* Choose variable format. */
           fmt_guesser_clear (fg);
-          for (row = ia->first_line->skip_lines; row < ia->file.line_cnt; row++)
+          for (row = ia->skip_lines; row < ia->file.line_cnt; row++)
             fmt_guesser_add (fg, column->contents[row]);
           fmt_guesser_guess (fg, &format);
           fmt_fix_input (&format);
index 999950bcaf45f8d13213c148b9a5eb589344d78c..c62c3bb767d25ce81b32acee20fda8f5195ce243 100644 (file)
@@ -347,14 +347,13 @@ split_fields (struct import_assistant *ia)
 static void
 choose_column_names (struct import_assistant *ia)
 {
-  const struct first_line_page *f = ia->first_line;
   struct dictionary *dict;
   unsigned long int generated_name_count = 0;
   struct column *col;
   size_t name_row;
 
   dict = dict_create (get_default_encoding ());
-  name_row = f->variable_names && f->skip_lines ? f->skip_lines : 0;
+  name_row = ia->variable_names && ia->skip_lines ? ia->skip_lines : 0;
   for (col = ia->columns; col < &ia->columns[ia->column_cnt]; col++)
     {
       char *hint, *name;
index 6e978a3940a52541e79ca2ec6ed8d8e93419dc06..6d41b0f9c9800a15b9c79329008c50732f792136 100644 (file)
@@ -81,7 +81,6 @@ text_data_import_assistant (PsppireDataWindow *dw)
     }
 
   ssp = ia->sheet_spec;
-  init_first_line_page (ia);
 
   init_formats_page (ia);
 
@@ -319,7 +318,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;
+  row = empty_list_store_iter_to_row (iter) + ia->skip_lines;
   field = ia->columns[column].contents[row];
   if (field.string != NULL)
     {
@@ -443,7 +442,7 @@ render_output_cell (GtkTreeViewColumn *tree_column,
 
   ok = parse_field (ia,
                     (empty_list_store_iter_to_row (iter)
-                     + ia->first_line->skip_lines),
+                     + ia->skip_lines),
                     GPOINTER_TO_INT (g_object_get_data (G_OBJECT (tree_column),
                                                         "column-number")),
                     &output, NULL);
@@ -526,7 +525,7 @@ get_tooltip_location (GtkWidget *widget, gint wx, gint wy,
   if (!ok)
     return FALSE;
 
-  *row = empty_list_store_iter_to_row (&iter) + ia->first_line->skip_lines;
+  *row = empty_list_store_iter_to_row (&iter) + ia->skip_lines;
   return TRUE;
 }
 
@@ -658,7 +657,7 @@ create_data_tree_view (bool input, GtkContainer *parent,
   GtkTreeView *tree_view;
   gint i;
 
-  make_tree_view (ia, ia->first_line->skip_lines, &tree_view);
+  make_tree_view (ia, ia->skip_lines, &tree_view);
   gtk_tree_selection_set_mode (gtk_tree_view_get_selection (tree_view),
                                GTK_SELECTION_NONE);
 
index a0f2a1a797a2f7e67c541a3ebd341187d078c8f9..60dced703d29a34705c4dfb06815cbc6ddbcfab6 100644 (file)
@@ -59,18 +59,6 @@ struct assistant
 
 
 
-/* Page where the user chooses the first line of data. */
-struct first_line_page
-  {
-    int skip_lines;    /* Number of initial lines to skip? */
-    bool variable_names; /* Variable names above first line of data? */
-
-    GtkWidget *page;
-    GtkTreeView *tree_view;
-    GtkWidget *variable_names_cb;
-  };
-
-
 /* Page where the user verifies and adjusts input formats. */
 struct formats_page
   {
@@ -98,6 +86,9 @@ struct import_assistant
     /* The columns produced. */
     struct column *columns;     /* Information about each column. */
     size_t column_cnt;          /* Number of columns. */
+
+    int skip_lines;             /* Number of initial lines to skip? */
+    bool variable_names;        /* Variable names above first line of data? */
   };
 
 
@@ -162,8 +153,6 @@ void  update_assistant (struct import_assistant *ia);
 bool init_file (struct import_assistant *ia, GtkWindow *parent_window);
 void destroy_file (struct import_assistant *ia);
 
-
-void init_sheet_spec_page (struct import_assistant *);
 void prepare_sheet_spec_page (struct import_assistant *ia);
 void reset_sheet_spec_page (struct import_assistant *);
 void post_sheet_spec_page (struct import_assistant *ia);
@@ -172,7 +161,6 @@ void init_first_line_page (struct import_assistant *ia);
 void prepare_first_line_page (struct import_assistant *ia);
 void reset_first_line_page (struct import_assistant *);
 
-void init_separators_page (struct import_assistant *ia);
 void prepare_separators_page (struct import_assistant *ia);
 void reset_separators_page (struct import_assistant *);
 void destroy_separators_page (struct import_assistant *ia);