PsppireDelimitedText: use the maximum_lines property of the child as the number of...
authorJohn Darrington <john@darrington.wattle.id.au>
Mon, 5 Jun 2017 16:12:19 +0000 (18:12 +0200)
committerJohn Darrington <john@darrington.wattle.id.au>
Tue, 6 Jun 2017 05:58:29 +0000 (07:58 +0200)
src/ui/gui/psppire-delimited-text.c

index 98f76b4301953f330f881d37b193111eb8893f52..c708a8c0cba8576b2c25fa7fd25d261affa90d11 100644 (file)
@@ -98,6 +98,7 @@ psppire_delimited_text_set_property (GObject         *object,
       break;
     case PROP_CHILD:
       tf->child = g_value_get_object (value);
+      g_return_if_fail (PSPPIRE_IS_TEXT_FILE (tf->child));
       break;
     case PROP_DELIMITERS:
       g_slist_free (tf->delimiters);
@@ -143,6 +144,13 @@ static void psppire_delimited_text_dispose        (GObject           *object);
 
 static GObjectClass *parent_class = NULL;
 
+static gint
+n_lines (PsppireDelimitedText *file)
+{
+  PsppireTextFile *child = PSPPIRE_TEXT_FILE (file->child);
+
+  return child->maximum_lines;
+}
 
 static gboolean
 __tree_get_iter (GtkTreeModel *tree_model,
@@ -162,7 +170,7 @@ __tree_get_iter (GtkTreeModel *tree_model,
 
   gint n = *indices;
 
-  gint children = gtk_tree_model_iter_n_children (file->child, NULL);
+  gint children = n_lines (file);
 
   if (n >= children - file->first_line)
     return FALSE;
@@ -187,7 +195,7 @@ __tree_iter_next (GtkTreeModel *tree_model,
 
   //  g_print ("%s:%d %s %d\n", __FILE__, __LINE__, __FUNCTION__, n);
 
-  gint children = gtk_tree_model_iter_n_children (file->child, NULL);
+  gint children = n_lines (file);
 
   if (n + 1 >= children - file->first_line)
     return FALSE;
@@ -237,7 +245,7 @@ __tree_get_path (GtkTreeModel *tree_model,
 
   gint n = GPOINTER_TO_INT (iter->user_data);
 
-  gint children = gtk_tree_model_iter_n_children (file->child, NULL);
+  gint children = n_lines (file);
 
   if (n >= children - file->first_line)
     return NULL;
@@ -264,7 +272,7 @@ __tree_model_iter_n_children (GtkTreeModel *tree_model,
   //  g_print ("%s:%d %s\n", __FILE__, __LINE__, __FUNCTION__);
   g_assert (iter == NULL);
 
-  gint children = gtk_tree_model_iter_n_children (file->child, NULL);
+  gint children = n_lines (file);
 
   return children - file->first_line;
 }