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

Method pasteAt

core/tree.go:1417–1465  ·  view source on GitHub ↗

todo: these methods require an interface to work for descended nodes, based on base code pasteAt inserts object(s) from mime data at rel position to this node. If another item with the same name already exists, it will append _Copy on the name of the inserted objects

(md mimedata.Mimes, mod events.DropMods, rel int, actNm string)

Source from the content-addressed store, hash-verified

1415// If another item with the same name already exists, it will
1416// append _Copy on the name of the inserted objects
1417func (tr *Tree) pasteAt(md mimedata.Mimes, mod events.DropMods, rel int, actNm string) {
1418 if tr.Parent == nil {
1419 return
1420 }
1421 parent := AsTree(tr.Parent)
1422 if parent == nil {
1423 MessageSnackbar(tr, "Error: cannot insert after the root of the tree")
1424 return
1425 }
1426 if tr.SyncNode != nil {
1427 tr.pasteAtSync(md, mod, rel, actNm)
1428 return
1429 }
1430 sl, pl := tr.nodesFromMimeData(md)
1431
1432 myidx := tr.IndexInParent()
1433 if myidx < 0 {
1434 return
1435 }
1436 myidx += rel
1437 sz := len(sl)
1438 var selTv *Tree
1439 for i, ns := range sl {
1440 orgpath := pl[i]
1441 if mod != events.DropMove {
1442 if cn := parent.ChildByName(ns.AsTree().Name, 0); cn != nil {
1443 ns.AsTree().SetName(ns.AsTree().Name + "_Copy")
1444 }
1445 }
1446 parent.InsertChild(ns, myidx+i)
1447 nwb := AsWidget(ns)
1448 ntv := AsTree(ns)
1449 ntv.root = tr.root
1450 nwb.setScene(tr.Scene)
1451 nwb.Update() // incl children
1452 npath := ns.AsTree().PathFrom(tr.root)
1453 if mod == events.DropMove && npath == orgpath { // we will be nuked immediately after drag
1454 ns.AsTree().SetName(ns.AsTree().Name + treeTempMovedTag) // special keyword :)
1455 }
1456 if i == sz-1 {
1457 selTv = ntv
1458 }
1459 }
1460 tr.treeChanged()
1461 parent.NeedsLayout()
1462 if selTv != nil {
1463 selTv.SelectEvent(events.SelectOne)
1464 }
1465}
1466
1467// pasteChildren inserts object(s) from mime data
1468// at end of children of this node

Callers 2

pasteBeforeMethod · 0.95
pasteAfterMethod · 0.95

Calls 15

pasteAtSyncMethod · 0.95
nodesFromMimeDataMethod · 0.95
treeChangedMethod · 0.95
SelectEventMethod · 0.95
AsTreeFunction · 0.85
MessageSnackbarFunction · 0.85
AsWidgetFunction · 0.85
IndexInParentMethod · 0.80
ChildByNameMethod · 0.80
InsertChildMethod · 0.80
PathFromMethod · 0.80
AsTreeMethod · 0.65

Tested by

no test coverage detected