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

Method PathFrom

tree/nodebase.go:250–263  ·  view source on GitHub ↗

PathFrom returns the path to this node from the given parent node, using [Node.Name]s separated by / delimeters. Any existing / characters in names are escaped to \\ The paths that it returns exclude the name of the parent and the leading slash; for example, in the tree a/b/c/d/e, the result of d.P

(parent Node)

Source from the content-addressed store, hash-verified

248// automatically gets the [NodeBase.This] version of the given parent,
249// so a base type can be passed in without manually accessing [NodeBase.This].
250func (n *NodeBase) PathFrom(parent Node) string {
251 if n.This == parent {
252 return ""
253 }
254 // critical to get `This`
255 parent = parent.AsTree().This
256 // we bail a level below the parent so it isn't in the path
257 if n.Parent == nil || n.Parent == parent {
258 return EscapePathName(n.Name)
259 }
260 ppath := n.Parent.AsTree().PathFrom(parent)
261 return ppath + "/" + EscapePathName(n.Name)
262
263}
264
265// FindPath returns the node at the given path from this node.
266// FindPath only works correctly when names are unique.

Callers 10

MimeDataMethod · 0.80
InitMethod · 0.80
OpenURLMethod · 0.80
mimeDataSyncMethod · 0.80
pasteAtSyncMethod · 0.80
MimeDataMethod · 0.80
pasteAtMethod · 0.80
childByLabelCanFocusFunction · 0.80
TestNodeEscapePathsFunction · 0.80
TestNodePathFromFunction · 0.80

Calls 2

EscapePathNameFunction · 0.85
AsTreeMethod · 0.65

Tested by 2

TestNodeEscapePathsFunction · 0.64
TestNodePathFromFunction · 0.64