diff --git a/addNode.go b/addNode.go index e0af110..cab2852 100644 --- a/addNode.go +++ b/addNode.go @@ -24,19 +24,19 @@ func (me *TreeInfo) AddNode(a *widget.Action) *Node { if a.WidgetType == widget.Root { log.Log(TREE, "AddNode() Root") n.Parent = n - me.treeRoot = n + treeRoot = n return n } - if me.treeRoot.FindWidgetId(a.WidgetId) != nil { + if treeRoot.FindWidgetId(a.WidgetId) != nil { log.Log(TREEWARN, "AddNode() WidgetId already exists", a.WidgetId) log.Log(TREEWARN, "probably this is a Show() / Hide() issue") log.Log(TREEWARN, "TODO: figure out what to do here") - return me.treeRoot.FindWidgetId(a.WidgetId) + return treeRoot.FindWidgetId(a.WidgetId) } // add this new widget on the binary tree - p := me.treeRoot.FindWidgetId(a.ParentId) + p := treeRoot.FindWidgetId(a.ParentId) n.Parent = p if n.Parent == nil { log.Log(TREEWARN, "AddNode() ERROR n.Parent == nil n =", n.WidgetId, n.WidgetType, n.GetProgName()) diff --git a/debug.go b/debug.go index f14e94c..86fa7ce 100644 --- a/debug.go +++ b/debug.go @@ -5,6 +5,10 @@ import ( "go.wit.com/widget" ) +func ShowButtons() { + treeRoot.ShowButtons() +} + func (n *Node) ShowButtons() { if n.WidgetType == widget.Button { n.DumpWidget("Button:") @@ -21,6 +25,10 @@ func (n *Node) DumpWidget(pad string) { var depth int = 0 +func ListWidgets() { + treeRoot.ListWidgets() +} + func (n *Node) ListWidgets() { if n == nil { log.Log(TREEWARN, "ERRRORRRR: n == nil in ListWidgets()") diff --git a/init.go b/init.go index ac5fb09..53d17c2 100644 --- a/init.go +++ b/init.go @@ -2,6 +2,7 @@ package tree import ( "errors" + "os" "runtime/debug" "sync" @@ -13,7 +14,7 @@ var muAction sync.Mutex // TODO: add checks for nil function pointers func (me *TreeInfo) newAction(a widget.Action) { - n := me.treeRoot.FindWidgetId(a.WidgetId) + n := treeRoot.FindWidgetId(a.WidgetId) switch a.ActionType { case widget.Add: if n == nil { @@ -83,6 +84,9 @@ func (me *TreeInfo) catchActionChannel() { me.SendToolkitPanic() debug.PrintStack() me.ToolkitClose() + if me.PluginName == "nocui" { + os.Exit(-1) + } } }() log.Log(TREE, "catchActionChannel() START") @@ -108,12 +112,6 @@ func New() *TreeInfo { me := new(TreeInfo) me.pluginChan = make(chan widget.Action, 1) - /* - full := "go.wit.com/gui" - short := "gui" - TREE = log.NewFlag("TREE", true, full, short, "treeRoot info") - */ - log.Log(TREE, "Init() start channel reciever") go me.catchActionChannel() log.Log(TREE, "Init() END") diff --git a/plugin.go b/plugin.go index cfa1fb4..1498880 100644 --- a/plugin.go +++ b/plugin.go @@ -15,6 +15,11 @@ import ( "go.wit.com/widget" ) +// searches the binary tree for a WidgetId +func FindWidgetId(id int) *Node { + return treeRoot.FindWidgetId(id) +} + // searches the binary tree for a WidgetId func (n *Node) FindWidgetId(id int) *Node { if n == nil { diff --git a/structs.go b/structs.go index 367f21a..17c10bc 100644 --- a/structs.go +++ b/structs.go @@ -10,6 +10,10 @@ import ( "go.wit.com/widget" ) +// this is the root node of the binary tree +// There is only one of these per application +var treeRoot *Node + type TreeInfo struct { PluginName string @@ -20,7 +24,6 @@ type TreeInfo struct { // this is the channel we get requests to make widgets pluginChan chan widget.Action - treeRoot *Node // NodeI interface{} // ActionFromChannel func(widget.Action)