Peter Hildebrandt wrote:
Here's a question for you cells wizards out there (and Kenny in particular):
Say, I have a model M that depends on the structure of a family tree. One of M's slots is therefore depending on the root of the family tree: (c? root).
More below, just retro-inserting notes: normally in /my/ work the parent slot is not even a Cell, but I /have/ done that a couple of times on certain subclasses of Family and it did work.
However, I want M to know about changes in the family tree, like, say, when a child or grandchild is added. Apparently cells (at least the cells_2.0 branch required by cells-gtk) does not broadcast change messages to the parents of a node (which I guess is the right thing in 99% of the cases).
Confused: The kids slot is a Cell, so any rule anywhere (on slots not just the ascendants) that references (kids <whatever>) will get kicked off whent that changes. More below on this.
What's the best way to deal with that?
(i) Is there some mechanism for this purpose present in cells? Or (ii) Do I roll my own special case solution? Or (iii) Is it worthwhile to build some general purpose solution to this problem?
My approach towards (ii) (I haven't coded anything yet, waiting for you comments) would be something like building an observer tree each node of which observes one node in the family tree. Something like this:
- Design a tiny tree observer model ("tto"?), suited to observing one
family node (defmodel tty (family) (observed observed-kids reports-to))
- Every tto knows about the parent model (M from above) and does the
right thing when it sees a change (say, call a closure)
- If the observed nodes has kids, it instantiates tto kids of its own
to match the kids of the observed tree (def-c-output observed ((self tto)) (make-tto :observed (c? new-value) :observed-kids (c? (kids new-value))) (setf (kids self) (mapcar (lambda (kid) (make-tto :observed (c? kid) :observed-kids (c? (kids kid)))) (kids new-value) ...) (def-c-output observed-kids ((self tto)) ...)
- Changing the root slot in M results in the instantiation of a tto for
the root
I guess that would work ... but I feel there must be a more elegant solution. I'm eager to hear your suggestions.
Thanks, Peter
Background:
If you have seen my ton of mails on the cells-gtk-devel list, you know I'm doing some GUI work with cells-gtk at the moment. I ran into the following issue: cells-gtk can use a family tree as a natural representation of the contents of a tree-view. However, when I change the items in that family tree, cells-gtk currently has no way of updating the C data structure correspondingly.
This sentence seems crucial and puzzles me some. What precisely is meant by "when I change the items in that family tree"? Do you mean reorgamize the tree by moving kids between parents?
As for "update the C data structure correspondingly", well, /what/ C data structure, this is the first I have heard of it. Do you mean the C struct implementing the tree view, or a C struct one might be "inspecting" by mapping its hierarchy to a tree of widgets?
The tree-model data type GTK uses internally is nasty to deal with, and therefore I really want to capsulate everything away. I have already figured out how to add/remove rows and children in the model, so I'd be ready to modify the C data type to reflect changes in the family tree. I'm just looking for the Right Way to do it.
Let me clarify a couple of things first. btw, I do not even have Cells-Gtk installed anywhere so I may have to do that if things get too complicated.
First of all, my models normally do not have the parent slot as a Cell at all, meaning I do not move things from one parent to another. But! There have been times when I did that and it did seem to work, so let's keep that in mind going forward.
Second, without looking I am almost certain the kids slot of the family class already does let applications react to changes to kids, so I am not clear on why TTO is necessary (unless we are talking about also needing the parent to be a Cell, which as I said might Just Work if we put our minds to it).
Third, I'd like to understand the functionality better. Is the goal to manipulate a tree on the C side via a [Cells-]Gtk tree view? Or just dynamically restucture a treeview? This is the same question as above where I ask about what is meant by "update the C data structure"?
cheers, ken