So I want to display a collection of things in a TreeView but be able to
sort the collection by one of several ways via a popupmenu & append new,
childless, items to the end of the collection. I don't see an easy way,
though, to either manipulate the TreeStore as a whole or to know the path to
the last entry just from the .ModelView.TreeStore API. I was starting to
just keep a Forest in an IORef, manipulate that, then update the TreeStore
from there...but that's at least four kinds of wrong.
What's an idiomatic way of accomplishing what I want?
From: Axel Simon <Axel.Simon@en...> - 2008-08-10 13:45:45
On Aug 10, 2008, at 14:45, Creighton Hogg wrote:
> So I want to display a collection of things in a TreeView but be
> able to sort the collection by one of several ways via a popupmenu
> & append new, childless, items to the end of the collection.
I assume that the newly added items are supposed to be sorted in the
same way as the rest of the list. If that isn't the case, then that's
really odd and it gets complicated.
> What's an idiomatic way of accomplishing what I want?
Have you looked at demo/treeList/TreeSort.hs? In the last release,
I've added everything that's needed to support sorting trees. If you
don't want your original model to change because of the view is
sorted in different ways, then you need to wrap your original model
into a TreeModelSort proxy (as shown in the demo). After that, you
can simply append new entries in the original model and they will
appear in the proxy model at the right (ordered) position.
As for the sorting, you can define different sort functions, each
function has a unique number which is called SortColumnId. Normally,
you'd associate one function with each column of your view (hence the
name), but you can define any number of functions and sort the view
by calling treeSortableSetSortColumnId. This function is
automatically called by the view if you call
treeViewColumnSetSortColumnId for a column and the user clicks the
header of that column.
It should all be there! What is lacking is proper documentation. The
concepts are all simple but it takes a while before one manages to
get the big picture. Maybe one day I write a tutorial about the
I hope this helps, let me know if this is not what you need.
Get latest updates about Open Source Projects, Conferences and News.