From: pierric <w.p...@gm...> - 2008-08-25 02:08:33
|
2008/8/25 Axel Simon <Axe...@en...> > > On Aug 22, 2008, at 15:29, pierric wrote: > > Hi, everyone. >> In my current project, I use gtk2hs to build the GUI. But I meet a few >> problems. Following two is about the TreeView. >> 1. TreeView has a function named treeViewGetModel to achieve the TreeModel >> data. But there seems no way to covert this model into the concrete ones, >> such as TreeStore. This problem make the program a bit tougher, for I have >> to store the TreeStore somewhere. So I wonder why not just let the >> treeViewGetModel return the TreeStore structure? >> > > The problem is that this is not type safe: Firstly you could then extract > either a TreeStore or a ListStore, furthermore, the parameter of the values > in the store could be anything. It's a bit like the read :: Read a => String > -> a function which can convert a string into anything that has a Read > instance. There is not way to make this type safe. I think following the same way as read is a good idea. TreeModelClass m => treeViewGetModel :: TreeView -> IO (Maybe m) But it's also not very safe. If I store a ListStore in treeview, this signature allows me to extract it as a TreeStore. > > You need to keep track of a ListStore, but you don't need to keep track of > the TreeView once you've inserted it into a widget tree. Storing data in a > GUI application is always a difficult issue in Haskell. Usually, the whole > application state can be stored in one (possibly global) IORef that is > passed to all callbacks that need it. > > Axel. > > As Richard has suggested, before update a treeStore, I need to first set the treeview with a empty model, which require the treeView object. This means that I cannot simply get rid of the treeView object as long as I have created it. |