I’d like my ValueTree::Listener to know when the ValueTree changes (is loaded from XML), is it possible at all, since the fromXml() method is static it does not work within the ValueTree i’m listening on, is there some other way to have valueTreeChildAdded() and others called during the restoration of a ValueTree from a XML document (this document is created only with the createXml() method, no bogus data in it).
well i did a copy of fromXml method in my own code (it’s just a few lines) and i got the behavior i want, almost i get the callback only for the first added child and not for children further down the tree.
masterTree = ValueTree (savedState.getTagName()); for (int i=0; i<savedState.getNumAttributes(); i++) masterTree.setProperty (savedState.getAttributeName(i), savedState.getAttributeValue(i), 0); forEachXmlChildElement (savedState, e) masterTree.addChild (ValueTree::fromXml (*e), -1, 0);
is there some easier way to have those callback, or do i need to override the ValueTree methods to achieve this ?
Well, loading a tree from XML creates an entirely new node. You can’t really load an XML representation into an existing node (what would be done with the old root?), so you replace the contents of the original. Perhaps that’s what you need a new callback for? (valueTreeContentReplaced).
As the entire structure is replaced with loaded data, surely you’re better off just traversing the tree and putting the new data to use? I.e. All the stuff that happens when things get added, do them all at once for the stuff that is already there.
The approach you’re describing doesn’t sound very practical!
it doesn’t i agree, and i’m moving away from it. i think i’ll go through the whole tree adding the relevant data with my own methods.