func shouldn't have been global
This commit is contained in:
parent
975c2d3102
commit
15100aad3e
|
@ -15,7 +15,7 @@ func (me *TreeInfo) doAction(a widget.Action) {
|
|||
if a.ActionType == widget.ToolkitInit {
|
||||
log.Log(TREEWARN, "tree.doAction() trapped ToolkitInit finally!")
|
||||
a.WidgetType = widget.Root
|
||||
n := AddNode(&a)
|
||||
n := addNode(&a)
|
||||
me.Add(n)
|
||||
log.Log(TREEWARN, "tree.doAction() init() me.treeRoot")
|
||||
if me.ToolkitInit != nil {
|
||||
|
|
21
addNode.go
21
addNode.go
|
@ -11,10 +11,10 @@ func (me *TreeInfo) AddNode(a *widget.Action) *Node {
|
|||
} else {
|
||||
log.Info("TREE: mutex lock was already held before AddNode()")
|
||||
}
|
||||
return AddNode(a)
|
||||
return addNode(a)
|
||||
}
|
||||
|
||||
func AddNode(a *widget.Action) *Node {
|
||||
func addNode(a *widget.Action) *Node {
|
||||
n := new(Node)
|
||||
n.WidgetType = a.WidgetType
|
||||
n.WidgetId = a.WidgetId
|
||||
|
@ -60,18 +60,23 @@ func AddNode(a *widget.Action) *Node {
|
|||
}
|
||||
|
||||
func (me *TreeInfo) DeleteNode(n *Node) {
|
||||
me.Lock()
|
||||
defer me.Unlock()
|
||||
log.Log(TREEWARN, "DeleteNode() before lock n =", n.WidgetId, n.GetProgName())
|
||||
if me.TryLock() {
|
||||
defer me.Unlock()
|
||||
} else {
|
||||
log.Info("TREE: mutex lock was already held before DeleteNode()")
|
||||
}
|
||||
p := n.Parent
|
||||
log.Log(TREEWARN, "DeleteNode() parent =", p.WidgetId, p.GetProgName())
|
||||
for i, child := range p.children {
|
||||
log.Log(TREE, "parent has child:", i, child.WidgetId, child.GetProgName())
|
||||
log.Log(TREEWARN, "parent has child:", i, child.WidgetId, child.GetProgName())
|
||||
if n == child {
|
||||
log.Log(TREE, "Found child ==", i, child.WidgetId, child.GetProgName())
|
||||
log.Log(TREE, "Found n ==", i, n.WidgetId, n.GetProgName())
|
||||
log.Log(TREEWARN, "Found child ==", i, child.WidgetId, child.GetProgName())
|
||||
log.Log(TREEWARN, "Found n ==", i, n.WidgetId, n.GetProgName())
|
||||
p.children = append(p.children[:i], p.children[i+1:]...)
|
||||
}
|
||||
}
|
||||
for i, child := range p.children {
|
||||
log.Log(TREE, "parent now has child:", i, child.WidgetId, child.GetProgName())
|
||||
log.Log(TREEWARN, "parent now has child:", i, child.WidgetId, child.GetProgName())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
package tree
|
||||
|
||||
import "log"
|
||||
|
||||
// find things in the tree
|
||||
// also verify parent <-> child mappings aren't a lie
|
||||
|
||||
// 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 {
|
||||
return nil
|
||||
}
|
||||
|
||||
if n.WidgetId == id {
|
||||
return n
|
||||
}
|
||||
|
||||
for _, child := range n.children {
|
||||
newN := child.FindWidgetId(id)
|
||||
if newN != nil {
|
||||
return newN
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// used for debugging the 'gui' package
|
||||
// to make sure things are valid
|
||||
// fixes any errors along the way
|
||||
func (me *Node) VerifyParentId() bool {
|
||||
return me.verifyParentId(0)
|
||||
}
|
||||
|
||||
func (n *Node) verifyParentId(parentId int) bool {
|
||||
if n == nil {
|
||||
return false
|
||||
}
|
||||
var ok bool = true
|
||||
|
||||
if n.ParentId != parentId {
|
||||
log.Printf("fixed widgetId %d from %d to %d", n.WidgetId, n.ParentId, parentId)
|
||||
n.ParentId = parentId
|
||||
ok = false
|
||||
}
|
||||
|
||||
for _, child := range n.children {
|
||||
if child.verifyParentId(n.WidgetId) {
|
||||
// everything is ok
|
||||
} else {
|
||||
ok = false
|
||||
}
|
||||
}
|
||||
return ok
|
||||
}
|
24
plugin.go
24
plugin.go
|
@ -16,30 +16,6 @@ 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 {
|
||||
return nil
|
||||
}
|
||||
|
||||
if n.WidgetId == id {
|
||||
return n
|
||||
}
|
||||
|
||||
for _, child := range n.children {
|
||||
newN := child.FindWidgetId(id)
|
||||
if newN != nil {
|
||||
return newN
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (me *TreeInfo) InitOK() {
|
||||
me.ok = true
|
||||
}
|
||||
|
|
45
structs.go
45
structs.go
|
@ -20,29 +20,28 @@ import (
|
|||
var treeRoot *Node
|
||||
|
||||
type TreeInfo struct {
|
||||
sync.Mutex // a lock around the tree to serialize access
|
||||
ok bool // indicates the plugin actually initialized
|
||||
PluginName string // used to identify the plugin
|
||||
config *ToolkitConfigs // protobuf of plugin settings
|
||||
callback chan widget.Action // mouse clicks or keyboard events back to the program
|
||||
pluginChan chan widget.Action // this is the channel we get requests to make widgets
|
||||
frozenChan chan widget.Action // expirement to get fyne to work
|
||||
Add func(*Node) // add a new widget
|
||||
AddText func(*Node, string) // add a string to a dropdown widget
|
||||
SetText func(*Node, string) // set the text of a widget
|
||||
SetTitle func(*Node, string) // update the title of a window or tab
|
||||
SetLabel func(*Node, string) // update the "label" (aka "Name") for a widget
|
||||
SetChecked func(*Node, bool) // set the state of a checkbox
|
||||
ToolkitInit func() // init the plugin
|
||||
ToolkitClose func() // shutdown and unload the plugin
|
||||
Show func(*Node) // show a widget
|
||||
Hide func(*Node) // hide a widget
|
||||
Enable func(*Node) // enable a widget
|
||||
Disable func(*Node) // disable a widget
|
||||
ShowTable func(*guipb.Table) // attempt at sending a whole table
|
||||
// NodeI interface{} // is an interface useful here?
|
||||
// NodeAction func(*Node, widget.ActionType) // deprecate
|
||||
currentTables []*guipb.Table
|
||||
sync.Mutex // a lock around the tree to serialize access
|
||||
ok bool // indicates the plugin actually initialized
|
||||
PluginName string // used to identify the plugin
|
||||
config *ToolkitConfigs // protobuf of plugin settings
|
||||
callback chan widget.Action // mouse clicks or keyboard events back to the program
|
||||
pluginChan chan widget.Action // this is the channel we get requests to make widgets
|
||||
frozenChan chan widget.Action // expirement to get fyne to work
|
||||
Add func(*Node) // add a new widget
|
||||
AddText func(*Node, string) // add a string to a dropdown widget
|
||||
SetText func(*Node, string) // set the text of a widget
|
||||
SetTitle func(*Node, string) // update the title of a window or tab
|
||||
SetLabel func(*Node, string) // update the "label" (aka "Name") for a widget
|
||||
SetChecked func(*Node, bool) // set the state of a checkbox
|
||||
ToolkitInit func() // init the plugin
|
||||
ToolkitClose func() // shutdown and unload the plugin
|
||||
Show func(*Node) // show a widget
|
||||
Hide func(*Node) // hide a widget
|
||||
Enable func(*Node) // enable a widget
|
||||
Disable func(*Node) // disable a widget
|
||||
ShowTable func(*guipb.Table) // attempt at sending a whole table
|
||||
currentTables []*guipb.Table // track the list of tables?
|
||||
Root *guipb.Tree // this is the future of this system
|
||||
}
|
||||
|
||||
type Node struct {
|
||||
|
|
4
table.go
4
table.go
|
@ -86,7 +86,7 @@ func (grid *Node) makeGridLabel(pb *guipb.Widget, w int, h int) *Node {
|
|||
a.State.GridOffset.X = w
|
||||
a.State.GridOffset.Y = h
|
||||
// log.Info("makeGridLabel()", a.State)
|
||||
return AddNode(a)
|
||||
return addNode(a)
|
||||
}
|
||||
|
||||
func (me *TreeInfo) updateTable(t *guipb.Table) {
|
||||
|
@ -184,7 +184,7 @@ func (me *TreeInfo) makeTable(t *guipb.Table) {
|
|||
a.WidgetId = int(t.Grid.Id)
|
||||
a.ParentId = int(t.Parent.Id)
|
||||
a.State.Enable = true
|
||||
grid = AddNode(a)
|
||||
grid = addNode(a)
|
||||
}
|
||||
if grid == nil {
|
||||
log.Info("tree: makeTable() failed to make grid")
|
||||
|
|
Loading…
Reference in New Issue