From 3ea3dd10db0e728240fc659bdd33c622d33e46b4 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Thu, 18 Jan 2024 00:05:54 -0600 Subject: initial commit Signed-off-by: Jeff Carr --- addNode.go | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 addNode.go (limited to 'addNode.go') diff --git a/addNode.go b/addNode.go new file mode 100644 index 0000000..36c5a06 --- /dev/null +++ b/addNode.go @@ -0,0 +1,47 @@ +package tree + +import ( + "errors" + + "go.wit.com/log" + "go.wit.com/lib/widget" +) + +// this is in common.go, do not move it +func (me *TreeInfo) AddNode(a *widget.Action) *Node { + n := new(Node) + n.WidgetType = a.WidgetType + n.WidgetId = a.WidgetId + n.ParentId = a.ParentId + + n.State = a.State + n.Strings = make(map[string]int) + + if (a.WidgetType == widget.Root) { + log.Info("AddNode() Root") + n.Parent = n + me.treeRoot = n + return n + } + + if (me.treeRoot.FindWidgetId(a.WidgetId) != nil) { + log.Warn("AddNode() WidgetId already exists", a.WidgetId) + log.Warn("probably this is a Show() / Hide() issue") + log.Warn("TODO: figure out what to do here") + return me.treeRoot.FindWidgetId(a.WidgetId) + } + + // add this new widget on the binary tree + p := me.treeRoot.FindWidgetId(a.ParentId) + n.Parent = p + if n.Parent == nil { + log.Error(errors.New("tree.AddNode() ERROR n.Parent == nil"), a.WidgetId, a.ParentId, a.ActionType) + log.Warn("AddNode() ERROR n.Parent == nil", a.WidgetId, a.ParentId, a.ActionType) + log.Warn("AddNode() ERROR n.Parent == nil", a.WidgetId, a.ParentId, a.WidgetType) + return n + } + log.Warn("AddNode() Adding to parent =", p.ParentId, p.WidgetType, p.GetProgName()) + log.Warn("AddNode() Adding child =", n.ParentId, n.WidgetType, n.GetProgName()) + p.children = append(p.children, n) + return n +} -- cgit v1.2.3