formats page: Construction is initialisation
authorJohn Darrington <john@darrington.wattle.id.au>
Thu, 24 Jan 2013 18:58:51 +0000 (19:58 +0100)
committerJohn Darrington <john@darrington.wattle.id.au>
Sat, 16 Feb 2013 14:03:29 +0000 (15:03 +0100)
src/ui/gui/page-assistant.c
src/ui/gui/page-formats.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 480133046e63897d5b9564289276ceadc33928ac..dfe7748b140f22dd55d0df706802f85a600cd0a3 100644 (file)
@@ -93,9 +93,7 @@ init_assistant (GtkWindow *parent_window)
 
   ia->first_line = first_line_page_create (ia);
 
-  ia->formats = xzalloc (sizeof *ia->formats);
-
-
+  ia->formats = formats_page_create (ia);
 
   g_signal_connect (a->assistant, "prepare", G_CALLBACK (on_prepare), ia);
   g_signal_connect (a->assistant, "cancel", G_CALLBACK (on_cancel), ia);
@@ -190,13 +188,15 @@ on_prepare (GtkAssistant *assistant, GtkWidget *page,
     }
 
 
-#endif
+
   
   gtk_widget_show (ia->asst.reset_button);
   if (page == ia->formats->page)
     gtk_widget_show (ia->asst.paste_button);
   else
     gtk_widget_hide (ia->asst.paste_button);
+
+#endif
 }
 
 /* Called when the Cancel button in the assistant is clicked. */
index 3a3df83a043dc560f5229fa799ff75babc1a92b3..9bce4d3204ceb7260cef7e9388aca05cbf194f02 100644 (file)
 #define _(msgid) gettext (msgid)
 #define N_(msgid) msgid
 
+/* Page where the user verifies and adjusts input formats. */
+struct formats_page
+  {
+    GtkWidget *page;
+    GtkTreeView *data_tree_view;
+    PsppireDict *psppire_dict;
+    struct variable **modified_vars;
+    size_t modified_var_cnt;
+  };
+
 /* The "formats" page of the assistant. */
 
 static void on_variable_change (PsppireDict *dict, int idx,
@@ -65,18 +75,20 @@ static void on_variable_change (PsppireDict *dict, int idx,
 static void clear_modified_vars (struct import_assistant *);
 
 /* Initializes IA's formats substructure. */
-void
-init_formats_page (struct import_assistant *ia)
+
+struct formats_page *
+formats_page_create (struct import_assistant *ia)
 {
   GtkBuilder *builder = ia->asst.builder;
-  struct formats_page *p = ia->formats;
+  struct formats_page *p = xzalloc (sizeof *p);
 
   p->page = add_page_to_assistant (ia, get_widget_assert (builder, "Formats"),
                                    GTK_ASSISTANT_PAGE_CONFIRM);
   p->data_tree_view = GTK_TREE_VIEW (get_widget_assert (builder, "data"));
   p->modified_vars = NULL;
   p->modified_var_cnt = 0;
-  p->dict = NULL;
+
+  return p;
 }
 
 /* Frees IA's formats substructure. */
@@ -159,7 +171,7 @@ prepare_formats_page (struct import_assistant *ia)
   psppire_dict = psppire_dict_new_from_dict (dict);
   g_signal_connect (psppire_dict, "variable_changed",
                     G_CALLBACK (on_variable_change), ia);
-  ia->formats->dict = dict;
+  ia->dict = dict;
   ia->formats->psppire_dict = psppire_dict;
 
   /* XXX: PsppireVarStore doesn't hold a reference to
index 6f6695f51b7f06bda51292ea0fc44b99be721b5a..84de6a86c9be6a3da5c4b5ddb1a03254195d85e4 100644 (file)
@@ -53,6 +53,8 @@
 #include "ui/gui/psppire-scanf.h"
 #include "ui/syntax-gen.h"
 
+#include <data/casereader.h>
+
 #include "gl/error.h"
 #include "gl/intprops.h"
 #include "gl/xalloc.h"
@@ -64,6 +66,7 @@
 struct import_assistant;
 
 
+
 /* The "sheet-spec" page of the assistant. */
 
 /* The sheet_spec page of the assistant (only relevant for spreadsheet imports). */
@@ -206,7 +209,6 @@ void
 update_assistant (struct import_assistant *ia)
 {
   struct sheet_spec_page *ssp = ia->sheet_spec;
-  //  struct file *file = &ia->file;
   int rows = 0;
 
 
index 6d41b0f9c9800a15b9c79329008c50732f792136..0d66e8a20ea81e60324e005beb531e99f457cee1 100644 (file)
@@ -82,8 +82,6 @@ text_data_import_assistant (PsppireDataWindow *dw)
 
   ssp = ia->sheet_spec;
 
-  init_formats_page (ia);
-
   gtk_widget_show_all (GTK_WIDGET (ia->asst.assistant));
 
   ia->asst.main_loop = g_main_loop_new (NULL, false);
@@ -377,16 +375,15 @@ parse_field (struct import_assistant *ia,
              size_t row, size_t column,
              char **outputp, char **tooltipp)
 {
-  struct substring field;
-  union value val;
-  struct variable *var;
   const struct fmt_spec *in;
   struct fmt_spec out;
   char *tooltip;
   bool ok;
 
-  field = ia->columns[column].contents[row];
-  var = dict_get_var (ia->formats->dict, column);
+  struct substring field = ia->columns[column].contents[row];
+  struct variable *var = dict_get_var (ia->dict, column);
+  union value val;
+
   value_init (&val, var_get_width (var));
   in = var_get_print_format (var);
   out = fmt_for_output_from_input (in);
@@ -396,7 +393,7 @@ parse_field (struct import_assistant *ia,
       char *error;
 
       error = data_in (field, "UTF-8", in->type, &val, var_get_width (var),
-                       dict_get_encoding (ia->formats->dict));
+                       dict_get_encoding (ia->dict));
       if (error != NULL)
         {
           tooltip = xasprintf (_("Cannot parse field content `%.*s' as "
@@ -414,7 +411,7 @@ parse_field (struct import_assistant *ia,
     }
   if (outputp != NULL)
     {
-      *outputp = data_out (&val, dict_get_encoding (ia->formats->dict),  &out);
+      *outputp = data_out (&val, dict_get_encoding (ia->dict),  &out);
     }
   value_destroy (&val, var_get_width (var));
 
@@ -623,7 +620,7 @@ make_data_column (struct import_assistant *ia, GtkTreeView *tree_view,
   if (input)
     column = &ia->columns[dict_idx];
   else
-    var = dict_get_var (ia->formats->dict, dict_idx);
+    var = dict_get_var (ia->dict, dict_idx);
 
   name = escape_underscores (input ? column->name : var_get_name (var));
   char_cnt = input ? column->width : var_get_print_format (var)->w;
index 60dced703d29a34705c4dfb06815cbc6ddbcfab6..0122312300af74ff30a2e496d4bacc80d96f9693 100644 (file)
@@ -54,24 +54,8 @@ struct assistant
 
     GtkCellRenderer *prop_renderer;
     GtkCellRenderer *fixed_renderer;
-
   };
 
-
-
-/* Page where the user verifies and adjusts input formats. */
-struct formats_page
-  {
-    struct dictionary *dict;
-
-    GtkWidget *page;
-    GtkTreeView *data_tree_view;
-    PsppireDict *psppire_dict;
-    struct variable **modified_vars;
-    size_t modified_var_cnt;
-  };
-
-
 struct import_assistant
   {
     struct file file;
@@ -89,11 +73,9 @@ struct import_assistant
 
     int skip_lines;             /* Number of initial lines to skip? */
     bool variable_names;        /* Variable names above first line of data? */
+    struct dictionary *dict;
   };
 
-
-
-
 struct column
   {
     /* Variable name for this column.  This is the variable name
@@ -157,7 +139,6 @@ 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);
 
-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 *);
 
@@ -165,7 +146,6 @@ void prepare_separators_page (struct import_assistant *ia);
 void reset_separators_page (struct import_assistant *);
 void destroy_separators_page (struct import_assistant *ia);
 
-void init_formats_page (struct import_assistant *ia);
 void prepare_formats_page (struct import_assistant *ia);
 void reset_formats_page (struct import_assistant *);
 void destroy_formats_page (struct import_assistant *ia);