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

Function setUniqueName

tree/admin.go:157–170  ·  view source on GitHub ↗

setUniqueName is the implementation of [SetUniqueName] that takes whether to add the unique id to the name even if it is already set.

(n Node, addIfSet bool)

Source from the content-addressed store, hash-verified

155// setUniqueName is the implementation of [SetUniqueName] that takes whether
156// to add the unique id to the name even if it is already set.
157func setUniqueName(n Node, addIfSet bool) {
158 nb := n.AsTree()
159 pn := nb.Parent
160 if pn == nil {
161 return
162 }
163 c := atomic.AddUint64(&pn.AsTree().numLifetimeChildren, 1)
164 id := "-" + strconv.FormatUint(c-1, 10) // must subtract 1 so we start at 0
165 if nb.Name == "" {
166 nb.SetName(nb.NodeType().IDName + id)
167 } else if addIfSet {
168 nb.SetName(nb.Name + id)
169 }
170}

Callers 2

SetParentFunction · 0.85
SetUniqueNameFunction · 0.85

Calls 3

NodeTypeMethod · 0.80
AsTreeMethod · 0.65
SetNameMethod · 0.65

Tested by

no test coverage detected