From 7e5d17100df07183d0c2bc805914d1d16309dd5a Mon Sep 17 00:00:00 2001 From: mappu Date: Sun, 23 Jun 2024 15:21:41 +1200 Subject: [PATCH] main: preload recursive navigation only one layer at a time --- main.go | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) 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) } }