Merge remote-tracking branch 'origin/master' into sheet
authorJohn Darrington <john@darrington.wattle.id.au>
Sat, 22 Apr 2017 18:56:00 +0000 (20:56 +0200)
committerJohn Darrington <john@darrington.wattle.id.au>
Sat, 22 Apr 2017 18:56:00 +0000 (20:56 +0200)
1  2 
lib/gtk-contrib/gtkxpaned.c
src/data/variable.c
src/ui/gui/psppire-data-window.c
src/ui/gui/psppire-import-assistant.c
src/ui/gui/psppire-import-assistant.h
src/ui/gui/widgets.c

index 19dea4554b91fb52aa7a738bf55c5c5bc10c88d5,4b98059ee3c21dbb40328d192dea6e1725c20de5..06f642a24e02a59f2e961a5f7ec3125a6e75717b
@@@ -1,5 -1,5 +1,5 @@@
  /*******************************************************************************
-  **3456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 
+  **3456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789
   **      10        20        30        40        50        60        70        80
   **
   **  library for GtkXPaned-widget, a 2x2 grid-like variation of GtkPaned of gtk+
@@@ -54,9 -54,7 +54,9 @@@ enum ChildPropertie
    {
      CHILD_PROP_0,
      CHILD_PROP_RESIZE,
 -    CHILD_PROP_SHRINK
 +    CHILD_PROP_SHRINK,
 +    CHILD_PROP_LEFT_ATTACH,
 +    CHILD_PROP_TOP_ATTACH
    };
  
  enum WidgetSignals
@@@ -528,36 -526,13 +528,36 @@@ gtk_xpaned_class_init (GtkXPanedClass 
                                                       G_MAXINT,
                                                       G_PARAM_READABLE));
  
 +
 +  gtk_container_class_install_child_property (container_class,
 +                                              CHILD_PROP_LEFT_ATTACH,
 +                                              g_param_spec_int ("left-attach",
 +                                                              "Left Attach",
 +                                                              "The column number to which the  left side of the widget should be attached",
 +                                                              0, 1,
 +                                                              0,
 +                                                              G_PARAM_READWRITE));
 +
 +
 +
 +  gtk_container_class_install_child_property (container_class,
 +                                              CHILD_PROP_TOP_ATTACH,
 +                                              g_param_spec_int ("top-attach",
 +                                                              "Top Attach",
 +                                                              "The row number to which the  top side of the widget should be attached",
 +                                                              0, 1,
 +                                                              0,
 +                                                              G_PARAM_READWRITE));
 +
 +
 +  
    /**
     * GtkPaned:resize:
     *
-    * The "resize" child property determines whether the child expands and 
+    * The "resize" child property determines whether the child expands and
     * shrinks along with the paned widget.
-    * 
-    * Since: 2.4 
+    *
+    * Since: 2.4
     */
    gtk_container_class_install_child_property (container_class,
                                                CHILD_PROP_RESIZE,
    /**
     * GtkPaned:shrink:
     *
-    * The "shrink" child property determines whether the child can be made 
+    * The "shrink" child property determines whether the child can be made
     * smaller than its requisition.
-    * 
-    * Since: 2.4 
+    *
+    * Since: 2.4
     */
    gtk_container_class_install_child_property (container_class,
                                                CHILD_PROP_SHRINK,
@@@ -837,12 -812,6 +837,12 @@@ gtk_xpaned_size_allocate (GtkWidget * w
    GtkRequisition bottom_right_child_requisition;
    gint handle_size;
  
 +  g_print ("Allocate %p %p %p %p\n",
 +         xpaned->top_left_child,
 +         xpaned->top_right_child,
 +         xpaned->bottom_left_child,
 +         xpaned->bottom_right_child);
 +  
    /* determine size of handle(s) */
    gtk_widget_style_get (widget, "handle-size", &handle_size, NULL);
  
@@@ -1077,109 -1046,73 +1077,109 @@@ gtk_xpaned_set_child_property (GtkConta
                                 const GValue * value, GParamSpec * pspec)
  {
    GtkXPaned *xpaned = GTK_XPANED (container);
 -  gboolean old_value = FALSE;
 -  gboolean new_value = FALSE;
  
    g_assert (child == xpaned->top_left_child ||
              child == xpaned->top_right_child ||
              child == xpaned->bottom_left_child ||
              child == xpaned->bottom_right_child);
  
 -  new_value = g_value_get_boolean (value);
 -
 +  gint attach = g_value_get_int (value);
    switch (property_id)
      {
 +    case CHILD_PROP_LEFT_ATTACH:
 +      g_object_ref (child);
 +      gtk_widget_unparent (child);
 +      if (attach == 0)
 +      {
 +      if (child == xpaned->top_right_child)
 +        xpaned->top_left_child = child;
 +      else if (child == xpaned->bottom_right_child)
 +        xpaned->bottom_left_child = child;
 +      }
 +      else
 +      {
 +      if (child == xpaned->top_left_child)
 +        xpaned->top_right_child = child;
 +      else if (child == xpaned->bottom_left_child)
 +        xpaned->bottom_right_child = child;
 +      }
 +      gtk_widget_set_parent (child, GTK_WIDGET (xpaned));
 +      g_object_unref (child);
 +      break;
 +    case CHILD_PROP_TOP_ATTACH:
 +      g_object_ref (child);
 +      gtk_widget_unparent (child);
 +      if (attach == 0)
 +      {
 +        if (child == xpaned->bottom_right_child)
 +          xpaned->top_right_child = child;
 +        else if (child == xpaned->bottom_left_child)
 +          xpaned->top_left_child = child;
 +      }
 +      else
 +      {
 +        if (child == xpaned->top_left_child)
 +          xpaned->bottom_left_child = child;
 +        else if (child == xpaned->top_right_child)
 +          xpaned->bottom_right_child = child;
 +      }
 +      gtk_widget_set_parent (child, GTK_WIDGET (xpaned));
 +      g_object_unref (child);
 +      break;
      case CHILD_PROP_RESIZE:
 -      if (child == xpaned->top_left_child)
 -        {
 -          old_value = xpaned->top_left_child_resize;
 -          xpaned->top_left_child_resize = new_value;
 -        }
 -      else if (child == xpaned->top_right_child)
 -        {
 -          old_value = xpaned->top_right_child_resize;
 -          xpaned->top_right_child_resize = new_value;
 -        }
 -      else if (child == xpaned->bottom_left_child)
 -        {
 -          old_value = xpaned->bottom_left_child_resize;
 -          xpaned->bottom_left_child_resize = new_value;
 -        }
 -      else if (child == xpaned->bottom_right_child)
 -        {
 -          old_value = xpaned->bottom_right_child_resize;
 -          xpaned->bottom_right_child_resize = new_value;
 -        }
 +      {
 +      gboolean  new_value = TRUE;
 +      
 +      if (child == xpaned->top_left_child)
 +        {
 +          xpaned->top_left_child_resize = new_value;
 +        }
 +      else if (child == xpaned->top_right_child)
 +        {
 +          xpaned->top_right_child_resize = new_value;
 +        }
 +      else if (child == xpaned->bottom_left_child)
 +        {
 +          xpaned->bottom_left_child_resize = new_value;
 +        }
 +      else if (child == xpaned->bottom_right_child)
 +        {
 +          xpaned->bottom_right_child_resize = new_value;
 +        }
 +      }
        break;
 -
 +      
      case CHILD_PROP_SHRINK:
 -      if (child == xpaned->top_left_child)
 -        {
 -          old_value = xpaned->top_left_child_shrink;
 -          xpaned->top_left_child_shrink = new_value;
 -        }
 -      else if (child == xpaned->top_right_child)
 -        {
 -          old_value = xpaned->top_right_child_shrink;
 -          xpaned->top_right_child_shrink = new_value;
 -        }
 -      else if (child == xpaned->bottom_left_child)
 -        {
 -          old_value = xpaned->bottom_left_child_shrink;
 -          xpaned->bottom_left_child_shrink = new_value;
 -        }
 -      else if (child == xpaned->bottom_right_child)
 -        {
 -          old_value = xpaned->bottom_right_child_shrink;
 -          xpaned->bottom_right_child_shrink = new_value;
 -        }
 +      {
 +      gboolean  new_value = FALSE;
 +      
 +      if (child == xpaned->top_left_child)
 +        {
 +          xpaned->top_left_child_shrink = new_value;
 +        }
 +      else if (child == xpaned->top_right_child)
 +        {
 +          xpaned->top_right_child_shrink = new_value;
 +        }
 +      else if (child == xpaned->bottom_left_child)
 +        {
 +          xpaned->bottom_left_child_shrink = new_value;
 +        }
 +      else if (child == xpaned->bottom_right_child)
 +        {
 +          xpaned->bottom_right_child_shrink = new_value;
 +        }
 +      }
        break;
  
      default:
        GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container,
                                                      property_id, pspec);
 -      old_value = -1;           /* quiet gcc */
        break;
      }
  
 -  if (old_value != new_value)
 -    gtk_widget_queue_resize (GTK_WIDGET (container));
 +  gtk_widget_queue_resize (GTK_WIDGET (container));
 +  gtk_widget_queue_draw (GTK_WIDGET (container));
  }
  
  static void
@@@ -1197,26 -1130,6 +1197,26 @@@ gtk_xpaned_get_child_property (GtkConta
  
    switch (property_id)
      {
 +    case CHILD_PROP_TOP_ATTACH:
 +      if (child == xpaned->top_left_child)
 +      g_value_set_int (value, 0);
 +      if (child == xpaned->top_right_child)
 +      g_value_set_int (value, 0);
 +      if (child == xpaned->bottom_left_child)
 +      g_value_set_int (value, 1);
 +      if (child == xpaned->bottom_right_child)
 +      g_value_set_int (value, 1);
 +      break;
 +    case CHILD_PROP_LEFT_ATTACH:
 +      if (child == xpaned->top_left_child)
 +      g_value_set_int (value, 0);
 +      if (child == xpaned->bottom_left_child)
 +      g_value_set_int (value, 0);
 +      if (child == xpaned->top_right_child)
 +      g_value_set_int (value, 1);
 +      if (child == xpaned->bottom_right_child)
 +      g_value_set_int (value, 1);
 +      break;
      case CHILD_PROP_RESIZE:
        if (child == xpaned->top_left_child)
          g_value_set_boolean (value, xpaned->top_left_child_resize);
@@@ -2101,9 -2014,9 +2101,9 @@@ gtk_xpaned_forall (GtkContainer * conta
  /**
   * gtk_xpaned_get_position_x:
   * @paned: a #GtkXPaned widget
-  * 
+  *
   * Obtains the x-position of the divider.
-  * 
+  *
   * Return value: x-position of the divider
   **/
  gint
@@@ -2117,9 -2030,9 +2117,9 @@@ gtk_xpaned_get_position_x (GtkXPaned * 
  /**
   * gtk_xpaned_get_position_y:
   * @paned: a #GtkXPaned widget
-  * 
+  *
   * Obtains the y-position of the divider.
-  * 
+  *
   * Return value: y-position of the divider
   **/
  gint
@@@ -2135,7 -2048,7 +2135,7 @@@ gtk_xpaned_get_position_y (GtkXPaned * 
   * @paned: a #GtkXPaned widget
   * @xposition: pixel x-position of divider, a negative values
   *                       of a component mean that the position is unset.
-  * 
+  *
   * Sets the x-position of the divider between the four panes.
   **/
  void
@@@ -2184,7 -2097,7 +2184,7 @@@ gtk_xpaned_set_position_x (GtkXPaned * 
   * @paned: a #GtkXPaned widget
   * @yposition: pixel y-position of divider, a negative values
   *                       of a component mean that the position is unset.
-  * 
+  *
   * Sets the y-position of the divider between the four panes.
   **/
  void
@@@ -2259,9 -2172,9 +2259,9 @@@ gtk_xpaned_fetch_unmaximized_y (GtkXPan
  /**
   * gtk_xpaned_get_top_left_child:
   * @xpaned: a #GtkXPaned widget
-  * 
+  *
   * Obtains the top-left child of the xpaned widget.
-  * 
+  *
   * Return value: top-left child, or %NULL if it is not set.
   *
   * Since: 2.4
@@@ -2277,9 -2190,9 +2277,9 @@@ gtk_xpaned_get_top_left_child (GtkXPane
  /**
   * gtk_xpaned_get_top_right_child:
   * @xpaned: a #GtkXPaned widget
-  * 
+  *
   * Obtains the top-right child of the xpaned widget.
-  * 
+  *
   * Return value: top-right child, or %NULL if it is not set.
   *
   * Since: 2.4
@@@ -2295,9 -2208,9 +2295,9 @@@ gtk_xpaned_get_top_right_child (GtkXPan
  /**
   * gtk_xpaned_get_bottom_left_child:
   * @xpaned: a #GtkXPaned widget
-  * 
+  *
   * Obtains the bottom-left child of the xpaned widget.
-  * 
+  *
   * Return value: bottom-left child, or %NULL if it is not set.
   *
   * Since: 2.4
@@@ -2313,9 -2226,9 +2313,9 @@@ gtk_xpaned_get_bottom_left_child (GtkXP
  /**
   * gtk_xpaned_get_bottom_right_child:
   * @xpaned: a #GtkXPaned widget
-  * 
+  *
   * Obtains the bottom-right child of the xpaned widget.
-  * 
+  *
   * Return value: bottom-right child, or %NULL if it is not set.
   *
   * Since: 2.4
diff --combined src/data/variable.c
index 42a07ee8bb5d3481bec1a4656f13bba1dd61a393,3e3c72a6bb7299eb7fb434f4feaed620ad0230f2..656a06204f1dc077b73987c4f2e18395209edfbe
@@@ -1,5 -1,5 +1,5 @@@
  /* PSPP - a program for statistical analysis.
 -   Copyright (C) 1997-9, 2000, 2006, 2009, 2010, 2011, 2012, 2013, 2014 Free Software Foundation, Inc.
 +   Copyright (C) 1997-9, 2000, 2006, 2009, 2010, 2011, 2012, 2013, 2014, 2016 Free Software Foundation, Inc.
  
     This program is free software: you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
  
  #include "gettext.h"
  #define _(msgid) gettext (msgid)
 +#define N_(msgid) (msgid)
 +
 +/* This should follow the definition in Gtk */
 +typedef struct
 +{
 +  int value;
 +  const char *name;
 +  const char *label;
 +} GEnumValue;
 +
 +const GEnumValue align[] =
 +  {
 +    {ALIGN_LEFT,   "left", N_("Left")},
 +    {ALIGN_RIGHT,  "right", N_("Right")},
 +    {ALIGN_CENTRE, "center", N_("Center")},
 +    {0,0,0}
 +  };
 +
 +const GEnumValue measure[] =
 +  {
 +    {MEASURE_NOMINAL, "nominal", N_("Nominal")},
 +    {MEASURE_ORDINAL, "ordinal", N_("Ordinal")},
 +    {MEASURE_SCALE,   "scale", N_("Scale")},
 +    {0,0,0}
 +  };
 +
 +const GEnumValue role[] =
 +  {
 +    {ROLE_INPUT,  "input",    N_("Input")},
 +    {ROLE_TARGET, "output",   N_("Output")},
 +    {ROLE_BOTH,   "both",     N_("Both")},
 +    {ROLE_NONE,   "none",     N_("None")},
 +    {ROLE_PARTITION, "partition", N_("Partition")},
 +    {ROLE_SPLIT,  "split",    N_("Split")},
 +    {0,0,0}
 +  };
  
  /* A variable. */
  struct variable
@@@ -497,7 -461,7 +497,7 @@@ var_set_value_labels (struct variable *
  {
    struct variable *ov = var_clone (v);
    var_set_value_labels_quiet (v, vls);
-   dict_var_changed (v, VAR_TRAIT_LABEL, ov);  
+   dict_var_changed (v, VAR_TRAIT_LABEL, ov);
  }
  
  
@@@ -580,7 -544,7 +580,7 @@@ var_append_value_name (const struct var
      case SETTINGS_VAL_STYLE_VALUES:
        append_value (v, value, str);
        break;
-       
      case SETTINGS_VAL_STYLE_LABELS:
        if (name == NULL)
        append_value (v, value, str);
@@@ -807,8 -771,20 +807,8 @@@ measure_is_valid (enum measure m
  const char *
  measure_to_string (enum measure m)
  {
 -  switch (m)
 -    {
 -    case MEASURE_NOMINAL:
 -      return _("Nominal");
 -
 -    case MEASURE_ORDINAL:
 -      return _("Ordinal");
 -
 -    case MEASURE_SCALE:
 -      return _("Scale");
 -
 -    default:
 -      return "Invalid";
 -    }
 +  assert (m == measure[m].value);
 +  return gettext (measure[m].label);
  }
  
  /* Returns a string version of measurement level M, for use in PSPP command
@@@ -890,10 -866,31 +890,10 @@@ var_role_is_valid (enum var_role role
  
  /* Returns a string version of ROLE, for display to a user. */
  const char *
 -var_role_to_string (enum var_role role)
 +var_role_to_string (enum var_role r)
  {
 -  switch (role)
 -    {
 -    case ROLE_INPUT:
 -      return _("Input");
 -
 -    case ROLE_TARGET:
 -      return _("Output");
 -
 -    case ROLE_BOTH:
 -      return _("Both");
 -
 -    case ROLE_NONE:
 -      return _("None");
 -
 -    case ROLE_PARTITION:
 -      return _("Partition");
 -
 -    case ROLE_SPLIT:
 -      return _("Split");
 -
 -    default:
 -      return "Invalid";
 -    }
 +  assert (r == role[r].value);
 +  return gettext (role[r].label);
  }
  
  /* Returns a string version of ROLE, for use in PSPP comamnd syntax. */
@@@ -999,8 -996,20 +999,8 @@@ alignment_is_valid (enum alignment a
  const char *
  alignment_to_string (enum alignment a)
  {
 -  switch (a)
 -    {
 -    case ALIGN_LEFT:
 -      return _("Left");
 -
 -    case ALIGN_RIGHT:
 -      return _("Right");
 -
 -    case ALIGN_CENTRE:
 -      return _("Center");
 -
 -    default:
 -      return "Invalid";
 -    }
 +  assert (a == align[a].value);
 +  return gettext (align[a].label);
  }
  
  /* Returns a string version of alignment A, for use in PSPP command syntax. */
@@@ -1106,7 -1115,7 +1106,7 @@@ var_must_leave (const struct variable *
     all if it hasn't been saved to or read from a system or
     portable file. */
  size_t
- var_get_short_name_cnt (const struct variable *var) 
+ var_get_short_name_cnt (const struct variable *var)
  {
    return var->short_name_cnt;
  }
@@@ -1135,14 -1144,14 +1135,14 @@@ var_set_short_name (struct variable *va
    assert (short_name == NULL || id_is_plausible (short_name, false));
  
    /* Clear old short name numbered IDX, if any. */
-   if (idx < var->short_name_cnt) 
+   if (idx < var->short_name_cnt)
      {
        free (var->short_names[idx]);
-       var->short_names[idx] = NULL; 
+       var->short_names[idx] = NULL;
      }
  
    /* Install new short name for IDX. */
-   if (short_name != NULL) 
+   if (short_name != NULL)
      {
        if (idx >= var->short_name_cnt)
          {
@@@ -1201,14 -1210,14 +1201,14 @@@ var_get_case_index (const struct variab
     V, or calling var_set_attributes() on V, will also destroy its
     attribute set. */
  struct attrset *
- var_get_attributes (const struct variable *v) 
+ var_get_attributes (const struct variable *v)
  {
    return CONST_CAST (struct attrset *, &v->attributes);
  }
  
  /* Replaces variable V's attributes set by a copy of ATTRS. */
  static void
- var_set_attributes_quiet (struct variable *v, const struct attrset *attrs) 
+ var_set_attributes_quiet (struct variable *v, const struct attrset *attrs)
  {
    attrset_destroy (&v->attributes);
    attrset_clone (&v->attributes, attrs);
  
  /* Replaces variable V's attributes set by a copy of ATTRS. */
  void
- var_set_attributes (struct variable *v, const struct attrset *attrs) 
+ var_set_attributes (struct variable *v, const struct attrset *attrs)
  {
    struct variable *ov = var_clone (v);
    var_set_attributes_quiet (v, attrs);
@@@ -1308,8 -1317,8 +1308,8 @@@ var_clear_vardict (struct variable *v
  /*
    Returns zero, if W is a missing value for WV or if it is less than zero.
    Typically used to force a numerical value into a valid weight.
-   
-   As a side effect, this function will emit a warning if the value 
+   As a side effect, this function will emit a warning if the value
    WARN_ON_INVALID points to a bool which is TRUE.  That bool will be then
    set to FALSE.
   */
@@@ -1318,7 -1327,7 +1318,7 @@@ var_force_valid_weight (const struct va
  {
    if (w < 0.0 || (wv && var_is_num_missing (wv, w, MV_ANY)))
      w = 0.0;
-   
    if (w == 0.0 && warn_on_invalid != NULL && *warn_on_invalid)
      {
        *warn_on_invalid = false;
index c0da89e92f7868a3cd3dcb5973514452c2ebc712,99c0c6ac69b331e06698c4930a501b3b669b2e09..bdbdd085ef3de95537bd84b0ddf1682645f5059a
@@@ -1,6 -1,5 +1,6 @@@
  /* PSPPIRE - a graphical user interface for PSPP.
 -   Copyright (C) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2016  Free Software Foundation
 +   Copyright (C) 2008, 2009, 2010, 2011, 2012, 2013, 2014,
 +   2016, 2017  Free Software Foundation
  
     This program is free software: you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
  #include "ui/gui/helper.h"
  #include "ui/gui/psppire-import-assistant.h"
  #include "ui/gui/psppire-data-window.h"
 +#include "ui/gui/psppire-data-editor.h"
  #include "ui/gui/psppire-dialog-action.h"
  #include "ui/gui/psppire-encoding-selector.h"
  #include "ui/gui/psppire-syntax-window.h"
  #include "ui/gui/psppire-window.h"
 -#include "ui/gui/psppire-data-sheet.h"
 -#include "ui/gui/psppire-var-sheet.h"
  #include "ui/gui/windows-menu.h"
  #include "ui/gui/goto-case-dialog.h"
  #include "ui/gui/psppire.h"
@@@ -47,8 -47,6 +47,8 @@@
  #include "gl/c-strcasestr.h"
  #include "gl/xvasprintf.h"
  
 +#include "ui/gui/efficient-sheet/jmd-sheet.h"
 +
  #include "find-dialog.h"
  #include "options-dialog.h"
  #include "psppire-dialog-action-1sks.h"
@@@ -205,7 -203,7 +205,7 @@@ transformation_change_callback (bool tr
                                                  "transform-pending");
  
      g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
-                                transformations_pending); 
+                                transformations_pending);
    }
  
    if ( transformations_pending)
@@@ -384,15 -382,15 +384,15 @@@ load_file (PsppireWindow *de, const gch
      {
        gchar *utf8_file_name;
        struct string filename;
-       
        utf8_file_name = g_filename_to_utf8 (file_name, -1, NULL, NULL, NULL);
  
        if (NULL == utf8_file_name)
        return FALSE;
  
-       ds_init_empty (&filename);    
+       ds_init_empty (&filename);
        syntax_gen_string (&filename, ss_cstr (utf8_file_name));
-       
        g_free (utf8_file_name);
  
        if (encoding && encoding[0])
        mime_type = "application/x-spss-por";
        else if (name_has_sav_suffix (file_name))
        mime_type = "application/x-spss-sav";
-       
        add_most_recent (file_name, mime_type, encoding);
      }
  
@@@ -706,7 -704,7 +706,7 @@@ static voi
  status_bar_activate (GAction *action, GVariant *param,  PsppireDataWindow  *de)
  {
    GtkWidget *statusbar = get_widget_assert (de->builder, "status-bar");
-   
    GVariant *state = g_action_get_state (action);
    const gboolean visible = g_variant_get_boolean (state);
    g_action_change_state (action, g_variant_new_boolean (!visible));
@@@ -748,7 -746,7 +748,7 @@@ on_switch_page (GtkNotebook *notebook, 
        gtk_widget_show (GTK_WIDGET (de->mi_clear_cases));
  
        break;
-       
      case 1:
        g_action_change_state (action, g_variant_new_string ("VARS"));
        gtk_widget_hide (GTK_WIDGET (de->ti_insert_case));
        gtk_widget_hide (GTK_WIDGET (de->mi_find));
        gtk_widget_hide (GTK_WIDGET (de->mi_find_separator));
        gtk_widget_hide (GTK_WIDGET (de->mi_clear_cases));
-       
        break;
-     }      
+     }
  }
  
  
@@@ -792,7 -790,7 +792,7 @@@ fonts_activate (PsppireDataWindow  *de
    GtkWidget *dialog =  gtk_font_chooser_dialog_new (NULL, GTK_WINDOW (toplevel));
    GtkStyleContext *style = gtk_widget_get_style_context (GTK_WIDGET(de->data_editor));
    const PangoFontDescription *current_font ;
-   
    gtk_style_context_get (style, GTK_STATE_FLAG_NORMAL, "font", &current_font, NULL);
  
    gtk_font_chooser_set_font_desc (GTK_FONT_CHOOSER (dialog), current_font);
@@@ -824,7 -822,7 +824,7 @@@ value_labels_activate (GAction *action
    GVariant *new_state  = g_action_get_state (action);
    labels_active = g_variant_get_boolean (new_state);
    g_object_set (de->data_editor, "value-labels", labels_active, NULL);
-   
    gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (de->ti_value_labels_button),
                                     labels_active);
  }
@@@ -919,7 -917,7 +919,7 @@@ on_recent_files_select (GtkMenuShell *m
  
    free (encoding);
  
-   if ( psppire_window_load (PSPPIRE_WINDOW (se), file, encoding, NULL) ) 
+   if ( psppire_window_load (PSPPIRE_WINDOW (se), file, encoding, NULL) )
      gtk_widget_show (se);
    else
      gtk_widget_destroy (se);
@@@ -969,16 -967,14 +969,16 @@@ file_import (PsppireDataWindow *dw
    GtkWidget *w = psppire_import_assistant_new (GTK_WINDOW (dw));
    PsppireImportAssistant *asst = PSPPIRE_IMPORT_ASSISTANT (w);
    gtk_widget_show_all (w);
-   
    asst->main_loop = g_main_loop_new (NULL, TRUE);
    g_main_loop_run (asst->main_loop);
    g_main_loop_unref (asst->main_loop);
  
- #if TEXT_FILE  
++#if TEXT_FILE
    if (!asst->file_name)
      goto end;
  
-   
++
    switch (asst->response)
      {
      case GTK_RESPONSE_APPLY:
      default:
        break;
      }
- #endif    
-  end:  
 -
++#endif
+  end:
    gtk_widget_destroy (GTK_WIDGET (asst));
  }
  
@@@ -1007,7 -1003,7 +1007,7 @@@ connect_dialog_action (GType type, Pspp
    GAction *act = g_object_new (type,
                               "top-level", de,
                               NULL);
-   
    g_action_map_add_action (G_ACTION_MAP (de), act);
  }
  
@@@ -1021,7 -1017,7 +1021,7 @@@ static voi
  connect_action_to_menuitem (GActionMap *map, const gchar *action_name, GtkWidget *w, const gchar *accel)
  {
    GAction *a = g_action_map_lookup_action (map, action_name);
-   
    if (NULL == a)
      g_error ("Action \"%s\" not found in map", action_name);
  
        detailed_action_name = g_strdup_printf ("win.%s", action_name);
        else if (GTK_IS_APPLICATION (map))
        detailed_action_name = g_strdup_printf ("app.%s", action_name);
-       
        gtk_application_set_accels_for_action (app,
                                             detailed_action_name,
                                             accels);
        free (detailed_action_name);
      }
-   
    g_signal_connect_swapped (w, "activate", G_CALLBACK (g_action_activate_null), a);
   }
  
@@@ -1071,52 -1067,10 +1071,52 @@@ static voi
  on_cut (PsppireDataWindow *dw)
  {
    int p = gtk_notebook_get_current_page (GTK_NOTEBOOK (dw->data_editor));
 -  if (p == 0)
 -    {
 -      PsppireDataSheet *ds = psppire_data_editor_get_active_data_sheet (dw->data_editor);
 -      psppire_data_sheet_edit_cut (ds);
 +  if (p == PSPPIRE_DATA_EDITOR_DATA_VIEW)
 +  {
 +      PsppireDict *dict = NULL;
 +      g_object_get (dw->data_editor, "dictionary", &dict, NULL);
-       
++
 +      gint x, y;
 +      JmdSheet *sheet = JMD_SHEET (dw->data_editor->data_sheet);
 +      JmdRange sel = *sheet->selection;
 +
 +      GtkClipboard *clip =
 +      gtk_clipboard_get_for_display (gtk_widget_get_display (GTK_WIDGET (dw)),
 +                                     GDK_SELECTION_CLIPBOARD);
 +
 +      /* Save the selected area to a string */
 +      GString *str = g_string_new ("");
 +      for (y = sel.start_y ; y <= sel.end_y; ++y)
 +      {
 +        for (x = sel.start_x ; x <= sel.end_x; ++x)
 +          {
 +            const struct variable * var = psppire_dict_get_variable (dict, x);
 +            gchar *s = psppire_data_store_get_string (dw->data_editor->data_store,
 +                                                        y, var, FALSE);
 +            g_string_append (str, s);
 +            g_string_append (str, "\t");
 +            g_free (s);
 +          }
 +        g_string_append (str, "\n");
 +      }
-       
++
 +      gtk_clipboard_set_text (clip, str->str, str->len);
 +      g_string_free (str, TRUE);
 +
 +      /* Now fill the selected area with SYSMIS */
 +      union value sm ;
 +      sm.f = SYSMIS;
 +      for (x = sel.start_x ; x <= sel.end_x; ++x)
 +      {
 +        const struct variable * var = psppire_dict_get_variable (dict, x);
 +        for (y = sel.start_y ; y <= sel.end_y; ++y)
 +          {
 +            psppire_data_store_set_value (dw->data_editor->data_store,
 +                                          y,
 +                                          var, &sm);
 +          }
 +      }
 +
      }
  }
  
@@@ -1124,13 -1078,10 +1124,13 @@@ static voi
  on_copy (PsppireDataWindow *dw)
  {
    int p = gtk_notebook_get_current_page (GTK_NOTEBOOK (dw->data_editor));
 -  if (p == 0)
 +  if (p == PSPPIRE_DATA_EDITOR_DATA_VIEW)
      {
 -      PsppireDataSheet *ds = psppire_data_editor_get_active_data_sheet (dw->data_editor);
 -      psppire_data_sheet_edit_copy (ds);
 +      GtkClipboard *clip =
 +      gtk_clipboard_get_for_display (gtk_widget_get_display (GTK_WIDGET (dw)),
 +                                 GDK_SELECTION_CLIPBOARD);
 +
 +      jmd_sheet_set_clip (JMD_SHEET (dw->data_editor->data_sheet), clip);
      }
  }
  
@@@ -1138,78 -1089,75 +1138,78 @@@ static voi
  on_paste (PsppireDataWindow *dw)
  {
    int p = gtk_notebook_get_current_page (GTK_NOTEBOOK (dw->data_editor));
 -  if (p == 0)
 +  if (p == PSPPIRE_DATA_EDITOR_DATA_VIEW)
      {
 -      PsppireDataSheet *ds = psppire_data_editor_get_active_data_sheet (dw->data_editor);
 -      psppire_data_sheet_edit_paste (ds);
 +      psppire_data_editor_paste (dw->data_editor);
      }
  }
  
 -
  static void
  on_clear_cases (PsppireDataWindow *dw)
  {
 -  int p = gtk_notebook_get_current_page (GTK_NOTEBOOK (dw->data_editor));
 -  if (p == 0)
 +  PsppireDataEditor *de = dw->data_editor;
 +  int p = gtk_notebook_get_current_page (GTK_NOTEBOOK (de));
 +  if (p == PSPPIRE_DATA_EDITOR_DATA_VIEW)
      {
 -      PsppireDataSheet *ds = psppire_data_editor_get_active_data_sheet (dw->data_editor);
 -      psppire_data_sheet_edit_clear_cases (ds);
 +      JmdRange *range = JMD_SHEET(de->data_sheet)->selection;
 +      psppire_data_store_delete_cases (de->data_store, range->start_y,
 +                                     range->end_y - range->start_y + 1);
 +      gtk_widget_queue_draw (GTK_WIDGET (de->data_sheet));
      }
  }
  
  static void
  on_clear_variables (PsppireDataWindow *dw)
  {
 -  int p = gtk_notebook_get_current_page (GTK_NOTEBOOK (dw->data_editor));
 -  if (p == 0)
 +  PsppireDataEditor *de = dw->data_editor;
 +  int p = gtk_notebook_get_current_page (GTK_NOTEBOOK (de));
 +  if (p == PSPPIRE_DATA_EDITOR_DATA_VIEW)
      {
 -      PsppireDataSheet *ds = psppire_data_editor_get_active_data_sheet (dw->data_editor);
 -      psppire_data_sheet_edit_clear_variables (ds);
 +      psppire_data_editor_data_delete_variables (de);
      }
    else
      {
 -      psppire_var_sheet_clear_variables (PSPPIRE_VAR_SHEET (dw->data_editor->var_sheet));
 +      psppire_data_editor_var_delete_variables (de);
      }
  }
  
 -
  static void
  insert_variable (PsppireDataWindow *dw)
  {
 -  int p = gtk_notebook_get_current_page (GTK_NOTEBOOK (dw->data_editor));
 -  if (p == 0)
 +  PsppireDataEditor *de = dw->data_editor;
 +  int p = gtk_notebook_get_current_page (GTK_NOTEBOOK (de));
 +
 +  if (p == PSPPIRE_DATA_EDITOR_DATA_VIEW)
      {
 -      PsppireDataSheet *ds = psppire_data_editor_get_active_data_sheet (dw->data_editor);
 -      psppire_data_sheet_insert_variable (ds);
 +      JmdRange *range = JMD_SHEET(de->data_sheet)->selection;
 +      psppire_data_editor_insert_new_variable_at_posn (de, range->start_x);
      }
    else
      {
 -      psppire_var_sheet_insert_variable (PSPPIRE_VAR_SHEET (dw->data_editor->var_sheet));
 +      JmdRange *range = JMD_SHEET(de->var_sheet)->selection;
 +      psppire_data_editor_insert_new_variable_at_posn (de, range->start_y);
      }
  }
  
 -
  static void
  insert_case_at_row (PsppireDataWindow *dw)
  {
 -  PsppireDataSheet *ds = psppire_data_editor_get_active_data_sheet (dw->data_editor);
 -
 -  psppire_data_sheet_insert_case (ds);
 +  PsppireDataEditor *de = dw->data_editor;
 +  JmdRange *range = JMD_SHEET(de->data_sheet)->selection;
 +  psppire_data_editor_insert_new_case_at_posn (de, range->start_y);
  }
  
  static void
  goto_case (PsppireDataWindow *dw)
  {
 -  PsppireDataSheet *ds = psppire_data_editor_get_active_data_sheet (dw->data_editor);
 -
 -  goto_case_dialog (ds);
 +  PsppireDataEditor *de = dw->data_editor;
 +  int p = gtk_notebook_get_current_page (GTK_NOTEBOOK (de));
 +  if (p == PSPPIRE_DATA_EDITOR_DATA_VIEW)
 +    {
 +      goto_case_dialog (JMD_SHEET (de->data_sheet));
 +    }
  }
  
 -
 -
  static GtkWidget *
  create_file_menu (PsppireDataWindow *dw)
  {
      GtkWidget *new_menu = gtk_menu_new ();
  
      g_object_set (new, "submenu", new_menu, NULL);
-       
      GtkWidget *syntax  = gtk_menu_item_new_with_mnemonic (_("_Syntax"));
      connect_action_to_menuitem (G_ACTION_MAP (g_application_get_default ()), "new-syntax", syntax, 0);
-     
      GtkWidget *data = gtk_menu_item_new_with_mnemonic (_("_Data"));
      connect_action_to_menuitem (G_ACTION_MAP (g_application_get_default ()), "new-data", data, 0);
  
      gtk_menu_attach (GTK_MENU (new_menu), syntax,    0, 1, 0, 1);
      gtk_menu_attach (GTK_MENU (new_menu), data,      0, 1, 1, 2);
    }
-   
    GtkWidget *open = gtk_menu_item_new_with_mnemonic (_("_Open"));
    connect_action_to_menuitem (G_ACTION_MAP (dw), "open", open, "<Ctrl>O");
-   
    GtkWidget *import = gtk_menu_item_new_with_mnemonic (_("_Import Data..."));
    connect_action_to_menuitem (G_ACTION_MAP (dw), "file-import", import, 0);
-   
    gtk_menu_attach (GTK_MENU (menu), open,       0, 1, 1, 2);
    gtk_menu_attach (GTK_MENU (menu), import,     0, 1, 2, 3);
  
  
    GtkWidget *save = gtk_menu_item_new_with_mnemonic (_("_Save..."));
    connect_action_to_menuitem (G_ACTION_MAP (dw), "save", save, "<Ctrl>S");
-   
    GtkWidget *save_as = gtk_menu_item_new_with_mnemonic (_("Save _As..."));
    connect_action_to_menuitem (G_ACTION_MAP (dw), "save-as", save_as, "<Shift><Ctrl>S");
-   
    GtkWidget *rename_dataset = gtk_menu_item_new_with_mnemonic (_("_Rename Dataset..."));
    connect_action_to_menuitem (G_ACTION_MAP (dw), "rename-dataset", rename_dataset, 0);
  
-   
    gtk_menu_attach (GTK_MENU (menu), save,        0, 1, 4, 5);
    gtk_menu_attach (GTK_MENU (menu), save_as,     0, 1, 5, 6);
    gtk_menu_attach (GTK_MENU (menu), rename_dataset,     0, 1, 6, 7);
      GtkWidget *dd_menu = gtk_menu_new ();
  
      g_object_set (display_data, "submenu", dd_menu, NULL);
-     
      GtkWidget *working_file  = gtk_menu_item_new_with_mnemonic (_("Working File"));
      connect_action_to_menuitem (G_ACTION_MAP (dw), "info-working", working_file, 0);
      GtkWidget *external_file = gtk_menu_item_new_with_mnemonic (_("_External File..."));
      gtk_menu_attach (GTK_MENU (dd_menu), working_file,    0, 1, 0, 1);
      gtk_menu_attach (GTK_MENU (dd_menu), external_file,   0, 1, 1, 2);
    }
-   
    gtk_menu_attach (GTK_MENU (menu), gtk_separator_menu_item_new (), 0, 1, 9, 10);
  
    {
  
      gtk_menu_attach (GTK_MENU (menu), mi_data,       0, 1, 10, 11);
      gtk_menu_attach (GTK_MENU (menu), mi_files,      0, 1, 11, 12);
-     
      g_object_set (menu_data, "show-tips",  TRUE, NULL);
      g_object_set (menu_files, "show-tips",  TRUE, NULL);
  
      g_object_set (mi_data, "submenu",  menu_data, NULL);
      g_object_set (mi_files, "submenu", menu_files, NULL);
-     
      {
        GtkRecentFilter *filter = gtk_recent_filter_new ();
  
      connect_action_to_menuitem (G_ACTION_MAP (g_application_get_default ()),
                                "quit", quit, "<Ctrl>Q");
    }
-   
    g_object_set (menuitem, "submenu", menu, NULL);
    gtk_widget_show_all (menuitem);
-   
    return menuitem;
  }
  
 +
  static GtkWidget *
  create_edit_menu (PsppireDataWindow *dw)
  {
    GAction *a = g_action_map_lookup_action (G_ACTION_MAP (dw),  "PsppireDialogActionVarInfo");
    g_assert (a);
    g_signal_connect_swapped (go_to_variable, "activate", G_CALLBACK (psppire_dialog_action_activate_null), a);
-   
    gtk_menu_attach (GTK_MENU (menu), go_to_variable,         0, 1, i, i + 1); ++i;
    gtk_menu_attach (GTK_MENU (menu), dw->mi_go_to_case,      0, 1, i, i + 1); ++i;
  
    {
      GtkAccelGroup *ag = gtk_accel_group_new ();
-     
      dw->mi_edit_separator = gtk_separator_menu_item_new ();
      gtk_menu_attach (GTK_MENU (menu), dw->mi_edit_separator, 0, 1, i, i + 1); ++i;
  
      gtk_window_add_accel_group (GTK_WINDOW (dw), ag);
      gtk_widget_add_accelerator (dw->mi_cut, "activate", ag,
                                'X', GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
-     
      dw->mi_copy = gtk_menu_item_new_with_mnemonic (_("_Copy"));
      gtk_menu_attach (GTK_MENU (menu), dw->mi_copy,     0, 1, i, i + 1); ++i;
      g_signal_connect_swapped (dw->mi_copy, "activate", G_CALLBACK (on_copy), dw);
      gtk_widget_add_accelerator (dw->mi_copy, "activate", ag,
                                'C', GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
-       
      dw->mi_paste = gtk_menu_item_new_with_mnemonic (_("_Paste"));
      gtk_menu_attach (GTK_MENU (menu), dw->mi_paste,     0, 1, i, i + 1); ++i;
      g_signal_connect_swapped (dw->mi_paste, "activate", G_CALLBACK (on_paste), dw);
      dw->mi_clear_variables = gtk_menu_item_new_with_mnemonic (_("Clear _Variables"));
      gtk_menu_attach (GTK_MENU (menu), dw->mi_clear_variables,     0, 1, i, i + 1); ++i;
      g_signal_connect_swapped (dw->mi_clear_variables, "activate", G_CALLBACK (on_clear_variables), dw);
-     
      dw->mi_clear_cases = gtk_menu_item_new_with_mnemonic (_("Cl_ear Cases"));
      gtk_menu_attach (GTK_MENU (menu), dw->mi_clear_cases,     0, 1, i, i + 1); ++i;
      g_signal_connect_swapped (dw->mi_clear_cases, "activate", G_CALLBACK (on_clear_cases), dw);
    }
-   
    {
      dw->mi_find_separator = gtk_separator_menu_item_new ();
      gtk_menu_attach (GTK_MENU (menu), dw->mi_find_separator, 0, 1, i, i + 1); ++i;
-   
      dw->mi_find = gtk_menu_item_new_with_mnemonic (_("_Find..."));
      g_signal_connect_swapped (dw->mi_find, "activate", G_CALLBACK (find_dialog), dw);
      gtk_menu_attach (GTK_MENU (menu), dw->mi_find,    0, 1,  i, i + 1); ++i;
                              G_CALLBACK (options_dialog), dw);
      gtk_menu_attach (GTK_MENU (menu), dw->mi_options, 0, 1,  i, i + 1); ++i;
    }
-   
    g_object_set (menuitem, "submenu", menu, NULL);
-   
    gtk_widget_show_all (menuitem);
-   
    return menuitem;
  }
  
 -
  static void
  psppire_data_window_finish_init (PsppireDataWindow *de,
                                   struct dataset *ds)
  
    de->data_editor =
      PSPPIRE_DATA_EDITOR (psppire_data_editor_new (de->dict, de->data_store));
-   
    g_signal_connect (de, "realize",
                      G_CALLBACK (set_data_page), de);
  
    g_signal_connect_swapped (de->data_store, "case-changed",
                            G_CALLBACK (set_unsaved), de);
  
 -  g_signal_connect_swapped (de->data_store, "case-inserted",
 -                          G_CALLBACK (set_unsaved), de);
 -
 -  g_signal_connect_swapped (de->data_store, "cases-deleted",
 -                          G_CALLBACK (set_unsaved), de);
 -
    dataset_set_callbacks (de->dataset, &cbs, de);
  
    connect_help (de->builder);
                    G_CALLBACK (on_split_change),
                    de);
  
 -  g_signal_connect_swapped (de->dict, "backend-changed",
 +  g_signal_connect_swapped (de->dict, "items-changed",
                              G_CALLBACK (enable_save), de);
    g_signal_connect_swapped (de->dict, "variable-inserted",
                              G_CALLBACK (enable_save), de);
    connect_dialog_action (PSPPIRE_TYPE_DIALOG_ACTION_FLIP,  de);
    connect_dialog_action (PSPPIRE_TYPE_DIALOG_ACTION_AGGREGATE,  de);
    connect_dialog_action (PSPPIRE_TYPE_DIALOG_ACTION_WEIGHT,  de);
-   
    connect_dialog_action (PSPPIRE_TYPE_DIALOG_ACTION_COMPUTE,  de);
    connect_dialog_action (PSPPIRE_TYPE_DIALOG_ACTION_COUNT,  de);
    connect_dialog_action (PSPPIRE_TYPE_DIALOG_ACTION_AUTORECODE,  de);
    connect_dialog_action (PSPPIRE_TYPE_DIALOG_ACTION_RECODE_SAME,  de);
    connect_dialog_action (PSPPIRE_TYPE_DIALOG_ACTION_RECODE_DIFFERENT,  de);
  
-     
    connect_dialog_action (PSPPIRE_TYPE_DIALOG_ACTION_DESCRIPTIVES,  de);
    connect_dialog_action (PSPPIRE_TYPE_DIALOG_ACTION_FREQUENCIES,  de);
    connect_dialog_action (PSPPIRE_TYPE_DIALOG_ACTION_EXAMINE,  de);
    connect_dialog_action (PSPPIRE_TYPE_DIALOG_ACTION_REGRESSION, de);
    connect_dialog_action (PSPPIRE_TYPE_DIALOG_ACTION_LOGISTIC, de);
    connect_dialog_action (PSPPIRE_TYPE_DIALOG_ACTION_ROC, de);
-   
    connect_dialog_action (PSPPIRE_TYPE_DIALOG_ACTION_COMMENTS, de);
    connect_dialog_action (PSPPIRE_TYPE_DIALOG_ACTION_VAR_INFO, de);
  
      g_signal_connect_swapped (file_import_action, "activate", G_CALLBACK (file_import), de);
      g_action_map_add_action (G_ACTION_MAP (de), G_ACTION (file_import_action));
    }
-   
    {
      GSimpleAction *save = g_simple_action_new ("save", NULL);
      g_signal_connect_swapped (save, "activate", G_CALLBACK (psppire_window_save), de);
      g_action_map_add_action (G_ACTION_MAP (de), G_ACTION (act_gridlines));
    }
  
-   
    {
      GSimpleAction *act_view_data = g_simple_action_new_stateful ("view_dv", G_VARIANT_TYPE_STRING,
                                                                 g_variant_new_string ("DATA"));
      g_signal_connect_swapped (find, "activate", G_CALLBACK (find_dialog), de);
      g_action_map_add_action (G_ACTION_MAP (de), G_ACTION (find));
    }
-   
    {
      int idx = 0;
      {
  
      {
        de->ti_jump_to_case = gtk_tool_button_new (NULL, "Jump to Case");
-       
        GAction *a = g_action_map_lookup_action (G_ACTION_MAP (de),  "jump-to-case");
        g_assert (a);
        g_signal_connect_swapped (de->ti_jump_to_case, "clicked",
                                G_CALLBACK (g_action_activate_null), a);
-       
        gtk_toolbar_insert (GTK_TOOLBAR (hb), de->ti_jump_to_case, idx++);
        gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (de->ti_jump_to_case), "edit-go-to-case");
        gtk_widget_set_tooltip_text (GTK_WIDGET (de->ti_jump_to_case), _("Jump to a case in the data sheet"));
        g_signal_connect_swapped (de->ti_find, "clicked",
                                G_CALLBACK (g_action_activate_null), a);
  
-       
        gtk_toolbar_insert (GTK_TOOLBAR (hb), de->ti_find, idx++);
        gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (de->ti_find), "edit-find");
        gtk_widget_set_tooltip_text (GTK_WIDGET (de->ti_find), _("Search for values in the data"));
    ll_push_head (&all_data_windows, &de->ll);
  }
  
 +
  static void
  psppire_data_window_dispose (GObject *object)
  {
@@@ -1898,7 -1851,6 +1898,7 @@@ psppire_data_window_get_property (GObje
  }
  
  
 +
  GtkWidget*
  psppire_data_window_new (struct dataset *ds)
  {
  
    GApplication *app = g_application_get_default ();
    gtk_application_add_window (GTK_APPLICATION (app), GTK_WINDOW (dw));
-   
    return dw;
  }
  
 +
 +
  bool
  psppire_data_window_is_empty (PsppireDataWindow *dw)
  {
    return psppire_dict_get_var_cnt (dw->dict) == 0;
  }
  
 +
  static void
  psppire_data_window_iface_init (PsppireWindowIface *iface)
  {
  
  \f
  
 +
  PsppireDataWindow *
  psppire_default_data_window (void)
  {
    return ll_data (ll_head (&all_data_windows), PsppireDataWindow, ll);
  }
  
 +
 +
  void
  psppire_data_window_set_default (PsppireDataWindow *pdw)
  {
@@@ -1976,8 -1922,6 +1976,8 @@@ psppire_data_window_undefault (PsppireD
    ll_push_tail (&all_data_windows, &pdw->ll);
  }
  
 +
 +
  PsppireDataWindow *
  psppire_data_window_for_dataset (struct dataset *ds)
  {
@@@ -2008,7 -1952,7 +2008,7 @@@ create_data_window (void
    GtkWidget *w = psppire_data_window_new (NULL);
  
    gtk_widget_show (w);
-   
    return GTK_WINDOW (w);
  }
  
index d8695706a317a4c3b9ff859c578bae2debf1ce15,5f8793186b3303e8201c724f48c6b5cfe0892239..9dc2385f541cb6e10c0f8629e3e87bff61b690f6
@@@ -1,5 -1,5 +1,5 @@@
  /* PSPPIRE - a graphical user interface for PSPP.
 -   Copyright (C) 2015, 2016  Free Software Foundation
 +   Copyright (C) 2015, 2016, 2017  Free Software Foundation
  
     This program is free software: you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
  
  #include "builder-wrapper.h"
  #include "helper.h"
 -#include "pspp-sheet-view.h"
 -#include "pspp-sheet-selection.h"
  #include "psppire-import-assistant.h"
  #include "psppire-scanf.h"
  #include "psppire-dialog.h"
  #include "psppire-empty-list-store.h"
  #include "psppire-encoding-selector.h"
  #include "psppire-spreadsheet-model.h"
 -#include "psppire-var-sheet.h"
 +#include "psppire-text-file.h"
 +#include "psppire-delimited-text.h"
 +
  #include "ui/syntax-gen.h"
  
  #include <gettext.h>
@@@ -68,10 -68,21 +68,10 @@@ static void split_fields (PsppireImport
  static void choose_column_names (PsppireImportAssistant *ia);
  
  
 -/* Frees IA's file substructure. */
 -static void destroy_file (PsppireImportAssistant *ia);
 -
 -static void clear_fields (PsppireImportAssistant *ia);
 -
  
  static void intro_page_create (PsppireImportAssistant *ia);
  static void first_line_page_create (PsppireImportAssistant *ia);
  
 -static gboolean process_file (PsppireImportAssistant *ia);
 -
 -
 -static GtkWidget * create_data_tree_view (gboolean input, GtkContainer *parent,
 -                                        PsppireImportAssistant *ia);
 -
  static void separators_page_create (PsppireImportAssistant *ia);
  static void formats_page_create (PsppireImportAssistant *ia);
  
@@@ -139,6 -150,7 +139,6 @@@ psppire_import_assistant_finalize (GObj
    if (ia->spreadsheet)
      spreadsheet_unref (ia->spreadsheet);
  
 -  //  clear_fields (ia);
    destroy_columns (ia);
  
    ds_destroy (&ia->separators);
  
    g_object_unref (ia->builder);
  
 -  destroy_file (ia);
 -
    g_object_unref (ia->prop_renderer);
    g_object_unref (ia->fixed_renderer);
  
@@@ -187,7 -201,6 +187,7 @@@ on_paste (GtkButton *button, PsppireImp
    close_assistant (ia, PSPPIRE_RESPONSE_PASTE);
  }
  
 +
  /* Revises the contents of the fields tree view based on the
     currently chosen set of separators. */
  static void
@@@ -196,8 -209,12 +196,8 @@@ revise_fields_preview (PsppireImportAss
    push_watch_cursor (ia);
  
    get_separators (ia);
 -  split_fields (ia);
 +  //  split_fields (ia);
    choose_column_names (ia);
 -  ia->fields_tree_view =
 -    GTK_WIDGET (create_data_tree_view (TRUE,
 -                                     GTK_CONTAINER (get_widget_assert (ia->builder, "fields-scroller")),
 -                                     ia));
  
    pop_watch_cursor (ia);
  }
@@@ -235,29 -252,24 +235,29 @@@ find_commonest_chars (unsigned long in
      ds_assign_cstr (result, def);
  }
  
 -
  /* Picks the most likely separator and quote characters based on
     IA's file data. */
  static void
  choose_likely_separators (PsppireImportAssistant *ia)
  {
    unsigned long int histogram[UCHAR_MAX + 1] = { 0 };
 -  size_t row;
  
    /* Construct a histogram of all the characters used in the
       file. */
 -  for (row = 0; row < ia->line_cnt; row++)
 +  gboolean valid;
 +  GtkTreeIter iter;
 +  for (valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (ia->text_file), &iter);
 +       valid;
 +       valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (ia->text_file), &iter))
      {
 -      struct substring line = ds_ss (&ia->lines[row]);
 +      gchar *xxx = 0;
 +      gtk_tree_model_get (GTK_TREE_MODEL (ia->text_file), &iter, 1, &xxx, -1);
 +      struct substring line = ss_cstr (xxx);
        size_t length = ss_length (line);
        size_t i;
        for (i = 0; i < length; i++)
          histogram[(unsigned char) line.string[i]]++;
 +      g_free (xxx);
      }
  
    find_commonest_chars (histogram, "\"'", "", &ia->quotes);
  
  static void set_separators (PsppireImportAssistant *ia);
  
-       
 +
 +static void
 +repopulate_delimiter_columns (PsppireImportAssistant *ia)
 +{
 +  /* Remove all the columns */
 +  while (gtk_tree_view_get_n_columns (GTK_TREE_VIEW (ia->fields_tree_view)) > 0)
 +    {
 +      GtkTreeViewColumn *tvc = gtk_tree_view_get_column (GTK_TREE_VIEW (ia->fields_tree_view), 0);
 +      gtk_tree_view_remove_column (GTK_TREE_VIEW (ia->fields_tree_view), tvc);
 +    }
 +
 +  gint n_fields = gtk_tree_model_get_n_columns (ia->delimiters_model);
 +
 +  /* ... and put them back again. */
 +  gint f;
 +  for (f = gtk_tree_view_get_n_columns (GTK_TREE_VIEW (ia->fields_tree_view));
 +       f < n_fields; f++)
 +    {
 +      GtkCellRenderer *renderer = gtk_cell_renderer_text_new ();
 +      GtkTreeViewColumn *column =
 +      gtk_tree_view_column_new_with_attributes ("var", renderer,
 +                                                "text", f,
 +                                                NULL);
 +      g_object_set (column,
 +                  "resizable", TRUE,
 +                  "sizing", GTK_TREE_VIEW_COLUMN_AUTOSIZE,
 +                  NULL);
++
 +      gtk_tree_view_append_column (GTK_TREE_VIEW (ia->fields_tree_view), column);
 +    }
 +}
 +
 +static void
 +reset_tree_view_model (PsppireImportAssistant *ia)
 +{
 +  GtkTreeModel *tm = gtk_tree_view_get_model (GTK_TREE_VIEW (ia->fields_tree_view));
 +  g_object_ref (tm);
 +  gtk_tree_view_set_model (GTK_TREE_VIEW (ia->fields_tree_view), NULL);
 +
 +
 +  repopulate_delimiter_columns (ia);
 +
 +  gtk_tree_view_set_model (GTK_TREE_VIEW (ia->fields_tree_view), tm);
 +  //  gtk_tree_view_columns_autosize (GTK_TREE_VIEW (ia->fields_tree_view));
 +
 +  g_object_unref (tm);
 +}
 +
  /* Called just before the separators page becomes visible in the
     assistant, and when the Reset button is clicked. */
  static void
  prepare_separators_page (PsppireImportAssistant *ia, GtkWidget *page)
  {
-      
 +  gtk_tree_view_set_model (GTK_TREE_VIEW (ia->fields_tree_view), ia->delimiters_model);
++
 +  g_signal_connect_swapped (ia->delimiters_model, "notify::delimiters",
 +                      G_CALLBACK (reset_tree_view_model), ia);
 +
 +
 +  repopulate_delimiter_columns (ia);
 +
    revise_fields_preview (ia);
    choose_likely_separators (ia);
    set_separators (ia);
  struct separator
  {
    const char *name;           /* Name (for use with get_widget_assert). */
 -  int c;                      /* Separator character. */
 +  gunichar c;                 /* Separator character. */
  };
  
  /* All the separators in the dialog box. */
@@@ -522,6 -478,23 +522,6 @@@ on_close (GtkAssistant *assistant, Pspp
  }
  
  
 -/* Frees IA's file substructure. */
 -static void
 -destroy_file (PsppireImportAssistant *ia)
 -{
 -  size_t i;
 -
 -  for (i = 0; i < ia->line_cnt; i++)
 -    ds_destroy (&ia->lines[i]);
 -
 -  g_free (ia->file_name);
 -  ia->file_name = NULL;
 -
 -  g_free (ia->encoding);
 -  ia->encoding = NULL;
 -}
 -
 -
  /* Increments the "watch cursor" level, setting the cursor for
     the assistant window to a watch face to indicate to the user
     that the ongoing operation may take some time. */
@@@ -551,7 -524,98 +551,7 @@@ pop_watch_cursor (PsppireImportAssistan
      }
  }
  
 -
 -static gboolean
 -process_file (PsppireImportAssistant *ia)
 -{
 -  struct string input;
 -  struct line_reader *reader = line_reader_for_file (ia->encoding, ia->file_name, O_RDONLY);
 -  if (reader == NULL)
 -    {
 -      msg_error (errno, _("Could not open `%s'"),
 -               ia->file_name);
 -      return FALSE;
 -    }
 -
 -  ds_init_empty (&input);
 -  for (ia->line_cnt = 0; ia->line_cnt < MAX_PREVIEW_LINES; ia->line_cnt++)
 -    {
 -      ds_clear (&input);
 -      if (!line_reader_read (reader, &input, MAX_LINE_LEN + 1)
 -        || ds_length (&input) > MAX_LINE_LEN)
 -      {
 -        if (line_reader_eof (reader))
 -          break;
 -        else if (line_reader_error (reader))
 -          msg (ME, _("Error reading `%s': %s"),
 -               ia->file_name, strerror (line_reader_error (reader)));
 -        else
 -          msg (ME, _("Failed to read `%s', because it contains a line "
 -                     "over %d bytes long and therefore appears not to be "
 -                     "a text file."),
 -               ia->file_name, MAX_LINE_LEN);
 -        line_reader_close (reader);
 -        destroy_file (ia);
 -        ds_destroy (&input);
 -        return FALSE;
 -      }
 -
 -      char *s = recode_string ("UTF-8", line_reader_get_encoding (reader),   ds_cstr (&input), ds_length (&input));
 -      ds_init_cstr (&ia->lines[ia->line_cnt], s);
 -      free (s);
 -    }
 -  ds_destroy (&input);
 -  if (ia->line_cnt == 0)
 -    {
 -      msg (ME, _("`%s' is empty."), ia->file_name);
 -      line_reader_close (reader);
 -      destroy_file (ia);
 -      return FALSE;
 -    }
 -
 -  /* Estimate the number of lines in the file. */
 -  if (ia->line_cnt < MAX_PREVIEW_LINES)
 -    {
 -      ia->total_lines = ia->line_cnt;
 -      ia->total_is_exact = true;
 -    }
 -  else
 -    {
 -      struct stat s;
 -      off_t position = line_reader_tell (reader);
 -      if (fstat (line_reader_fileno (reader), &s) == 0 && position > 0)
 -      {
 -        ia->total_lines = (double) ia->line_cnt / position * s.st_size;
 -        ia->total_is_exact = false;
 -      }
 -      else
 -      {
 -        ia->total_lines = 0;
 -        ia->total_is_exact = true;
 -      }
 -    }
 -  line_reader_close (reader);
 -  return TRUE;
 -}
 -
 -
 -static void
 -render_line_number (PsppSheetViewColumn *tree_column,
 -                    GtkCellRenderer *cell,
 -                    GtkTreeModel *tree_model,
 -                    GtkTreeIter *iter,
 -                    gpointer data)
 -{
 -  gint row = empty_list_store_iter_to_row (iter);
 -  char s[INT_BUFSIZE_BOUND (int)];
 -  int first_line = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (tree_model),
 -                                                     "first-line"));
 -  sprintf (s, "%d", first_line + row);
 -  g_object_set (cell, "text", s, NULL);
 -}
 -
 -
 -
 +#if SHEET_MERGE
  static gint
  get_string_width (GtkWidget *treeview, GtkCellRenderer *renderer,
                  const char *string)
    return width;
  }
  
 -
  static gint
  get_monospace_width (GtkWidget *treeview, GtkCellRenderer *renderer,
                       size_t char_cnt)
    return width;
  }
  
 -static void
 -add_line_number_column (const PsppireImportAssistant *ia,
 -                        GtkWidget *treeview)
 -{
 -  PsppSheetViewColumn *column =
 -    pspp_sheet_view_column_new_with_attributes (_("Line"), ia->prop_renderer, (void *) NULL);
 -
 -  pspp_sheet_view_column_set_fixed_width (column, get_monospace_width (treeview, ia->prop_renderer, 5));
 -
 -  pspp_sheet_view_column_set_resizable (column, TRUE);
 -
 -  pspp_sheet_view_column_set_cell_data_func (column, ia->prop_renderer,
 -                                             render_line_number, NULL, NULL);
 -
 -  pspp_sheet_view_append_column (PSPP_SHEET_VIEW (treeview), column);
 -}
 -
 -
  static void
  set_model_on_treeview (PsppireImportAssistant *ia, GtkWidget *tree_view, size_t first_line)
  {
    g_object_unref (model);
  }
  
 -
  static GtkWidget *
  make_tree_view (const PsppireImportAssistant *ia)
  {
  
    return tree_view;
  }
 +#endif
  
  static GtkWidget *
  add_page_to_assistant (PsppireImportAssistant *ia,
@@@ -641,6 -724,7 +641,6 @@@ prepare_sheet_spec_page (PsppireImportA
  }
  
  
 -
  /* Initializes IA's sheet_spec substructure. */
  static void
  sheet_spec_page_create (PsppireImportAssistant *ia)
    g_object_set_data (G_OBJECT (page), "on-entering", prepare_sheet_spec_page);
  }
  
 -
  static void
  on_chosen (PsppireImportAssistant *ia, GtkWidget *page)
  {
@@@ -712,16 -797,12 +712,16 @@@ on_map (PsppireImportAssistant *ia, Gtk
  {
    GtkFileChooser *fc = GTK_FILE_CHOOSER (page);
  
 +#if TEXT_FILE
    if (ia->file_name)
      gtk_file_chooser_set_filename (fc, ia->file_name);
 +#endif
  
    on_chosen (ia, page);
  }
  
 +
 +
  static void
  chooser_page_enter (PsppireImportAssistant *ia, GtkWidget *page)
  {
  static void
  chooser_page_leave (PsppireImportAssistant *ia, GtkWidget *page)
  {
 -
 -  if (ia->file_name)
 -    g_free (ia->file_name);
 -  ia->file_name = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (page));
 -
 -  if (ia->encoding)
 -    g_free (ia->encoding);
 -  ia->encoding = psppire_encoding_selector_get_encoding (ia->encoding_selector);
 +  g_print ("%s:%d %s\n", __FILE__, __LINE__, __FUNCTION__);
 +  gchar *file_name = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (page));
 +  gchar *encoding = psppire_encoding_selector_get_encoding (ia->encoding_selector);
  
    if (!ia->spreadsheet)
 -    process_file (ia);
 +    {
 +      ia->text_file = psppire_text_file_new (file_name, encoding);
 +      gtk_tree_view_set_model (GTK_TREE_VIEW (ia->first_line_tree_view),
 +                             GTK_TREE_MODEL (ia->text_file));
 +    }
 +
 +  g_free (file_name);
 +  g_free (encoding);
  }
  
  static void
@@@ -756,8 -835,6 +756,8 @@@ chooser_page_reset (PsppireImportAssist
    on_chosen (ia, page);
  }
  
 +
 +
  static void
  chooser_page_create (PsppireImportAssistant *ia)
  {
  }
  
  
 +
  static void
  psppire_import_assistant_init (PsppireImportAssistant *ia)
  {
    ia->column_cnt = 0;
    ia->columns = NULL;
  
 -  ia->file_name = NULL;
 -  ia->encoding = NULL;
    ia->spreadsheet = NULL;
    ia->watch_cursor = 0;
  
@@@ -911,12 -989,34 +911,12 @@@ on_intro_amount_changed (PsppireImportA
                                                          GTK_TOGGLE_BUTTON (p->percent_button)));
  }
  
 -
 -static void
 -render_line (PsppSheetViewColumn *tree_column,
 -             GtkCellRenderer *cell,
 -             GtkTreeModel *tree_model,
 -             GtkTreeIter *iter,
 -             gpointer data)
 -{
 -  gint row = empty_list_store_iter_to_row (iter);
 -  struct string *lines;
 -
 -  lines = g_object_get_data (G_OBJECT (tree_model), "lines");
 -  g_return_if_fail (lines != NULL);
 -
 -  g_object_set (cell, "text", ds_cstr (&lines[row]), NULL);
 -}
 -
  /* Sets the widgets to match IA's first_line substructure. */
  static void
  set_first_line (PsppireImportAssistant *ia)
  {
    GtkTreePath *path = gtk_tree_path_new_from_indices (ia->skip_lines, -1);
  
 -
 -  set_model_on_treeview (ia, ia->tree_view, 0);
 -
 -  pspp_sheet_view_set_cursor (PSPP_SHEET_VIEW (ia->tree_view),
 -                            path, NULL, false);
    gtk_tree_path_free (path);
  
    gtk_toggle_button_set_active (
                              ia->skip_lines > 0);
  }
  
 -
 -/* Creates and returns a tree view that contains each of the
 -   lines in IA's file as a row. */
 -static GtkWidget *
 -create_lines_tree_view (GtkContainer *parent, PsppireImportAssistant *ia)
 -{
 -  size_t max_line_length;
 -  gint content_width, header_width;
 -  size_t i;
 -  const gchar *title = _("Text");
 -  GtkWidget *tree_view = make_tree_view (ia);
 -  PsppSheetViewColumn *column =
 -    pspp_sheet_view_column_new_with_attributes (title,
 -                                              ia->fixed_renderer, (void *) NULL);
 -
 -  pspp_sheet_view_column_set_cell_data_func (column, ia->fixed_renderer,
 -                                           render_line, NULL, NULL);
 -  pspp_sheet_view_column_set_resizable (column, TRUE);
 -  pspp_sheet_view_column_set_expand (column, TRUE);
 -
 -  max_line_length = 0;
 -  for (i = 0; i < ia->line_cnt; i++)
 -    {
 -      size_t w = ds_length (&ia->lines[i]);
 -      max_line_length = MAX (max_line_length, w);
 -    }
 -
 -  content_width = get_monospace_width (tree_view, ia->fixed_renderer,
 -                                       max_line_length);
 -  header_width = get_string_width (tree_view, ia->prop_renderer, title);
 -  pspp_sheet_view_column_set_fixed_width (column, MAX (content_width,
 -                                                     header_width));
 -  pspp_sheet_view_append_column (PSPP_SHEET_VIEW (tree_view), column);
 -
 -  GtkWidget *oldtv = gtk_bin_get_child (GTK_BIN (parent));
 -  if (oldtv)
 -    gtk_container_remove (parent, oldtv);
 -
 -  gtk_container_add (parent, tree_view);
 -  gtk_widget_show (tree_view);
 -
 -  return tree_view;
 -}
 +#if SHEET_MERGE
  
  
  /* Sets IA's first_line substructure to match the widgets. */
@@@ -952,8 -1094,6 +952,8 @@@ set_first_line_options (PsppireImportAs
    gtk_widget_set_sensitive (ia->variable_names_cb, ia->skip_lines > 0);
  }
  
 +
 +
  static void
  reset_first_line_page (PsppireImportAssistant *ia)
  {
    gtk_widget_set_sensitive (ia->variable_names_cb, FALSE);
  }
  
-       
 +#endif
 +
 +static void
 +on_cursor_change (GtkTreeView *treeview, gpointer user_data)
 +{
 +  PsppireImportAssistant *ia = PSPPIRE_IMPORT_ASSISTANT (user_data);
 +  GtkTreeSelection *selection = gtk_tree_view_get_selection (treeview);
 +  GtkTreeModel *model = NULL;
 +  GtkTreeIter iter;
 +  if (gtk_tree_selection_get_selected (selection, &model, &iter))
 +    {
 +      int n;
 +      PsppireTextFile *tf = PSPPIRE_TEXT_FILE (model);
 +      GtkTreePath *path = gtk_tree_model_get_path (model, &iter);
 +      gint *index = gtk_tree_path_get_indices (path);
-       
++
 +      n = *index;
++
 +      gtk_tree_path_free (path);
 +
 +      g_print ("%s:%d Setting first line to %d\n", __FILE__, __LINE__, n);
 +
 +      ia->delimiters_model = psppire_delimited_text_new (ia->text_file);
 +      g_object_set (ia->delimiters_model, "first-line", n, NULL);
 +    }
 +}
 +
  
  /* Initializes IA's first_line substructure. */
  static void
  first_line_page_create (PsppireImportAssistant *ia)
  {
 +  g_print ("%s:%d %s\n", __FILE__, __LINE__, __FUNCTION__);
    GtkWidget *w =  get_widget_assert (ia->builder, "FirstLine");
  
    g_object_set_data (G_OBJECT (w), "on-entering", set_first_line);
    add_page_to_assistant (ia, w,
                         GTK_ASSISTANT_PAGE_CONTENT, _("Select the First Line"));
  
 -  ia->tree_view = GTK_WIDGET (create_lines_tree_view (
 -                                                    GTK_CONTAINER (get_widget_assert (ia->builder, "first-line-scroller")), ia));
 +  GtkWidget *scrolled_window = get_widget_assert (ia->builder, "first-line-scroller");
 +
 +  if (ia->first_line_tree_view == NULL)
 +    {
 +      ia->first_line_tree_view = gtk_tree_view_new ();
 +
 +      gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (ia->first_line_tree_view), TRUE);
 +
 +      GtkCellRenderer *renderer = gtk_cell_renderer_text_new ();
 +      GtkTreeViewColumn *column = gtk_tree_view_column_new_with_attributes (_("Line"), renderer,
 +                                                                          "text", 0,
 +                                                                          NULL);
 +      gtk_tree_view_append_column (GTK_TREE_VIEW (ia->first_line_tree_view), column);
 +
 +      renderer = gtk_cell_renderer_text_new ();
 +      column = gtk_tree_view_column_new_with_attributes (_("Text"), renderer, "text", 1, NULL);
 +      gtk_tree_view_append_column (GTK_TREE_VIEW (ia->first_line_tree_view), column);
 +
 +      gtk_container_add (GTK_CONTAINER (scrolled_window), ia->first_line_tree_view);
 +
 +      g_signal_connect (ia->first_line_tree_view, "cursor-changed",
 +                      G_CALLBACK (on_cursor_change), ia);
 +    }
 +  gtk_widget_show_all (scrolled_window);
 +
 +
 +
 +#if SHEET_MERGE
    ia->variable_names_cb = get_widget_assert (ia->builder, "variable-names");
    pspp_sheet_selection_set_mode (
                                 pspp_sheet_view_get_selection (PSPP_SHEET_VIEW (ia->tree_view)),
  
  
    g_object_set_data (G_OBJECT (w), "on-reset", reset_first_line_page);
 +#endif
  }
  
  
 +
 +
  static void
  intro_on_enter (PsppireImportAssistant *ia)
  {
  
    struct string s;
  
 -  if (ia->line_cnt > MAX_PREVIEW_LINES)
 -    ia->line_cnt = MAX_PREVIEW_LINES;
 -
    ds_init_empty (&s);
    ds_put_cstr (&s, _("This assistant will guide you through the process of "
                       "importing data into PSPP from a text file with one line "
                       "per case,  in which fields are separated by tabs, "
                       "commas, or other delimiters.\n\n"));
  
 -  if (ia->total_is_exact)
 +  if (ia->text_file)
      {
 -      ds_put_format (
 -                   &s, ngettext ("The selected file contains %'lu line of text.  ",
 -                                 "The selected file contains %'lu lines of text.  ",
 -                                 ia->total_lines),
 -                   ia->total_lines);
 -    }
 -  else if (ia->total_lines > 0)
 -    {
 -      ds_put_format (
 -                   &s, ngettext (
 -                                 "The selected file contains approximately %'lu line of text.  ",
 -                                 "The selected file contains approximately %'lu lines of text.  ",
 -                                 ia->total_lines),
 -                   ia->total_lines);
 -      ds_put_format (
 -                   &s, ngettext (
 -                                 "Only the first %zu line of the file will be shown for "
 -                                 "preview purposes in the following screens.  ",
 -                                 "Only the first %zu lines of the file will be shown for "
 -                                 "preview purposes in the following screens.  ",
 -                                 ia->line_cnt),
 -                   ia->line_cnt);
 +      if (ia->text_file->total_is_exact)
 +      {
 +        ds_put_format (
 +                       &s, ngettext ("The selected file contains %'lu line of text.  ",
 +                                     "The selected file contains %'lu lines of text.  ",
 +                                     ia->text_file->total_lines),
 +                       ia->text_file->total_lines);
 +      }
 +      else if (ia->text_file->total_lines > 0)
 +      {
 +        ds_put_format (
 +                       &s, ngettext (
 +                                     "The selected file contains approximately %'lu line of text.  ",
 +                                     "The selected file contains approximately %'lu lines of text.  ",
 +                                     ia->text_file->total_lines),
 +                       ia->text_file->total_lines);
 +        ds_put_format (
 +                       &s, ngettext (
 +                                     "Only the first %zu line of the file will be shown for "
 +                                     "preview purposes in the following screens.  ",
 +                                     "Only the first %zu lines of the file will be shown for "
 +                                     "preview purposes in the following screens.  ",
 +                                     ia->text_file->line_cnt),
 +                       ia->text_file->line_cnt);
 +      }
      }
  
    ds_put_cstr (&s, _("You may choose below how much of the file should "
  
    GtkAdjustment *adj = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (ia->n_cases_spin));
    gtk_adjustment_set_lower (adj, 1.0);
 -  if (ia->total_is_exact)
 -    gtk_adjustment_set_value (adj, old_value);
 -  if (ia->total_is_exact)
 -    gtk_adjustment_set_upper (adj, ia->total_lines);
 -  else
 -    gtk_adjustment_set_upper (adj, DBL_MAX);
  
 +  if (ia->text_file)
 +    {
 +      if (psppire_text_file_get_total_exact (ia->text_file))
 +      {
 +        gulong total_lines = psppire_text_file_get_n_lines (ia->text_file);
 +        gtk_adjustment_set_upper (adj, total_lines);
 +        gtk_adjustment_set_value (adj, old_value);
 +      }
 +      else
 +      gtk_adjustment_set_upper (adj, DBL_MAX);
 +    }
    gtk_grid_attach (GTK_GRID (table), hbox_n_cases,
                   1, 1,
                   1, 1);
@@@ -1185,8 -1263,6 +1185,8 @@@ psppire_import_assistant_new (GtkWindo
                                   NULL));
  }
  
 +
 +
  \f
  
  struct column
@@@ -1227,8 -1303,6 +1227,8 @@@ destroy_columns (PsppireImportAssistan
    free (ia->columns);
  }
  
 +#if SHEET_MERGE
 +
  /* Called to render one of the cells in the fields preview tree
     view. */
  static void
@@@ -1262,7 -1336,6 +1262,7 @@@ render_input_cell (PsppSheetViewColumn 
                    (void *) NULL);
  }
  
 +#endif
  
  /* Parses the contents of the field at (ROW,COLUMN) according to
     its variable format.  If OUTPUTP is non-null, then *OUTPUTP
@@@ -1322,7 -1395,6 +1322,7 @@@ parse_field (PsppireImportAssistant *ia
    return ok;
  }
  
 +#if SHEET_MERGE
  
  /* Called to render one of the cells in the data preview tree
     view. */
@@@ -1393,7 -1465,6 +1393,7 @@@ get_tooltip_location (GtkWidget *widget
  }
  
  
 +
  \f
  
  
@@@ -1442,7 -1513,7 +1442,7 @@@ on_query_output_tooltip (GtkWidget *wid
    free (text);
    return TRUE;
  }
 -
 +#endif
  \f
  
  
@@@ -1506,7 -1577,42 +1506,7 @@@ get_separators (PsppireImportAssistant 
  
  
  
 -/* Frees and clears the column data in IA's separators
 -   substructure. */
 -static void
 -clear_fields (PsppireImportAssistant *ia)
 -{
 -  if (ia->column_cnt > 0)
 -    {
 -      struct column *col;
 -      size_t row;
 -
 -      for (row = 0; row < ia->line_cnt; row++)
 -        {
 -          const struct string *line = &ia->lines[row];
 -          const char *line_start = ds_data (line);
 -          const char *line_end = ds_end (line);
 -
 -          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))
 -                ss_dealloc (&col->contents[row]);
 -            }
 -        }
 -
 -      for (col = ia->columns; col < &ia->columns[ia->column_cnt]; col++)
 -        {
 -          free (col->name);
 -          free (col->contents);
 -        }
 -
 -      free (ia->columns);
 -      ia->columns = NULL;
 -      ia->column_cnt = 0;
 -    }
 -}
 -
 +#if SHEET_MERGE
  
  /* Breaks the file data in IA into columns based on the
     separators set in IA's separators substructure. */
@@@ -1515,7 -1621,9 +1515,7 @@@ split_fields (PsppireImportAssistant *i
  {
    size_t columns_allocated;
    bool space_sep;
 -  size_t row;
 -
 -  clear_fields (ia);
 +  size_t row = 0;
  
    /* Is space in the set of separators? */
    space_sep = ss_find_byte (ds_ss (&ia->separators), ' ') != SIZE_MAX;
       contains variables names if ia->first_line.variable_names is
       TRUE. */
    columns_allocated = 0;
 -  for (row = 0; row < ia->line_cnt; row++)
 +
 +  gint n_lines = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (ia->text_file), NULL);
 +  GtkTreeIter iter;
 +  gtk_tree_model_get_iter_first (GTK_TREE_MODEL (ia->text_file), &iter);
 +  while (gtk_tree_model_iter_next (GTK_TREE_MODEL (ia->text_file), &iter))
      {
 -      struct string *line = &ia->lines[row];
 -      struct substring text = ds_ss (line);
 +      row++;
 +      gchar *xxx;
 +      gtk_tree_model_get (GTK_TREE_MODEL (ia->text_file), &iter, 1, &xxx, -1);
 +      struct substring text = ss_cstr (xxx);
 +      g_free (xxx);
        size_t column_idx;
  
 -      for (column_idx = 0; ; column_idx++)
 +      for (column_idx = 0; ;column_idx++)
          {
            struct substring field = SS_EMPTY_INITIALIZER;
            struct column *column;
                column = &ia->columns[ia->column_cnt++];
                column->name = NULL;
                column->width = 0;
 -              column->contents = xcalloc (ia->line_cnt,
 +              column->contents = xcalloc (n_lines,
                                            sizeof *column->contents);
              }
            column = &ia->columns[column_idx];
      }
  }
  
 -static PsppSheetViewColumn *
 -make_data_column (PsppireImportAssistant *ia, GtkWidget *tree_view,
 -                  bool input, gint dict_idx)
 -{
 -  struct variable *var = NULL;
 -  struct column *column = NULL;
 -  size_t char_cnt = 0;
 -  gint content_width, header_width;
 -  PsppSheetViewColumn *tree_column;
 -  char *name = NULL;
 -
 -  if (input)
 -    {
 -      column = &ia->columns[dict_idx];
 -      name = escape_underscores (column->name);
 -      char_cnt = column->width;
 -    }
 -  else
 -    {
 -      var = dict_get_var (ia->dict, dict_idx);
 -      name = escape_underscores (var_get_name (var));
 -      char_cnt = var_get_print_format (var)->w;
 -    }
 -
 -  content_width = get_monospace_width (tree_view, ia->fixed_renderer,
 -                                       char_cnt);
 -  header_width = get_string_width (tree_view, ia->prop_renderer,
 -                                   name);
 -
 -  tree_column = pspp_sheet_view_column_new ();
 -  g_object_set_data (G_OBJECT (tree_column), "column-number",
 -                     GINT_TO_POINTER (dict_idx));
 -  pspp_sheet_view_column_set_title (tree_column, name);
 -  pspp_sheet_view_column_pack_start (tree_column, ia->fixed_renderer,
 -                                     FALSE);
 -  pspp_sheet_view_column_set_cell_data_func (
 -                                           tree_column, ia->fixed_renderer,
 -                                           input ? render_input_cell : render_output_cell, ia, NULL);
 -  pspp_sheet_view_column_set_fixed_width (tree_column, MAX (content_width,
 -                                                            header_width));
 -
 -  free (name);
 -
 -  return tree_column;
 -}
 -
 -
 -static GtkWidget *
 -create_data_tree_view (gboolean input, GtkContainer *parent,
 -                       PsppireImportAssistant *ia)
 -{
 -  gint i;
 -  GtkWidget *tree_view = make_tree_view (ia);
 -
 -  set_model_on_treeview (ia, tree_view, ia->skip_lines);
 -
 -  pspp_sheet_selection_set_mode (pspp_sheet_view_get_selection (PSPP_SHEET_VIEW (tree_view)),
 -                                 PSPP_SHEET_SELECTION_NONE);
 -
 -  for (i = 0; i < ia->column_cnt; i++)
 -    {
 -      PsppSheetViewColumn *w = make_data_column (ia, tree_view, input, i);
 -
 -      pspp_sheet_view_append_column (PSPP_SHEET_VIEW (tree_view), w);
 -    }
 -
 -  g_object_set (G_OBJECT (tree_view), "has-tooltip", TRUE, (void *) NULL);
 -  g_signal_connect (tree_view, "query-tooltip",
 -                    G_CALLBACK (input ? on_query_input_tooltip
 -                                : on_query_output_tooltip), ia);
 -
 -  GtkWidget *child = gtk_bin_get_child (GTK_BIN (parent));
 -  if (child)
 -    {
 -      g_object_ref (child);
 -      gtk_container_remove (parent, child);
 -    }
 -  gtk_container_add (parent, tree_view);
 -  if (child)
 -    g_object_unref (child);
 -
 -  gtk_widget_show (tree_view);
 -
 -  return tree_view;
 -}
 -
 +#endif
  
  /* Chooses a name for each column on the separators page */
  static void
@@@ -1642,24 -1828,9 +1642,24 @@@ static voi
  on_separator_toggle (GtkToggleButton *toggle UNUSED,
                       PsppireImportAssistant *ia)
  {
 -  revise_fields_preview (ia);
 +  int i;
 +  GSList *delimiters = NULL;
 +  for (i = 0; i < SEPARATOR_CNT; i++)
 +    {
 +      const struct separator *s = &separators[i];
 +      GtkWidget *button = get_widget_assert (ia->builder, s->name);
 +      if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
 +      {
 +        delimiters = g_slist_prepend (delimiters,  GINT_TO_POINTER (s->c));
 +      }
 +    }
 +
 +  g_object_set (ia->delimiters_model, "delimiters", delimiters, NULL);
 +
 +  //  revise_fields_preview (ia);
  }
  
 +
  /* Called when the user changes the entry field for custom
     separators. */
  static void
@@@ -1686,7 -1857,7 +1686,7 @@@ on_separators_custom_cb_toggle (GtkTogg
  static void
  on_quote_combo_change (GtkComboBox *combo, PsppireImportAssistant *ia)
  {
 -  revise_fields_preview (ia);
 +  //  revise_fields_preview (ia);
  }
  
  /* Called when the user toggles the checkbox that enables
@@@ -1712,6 -1883,7 +1712,6 @@@ separators_page_create (PsppireImportAs
    g_object_set_data (G_OBJECT (w), "on-entering", prepare_separators_page);
    g_object_set_data (G_OBJECT (w), "on-reset", prepare_separators_page);
  
 -
    add_page_to_assistant (ia, w,   GTK_ASSISTANT_PAGE_CONTENT, _("Choose Separators"));
  
    ia->custom_cb = get_widget_assert (builder, "custom-cb");
    ia->quote_cb = get_widget_assert (builder, "quote-cb");
  
    set_quote_list (GTK_COMBO_BOX (ia->quote_combo));
 -  ia->fields_tree_view = NULL;
 +
 +  if (ia->fields_tree_view == NULL)
 +    {
 +      GtkWidget *scroller = get_widget_assert (ia->builder, "fields-scroller");
 +      ia->fields_tree_view = gtk_tree_view_new ();
 +      gtk_container_add (GTK_CONTAINER (scroller), GTK_WIDGET (ia->fields_tree_view));
 +      gtk_widget_show_all (scroller);
 +    }
  
    g_signal_connect (ia->quote_combo, "changed",
                      G_CALLBACK (on_quote_combo_change), ia);
    for (i = 0; i < SEPARATOR_CNT; i++)
      g_signal_connect (get_widget_assert (builder, separators[i].name),
                        "toggled", G_CALLBACK (on_separator_toggle), ia);
 +
  }
  
  
  
  \f
 +
 +#if SHEET_MERGE
 +
  /* Called when the user changes one of the variables in the
     dictionary. */
  static void
@@@ -1788,7 -1949,7 +1788,7 @@@ on_variable_change (PsppireDict *dict, 
    pop_watch_cursor (ia);
  }
  
 -
 +#endif
  
  
  /* Called just before the formats page of the assistant is
  static void
  prepare_formats_page (PsppireImportAssistant *ia)
  {
 -  PsppireDict *psppire_dict = NULL;
 -  PsppireVarSheet *var_sheet;
 -  GtkBin *vars_scroller;
 -  GtkWidget *old_var_sheet;
 -
 -
 -  push_watch_cursor (ia);
 -
 -  if (ia->spreadsheet == NULL)
 -    {
 -      struct fmt_guesser *fg;
 -      unsigned long int number = 0;
 -      size_t column_idx;
 -
 -
 -      ia->dict = dict_create (get_default_encoding ());
 -      fg = fmt_guesser_create ();
 -      for (column_idx = 0; column_idx < ia->column_cnt; column_idx++)
 -      {
 -        struct variable *modified_var =
 -          (column_idx < ia->modified_var_cnt ? ia->modified_vars[column_idx] : NULL);
 -
 -        if (modified_var == NULL)
 -          {
 -            struct column *column = &ia->columns[column_idx];
 -            struct variable *var;
 -            struct fmt_spec format;
 -            char *name;
 -            size_t row;
 -
 -            /* Choose variable name. */
 -            name = dict_make_unique_var_name (ia->dict, column->name, &number);
 -
 -            /* Choose variable format. */
 -            fmt_guesser_clear (fg);
 -            for (row = ia->skip_lines; row < ia->line_cnt; row++)
 -              fmt_guesser_add (fg, column->contents[row]);
 -            fmt_guesser_guess (fg, &format);
 -            fmt_fix_input (&format);
 -
 -            /* Create variable. */
 -            var = dict_create_var_assert (ia->dict, name, fmt_var_width (&format));
 -            var_set_both_formats (var, &format);
 -
 -            free (name);
 -          }
 -        else
 -          {
 -            char *name;
 -
 -            name = dict_make_unique_var_name (ia->dict, var_get_name (modified_var),
 -                                              &number);
 -            dict_clone_var_as_assert (ia->dict, modified_var, name);
 -            free (name);
 -          }
 -      }
 -      fmt_guesser_destroy (fg);
 -    }
 -  else
 -    {
 -      int row_start = -1;
 -      int row_stop = -1;
 -      int col_start = -1;
 -      int col_stop = -1;
 -
 -      GtkBuilder *builder = ia->builder;
 -
 -      struct casereader *reader = NULL;
 -
 -      GtkWidget *readnames_checkbox = get_widget_assert (builder, "readnames-checkbox");
 -      GtkWidget *range_entry = get_widget_assert (builder, "cell-range-entry");
 -      const gchar *range = gtk_entry_get_text (GTK_ENTRY (range_entry));
 -      GtkWidget *combo_box = get_widget_assert (builder, "sheet-entry");
 -
 -      gint num = gtk_combo_box_get_active (GTK_COMBO_BOX (combo_box));
 -
 -      struct spreadsheet_read_options sro;
 -
 -      sro.sheet_name = NULL;
 -      sro.cell_range = NULL;
 -      sro.sheet_index = num + 1;
 -
 -      if ( convert_cell_ref (range, &col_start, &row_start, &col_stop, &row_stop))
 -      {
 -        sro.cell_range = g_strdup (range);
 -      }
 -
 -      sro.read_names = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (readnames_checkbox));
 -      sro.asw = -1;
 -
 -      switch (ia->spreadsheet->type)
 -      {
 -      case SPREADSHEET_ODS:
 -      case SPREADSHEET_GNUMERIC:
 -        {
 -          reader = spreadsheet_make_reader (ia->spreadsheet, &sro);
 -          ia->dict = dict_clone (ia->spreadsheet->dict);
 -        }
 -        break;
 -      default:
 -        g_assert_not_reached ();
 -        break;
 -      }
 -      g_free (sro.cell_range);
 -
 -      if (reader && ia->dict)
 -      {
 -        struct ccase *c;
 -        int col;
 -
 -        ia->column_cnt = dict_get_var_cnt (ia->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 (ia->dict, col);
 -            ia->columns[col].name = xstrdup (var_get_name (var));
 -            ia->columns[col].contents = NULL;
 -          }
 -
 -        casenumber rows = 0;
 -        for (; (c = casereader_read (reader)) != NULL; case_unref (c))
 -          {
 -            rows++;
 -            for (col = 0; col < ia->column_cnt ; ++col)
 -              {
 -                char *ss;
 -                const struct variable *var = dict_get_var (ia->dict, col);
 -
 -                ia->columns[col].contents = xrealloc (ia->columns[col].contents,
 -                                                      sizeof (struct substring) * rows);
 -
 -                ss = data_out (case_data (c, var), dict_get_encoding (ia->dict),
 -                               var_get_print_format (var));
 -
 -                ia->columns[col].contents[rows - 1] = ss_cstr (ss);
 -              }
 -
 -            if (rows > MAX_PREVIEW_LINES)
 -              {
 -                case_unref (c);
 -                break;
 -              }
 -          }
 -        casereader_destroy (reader);
 -        ia->line_cnt = rows;
 -      }
 -      else
 -      {
 -        GtkWidget * dialog = gtk_message_dialog_new (NULL,
 -                                                     GTK_DIALOG_MODAL,
 -                                                     GTK_MESSAGE_ERROR,
 -                                                     GTK_BUTTONS_CLOSE,
 -                                                     _("An error occurred reading the spreadsheet file."));
 -
 -        gtk_dialog_run (GTK_DIALOG (dialog));
 -        gtk_widget_destroy (dialog);
 -      }
 -    }
 -
 -  psppire_dict = psppire_dict_new_from_dict (ia->dict);
 -  g_signal_connect (psppire_dict, "variable-changed",
 -                  G_CALLBACK (on_variable_change), ia);
 -  ia->psppire_dict = psppire_dict;
 -
 -
 -  /* XXX: PsppireVarStore doesn't hold a reference to
 -     psppire_dict for now, but it should.  After it does, we
 -     should g_object_ref the psppire_dict here, since we also
 -     hold a reference via ia->formats->dict. */
 -  var_sheet = PSPPIRE_VAR_SHEET (psppire_var_sheet_new ());
 -  g_object_set (var_sheet,
 -              "dictionary", psppire_dict,
 -              "may-create-vars", FALSE,
 -              "may-delete-vars", FALSE,
 -              "format-use", FMT_FOR_INPUT,
 -              "enable-grid-lines", PSPP_SHEET_VIEW_GRID_LINES_BOTH,
 -              (void *) NULL);
 -
 -  vars_scroller = GTK_BIN (get_widget_assert (ia->builder, "vars-scroller"));
 -  old_var_sheet = gtk_bin_get_child (GTK_BIN (vars_scroller));
 -  if (old_var_sheet != NULL)
 -    gtk_container_remove (GTK_CONTAINER (vars_scroller),  old_var_sheet);
 -  gtk_container_add (GTK_CONTAINER (vars_scroller), GTK_WIDGET (var_sheet));
 -  gtk_widget_show (GTK_WIDGET (var_sheet));
 -
 -  ia->data_tree_view =
 -    GTK_WIDGET (create_data_tree_view (
 -                                     FALSE,
 -                                     GTK_CONTAINER (get_widget_assert (ia->builder, "data-scroller")),
 -                                     ia));
 -
 -  gtk_widget_show (ia->paste_button);
 -
 -  pop_watch_cursor (ia);
  }
  
  static void
@@@ -1980,8 -2335,6 +1980,8 @@@ sheet_spec_gen_syntax (PsppireImportAss
  
    struct string s = DS_EMPTY_INITIALIZER;
  
 +  char *filename;
 +  g_object_get (ia->text_file, "file-name", &filename, NULL);
    syntax_gen_pspp (&s,
                   "GET DATA"
                   "\n  /TYPE=%ss"
                   "\n  /SHEET=index %d"
                   "\n  /READNAMES=%ss",
                   (ia->spreadsheet->type == SPREADSHEET_GNUMERIC) ? "GNM" : "ODS",
 -                 ia->file_name,
 +                 filename,
                   sheet_index,
                   read_names ? "ON" : "OFF");
  
 -
    if (range && 0 != strcmp ("", range))
      {
        syntax_gen_pspp (&s,
    return ds_cstr (&s);
  }
  
 +
  gchar *
  psppire_import_assistant_generate_syntax (PsppireImportAssistant *ia)
  {
  
    if (!ia->spreadsheet)
      {
 -      if (ia->file_name == NULL)
 +      gchar *file_name = NULL;
 +      gchar *encoding = NULL;
 +      g_object_get (ia->text_file,
 +                  "filename", &file_name,
 +                  "encoding", &encoding,
 +                  NULL);
 +
 +      if (file_name == NULL)
        return NULL;
  
        syntax_gen_pspp (&s,
                       "GET DATA"
                       "\n  /TYPE=TXT"
                       "\n  /FILE=%sq\n",
 -                     ia->file_name);
 -      if (ia->encoding && strcmp (ia->encoding, "Auto"))
 -      syntax_gen_pspp (&s, "  /ENCODING=%sq\n", ia->encoding);
 +                     file_name);
 +      if (encoding && strcmp (encoding, "Auto"))
 +      syntax_gen_pspp (&s, "  /ENCODING=%sq\n", encoding);
  
        ds_put_cstr (&s,
                   "  /ARRANGEMENT=DELIMITED\n"
index dc52c7aeb66cd09ca6ee656b1fc4a79564d4a498,fe8040130d103adb1eb0c3ad2b92339b86422dc9..44dffdc7d908ef098b72a1b0eabd5e0803bcf0bb
@@@ -26,7 -26,6 +26,7 @@@
  #include "libpspp/str.h"
  #include "psppire-dict.h"
  #include "data/spreadsheet-reader.h"
 +#include "psppire-text-file.h"
  
  G_BEGIN_DECLS
  
@@@ -59,8 -58,12 +59,8 @@@ typedef struct _PsppireImportAssistan
  typedef struct _PsppireImportAssistantClass  PsppireImportAssistantClass;
  
  
 -struct first_line_page;
 -
  typedef void page_func (PsppireImportAssistant *, GtkWidget *page);
  
 -enum { MAX_PREVIEW_LINES = 1000 }; /* Max number of lines to read. */
 -
  struct _PsppireImportAssistant
  {
    GtkAssistant parent;
@@@ -74,7 -77,7 +74,7 @@@
    GtkFileFilter *default_filter;
    /* END The chooser page of the assistant. */
  
-   
    /* START The introduction page of the assistant. */
      GtkWidget *all_cases_button;
      GtkWidget *n_cases_button;
  
  
    /* START first line page */
 -  GtkWidget *tree_view;
 +  GtkWidget *first_line_tree_view;
    GtkWidget *variable_names_cb;
    /* END first line page */
  
    GtkCellRenderer *prop_renderer;
    GtkCellRenderer *fixed_renderer;
  
 -  // START     struct file file;
 -  char *file_name;        /* File name. */
 -
 -  /* Relevant only for text files */
 -
 -  gchar *encoding;        /* Encoding. */
 -  unsigned long int total_lines; /* Number of lines in file. */
 -  gboolean total_is_exact;    /* Is total_lines exact (or an estimate)? */
 -
 -  /* The first several lines of the file. */
 -  struct string lines[MAX_PREVIEW_LINES];
 -  size_t line_cnt;
 -
 -  // END     struct file file;
 +  PsppireTextFile *text_file;
  
 +  GtkTreeModel *delimiters_model;
 +  
    struct sheet_spec_page *sheet_spec;
 -  struct first_line_page *first_line;
  
    /* The columns produced. */
    struct column *columns;     /* Information about each column. */
diff --combined src/ui/gui/widgets.c
index da62642870f01f05ae2b70bef2094d84637b631e,37d13bf9723198f4d8a664de2370d207f2b9f240..e969eb5ae21c3fd4a69a50def4e5c83cfefeb388
@@@ -4,7 -4,6 +4,7 @@@
  
  #include "widgets.h"
  
 +#include "gettext.h"
  
  #include "psppire-dialog.h"
  #include "psppire-selector.h"
@@@ -121,65 -120,9 +121,65 @@@ preregister_actions (void
  }
  
  
 +static void
 +tx_string_to_double (const GValue *src, GValue *dest)
 +{
 +  const gchar *str = g_value_get_string (src);
 +  gdouble dble = g_strtod (str, NULL);
 +  g_value_set_double (dest, dble);
 +}
 +
 +
 +static void
 +tx_string_to_int (const GValue *src, GValue *dest)
 +{
 +  const gchar *str = g_value_get_string (src);
 +  gint x = atoi (str);
 +  g_value_set_int (dest, x);
 +}
 +
 +static void
 +enum_to_string (const GValue *src, GValue *dest)
 +{
 +  gint n = g_value_get_enum (src);
 +  GType t = G_VALUE_TYPE (src);
 +  GEnumClass *ec = g_type_class_ref (t);
 +  GEnumValue *ev = g_enum_get_value (ec, n);
 +
 +  g_value_set_string (dest, gettext (ev->value_nick));
 +}
 +
 +
 +
 +GType align_enum_type;
 +GType measure_enum_type;
 +GType role_enum_type;
 +
 +
 +extern const GEnumValue align[];
 +extern const GEnumValue measure[];
 +extern const GEnumValue role[];
 +
 +
 +
 +static void
 +preregister_misc (void)
 +{
 +  align_enum_type = g_enum_register_static ("PsppAlignment", align);
 +  measure_enum_type = g_enum_register_static ("PsppMeasure", measure);
 +  role_enum_type = g_enum_register_static ("PsppRole", role);
 +
 +  g_value_register_transform_func (G_TYPE_STRING, G_TYPE_DOUBLE, tx_string_to_double);
 +  g_value_register_transform_func (G_TYPE_STRING, G_TYPE_INT, tx_string_to_int);
 +  
 +  g_value_register_transform_func (measure_enum_type, G_TYPE_STRING, enum_to_string);
 +  g_value_register_transform_func (align_enum_type, G_TYPE_STRING, enum_to_string);
 +  g_value_register_transform_func (role_enum_type, G_TYPE_STRING, enum_to_string);
 +}
 +
  
  /* Any custom widgets which are to be used in GtkBuilder ui files
-    need to be preregistered, otherwise GtkBuilder refuses to 
+    need to be preregistered, otherwise GtkBuilder refuses to
     acknowledge their existence. */
  void
  preregister_widgets (void)
    psppire_means_layer_get_type ();
  
    preregister_actions ();
 +  preregister_misc ();
  
    /* This seems to be necessary on Cygwin.
       It ought not to be necessary.  Having it here can't do any harm. */