Re: [patch] fix insertion in GtkTreeModelSort



On Wed, 2002-03-06 at 21:55, Darin Adler wrote:
> 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.

Hi Darin,

Good catch! This function only does something useful when a
::row_inserted is being emitted for a node whose value has already been
set. I suspect this is the case with the Nautilus treeview, our test
programs didn't handle that (with the treestore you first have to insert
the node before you can set the value) -- so that's why we didn't catch
this earlier.

The patch looks fine to commit.


Thanks,


	Kris

> 
> 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
> 
> _______________________________________________
> gtk-devel-list mailing list
> gtk-devel-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtk-devel-list
> 




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