local function t(t,N)local M=NodeLookup[t]if not M then return end local p=NodeLookup[N]if not p then return end local L=nodeIsVisible(M)remove(M.Parent,M.Index)M.Parent=p M.Depth=depth(t)local function f(t,N)for M=1,#t,1 do t[M].Depth=N f(t[M],N+1)end end f(M,M.Depth+1)insert(p,#p+1,M)if L or nodeIsVisible(M)then updateList()elseif nodeIsVisible(M.Parent)then updateScroll()end end
-- Moves a tree node to a new parent. Called when an existing object's parent
-- changes.
local function moveObject(object, parent)
	local objectNode = NodeLookup[object]
	if not objectNode then
		return
	end

	local parentNode = NodeLookup[parent]
	if not parentNode then
		return
	end

	local visible = nodeIsVisible(objectNode)

	remove(objectNode.Parent, objectNode.Index)
	objectNode.Parent = parentNode

	objectNode.Depth = depth(object)
	local function r(node, d)
		for i = 1, #node do
			node[i].Depth = d
			r(node[i], d + 1)
		end
	end
	r(objectNode, objectNode.Depth + 1)

	insert(parentNode, #parentNode + 1, objectNode)

	if visible or nodeIsVisible(objectNode) then
		updateList()
	elseif nodeIsVisible(objectNode.Parent) then
		updateScroll()
	end
end
