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

Method insertAt

core/treesync.go:212–242  ·  view source on GitHub ↗

insertAt inserts a new node in the tree at given relative offset from this node, at the same (sibling) level, prompting for the type of node to insert If SyncNode is set, operates on Sync Tree.

(rel int, actNm string)

Source from the content-addressed store, hash-verified

210// prompting for the type of node to insert
211// If SyncNode is set, operates on Sync Tree.
212func (tr *Tree) insertAt(rel int, actNm string) {
213 if tr.IsRoot(actNm) {
214 return
215 }
216 myidx := tr.IndexInParent()
217 if myidx < 0 {
218 return
219 }
220 myidx += rel
221 var typ *types.Type
222 if tr.SyncNode == nil {
223 typ = types.TypeByValue(tr.This)
224 } else {
225 typ = types.TypeByValue(tr.SyncNode)
226 }
227 d := NewBody().AddTitle(actNm).AddText("Number and type of items to insert:")
228 nd := &newItemsData{Number: 1, Type: typ}
229 NewForm(d).SetStruct(nd)
230 d.AddBottomBar(func(parent Widget) {
231 d.AddCancel(parent)
232 d.AddOK(parent).OnClick(func(e events.Event) {
233 parent := AsTree(tr.Parent)
234 if tr.SyncNode != nil {
235 parent.addSyncNodes(rel, myidx, nd.Type, nd.Number)
236 } else {
237 parent.addTreeNodes(rel, myidx, nd.Type, nd.Number)
238 }
239 })
240 })
241 d.RunDialog(tr)
242}
243
244// AddChildNode adds a new child node to this one in the tree,
245// prompting the user for the type of node to add

Callers 2

InsertAfterMethod · 0.95
InsertBeforeMethod · 0.95

Calls 15

IsRootMethod · 0.95
TypeByValueFunction · 0.92
NewBodyFunction · 0.85
NewFormFunction · 0.85
AsTreeFunction · 0.85
IndexInParentMethod · 0.80
AddTextMethod · 0.80
AddTitleMethod · 0.80
AddBottomBarMethod · 0.80
AddCancelMethod · 0.80
AddOKMethod · 0.80
addSyncNodesMethod · 0.80

Tested by

no test coverage detected