diff --git a/main.go b/main.go index f06e038..b92dbff 100644 --- a/main.go +++ b/main.go @@ -319,6 +319,29 @@ func (f *TMainForm) OnNavExpanding(sender vcl.IObject, node *vcl.TTreeNode, allo } *allowExpansion = node.HasChildren() + + // While we're here - preload one single level deep (not any deeper) + + if node.HasChildren() { + + // This node has children that we haven't processed. Process them now + cc := node.GetFirstChild() + + for { + ndataChild := (*navData)(cc.Data()) + if ndataChild.childrenLoaded { + break // We always do them together, so if one's done, no need to keep looking + } + + f.NavLoadChildren(cc, ndataChild) + + cc = cc.GetNextSibling() + if cc == nil { + break + } + } + + } } func (f *TMainForm) NavLoadChildren(node *vcl.TTreeNode, ndata *navData) error { @@ -345,7 +368,7 @@ func (f *TMainForm) NavLoadChildren(node *vcl.TTreeNode, ndata *navData) error { for _, bucketName := range nextBucketNames { node := f.Buckets.Items().AddChild(node, formatUtf8([]byte(bucketName))) - // node.SetHasChildren(true) // dynamically populate in OnNavExpanding + node.SetHasChildren(true) // dynamically populate in OnNavExpanding node.SetImageIndex(imgTable) node.SetSelectedIndex(imgTable) navData := &navData{ @@ -358,9 +381,6 @@ func (f *TMainForm) NavLoadChildren(node *vcl.TTreeNode, ndata *navData) error { node.SetData(unsafe.Pointer(navData)) ndata.ld.Keepalive(navData) - - // Recurse to see if it has any children of its own - f.NavLoadChildren(node, ndata) } }