[patch] fix insertion in GtkTreeModelSort



The code that inserted new elements into the tree was looking for the right
place to insert an element before updating it's table of where each sorted
element is in the underlying model.

The effect was that things didn't get sorted properly if you inserted them
one at a time. After this patch, the Nautilus tree view sorts properly.

Index: gtk/gtktreemodelsort.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtktreemodelsort.c,v
retrieving revision 1.58
diff -p -u -r1.58 gtktreemodelsort.c
--- gtk/gtktreemodelsort.c    2002/03/03 05:41:27    1.58
+++ gtk/gtktreemodelsort.c    2002/03/06 20:53:29
@@ -1663,6 +1663,12 @@ gtk_tree_model_sort_insert_value (GtkTre
   elt.ref_count = 0;
   elt.children = NULL;
 
+  /* update all larger offsets */
+  tmp_elt = SORT_ELT (level->array->data);
+  for (i = 0; i < level->array->len; i++, tmp_elt++)
+    if (tmp_elt->offset >= offset)
+      tmp_elt->offset++;
+
   if (tree_model_sort->sort_column_id ==
GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID &&
       tree_model_sort->default_sort_func == NO_SORT_FUNC)
     index = offset;
@@ -1672,16 +1678,10 @@ gtk_tree_model_sort_insert_value (GtkTre
                                                    FALSE);
 
   g_array_insert_vals (level->array, index, &elt, 1);
-
-  /* update all larger offsets */
   tmp_elt = SORT_ELT (level->array->data);
   for (i = 0; i < level->array->len; i++, tmp_elt++)
-    {
-      if ((tmp_elt->offset >= offset) && i != index)
-    tmp_elt->offset++;
-      if (tmp_elt->children)
-    tmp_elt->children->parent_elt = tmp_elt;
-    }
+    if (tmp_elt->children)
+      tmp_elt->children->parent_elt = tmp_elt;
 
   return TRUE;
 }
===================================================================

    -- Darin




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]