MCPcopy Create free account
hub / github.com/cogentcore/core / syncToSrc

Method syncToSrc

core/treesync.go:62–93  ·  view source on GitHub ↗

syncToSrc updates the view tree to match the sync tree, using ConfigChildren to maximally preserve existing tree elements. init means we are doing initial build, and depth tracks depth (only during init).

(tvIndex *int, init bool, depth int)

Source from the content-addressed store, hash-verified

60// init means we are doing initial build, and depth tracks depth
61// (only during init).
62func (tr *Tree) syncToSrc(tvIndex *int, init bool, depth int) {
63 sn := tr.SyncNode
64 // root must keep the same name for continuity with surrounding context
65 if tr != tr.root {
66 nm := "tv_" + sn.AsTree().Name
67 tr.SetName(nm)
68 }
69 tr.viewIndex = *tvIndex
70 *tvIndex++
71 if init && depth >= tr.root.OpenDepth {
72 tr.SetClosed(true)
73 }
74 skids := sn.AsTree().Children
75 p := make(tree.TypePlan, 0, len(skids))
76 typ := tr.NodeType()
77 for _, skid := range skids {
78 p.Add(typ, "tv_"+skid.AsTree().Name)
79 }
80 tree.Update(tr, p)
81 idx := 0
82 for _, skid := range sn.AsTree().Children {
83 if len(tr.Children) <= idx {
84 break
85 }
86 vk := AsTree(tr.Children[idx])
87 vk.setSyncNode(skid, tvIndex, init, depth+1)
88 idx++
89 }
90 if !sn.AsTree().HasChildren() {
91 tr.SetClosed(true)
92 }
93}
94
95// Label returns the display label for this node,
96// satisfying the [labels.Labeler] interface.

Callers 3

SyncTreeMethod · 0.95
setSyncNodeMethod · 0.95
ResyncMethod · 0.95

Calls 9

SetClosedMethod · 0.95
UpdateFunction · 0.92
AsTreeFunction · 0.85
NodeTypeMethod · 0.80
setSyncNodeMethod · 0.80
AsTreeMethod · 0.65
SetNameMethod · 0.65
AddMethod · 0.65
HasChildrenMethod · 0.45

Tested by

no test coverage detected