Another idea for improving the tree/list stuff would be to allow the data model to be defined in Haskell. That way one would not have to make do with the two models provided by Gtk+, the TreeStore and the ListStore. These are rather cumbersome to use from Haskell since it all has to be done in the IO monad. Also it doesn’t feel ideal since you’re having to stuff your data into a different structure rather than just providing an adaptor for your existing data model.
Now the Gtk+ tree/list system is designed to follow the model/view/controller pattern so it does allow you to create your own models that implement the GtkTreeModel interface. However Gtk2Hs does not provide a way to implement the GtkTreeModel interface using Haskell. So my suggestion is to do just that.
I’m not quite sure how this would pan out but I think it’s worth a go. It can’t be worse than the existing system!
This would be implemented by writing in C a HaskellTreeStore that implementes the GtkTreeModel interface and deligates its implementation to a Haskell implementation. The Haskell implementation would probably be an instance of some new type class, lets call it TreeModelInterface.
So suppose you have some data and you want to connect it up to a list widget.
data MyDataset = ...
Then you would need to make it an instance of the TreeModelInterface
instance TreeModelInterface MyDataset where
getNumberOfRows mydataset = ...
getValue mydataset row = ...
...
Then if you’ve got a value of your MyDataset type then you could construct a TreeModel:
treeModelNew :: TreeModelInterface model => -> TreeModel
So you would then connect this new model to a view in much the same way as one currently does with the TreeStore and the ListStore models.
These names are not the greatest, just the first thing I thought of, suggestions welcome.