binary tree is global
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
12829e6e1c
commit
ec829f6e2b
|
@ -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())
|
||||
|
|
8
debug.go
8
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()")
|
||||
|
|
12
init.go
12
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")
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue