2024-01-18 00:05:54 -06:00
|
|
|
package tree
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
2024-01-18 04:08:11 -06:00
|
|
|
"sync"
|
2024-01-18 00:05:54 -06:00
|
|
|
|
|
|
|
"go.wit.com/log"
|
2024-01-18 04:08:11 -06:00
|
|
|
"go.wit.com/widget"
|
2024-01-18 00:05:54 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
var muAction sync.Mutex
|
|
|
|
|
2024-02-05 09:05:09 -06:00
|
|
|
func (me *TreeInfo) newAction(a widget.Action) {
|
|
|
|
n := me.treeRoot.FindWidgetId(a.WidgetId)
|
2024-02-05 07:20:57 -06:00
|
|
|
switch a.ActionType {
|
|
|
|
case widget.Add:
|
|
|
|
if n == nil {
|
|
|
|
n := me.AddNode(&a)
|
2024-02-05 09:05:09 -06:00
|
|
|
me.Add(n)
|
|
|
|
return
|
2024-02-05 07:20:57 -06:00
|
|
|
}
|
2024-02-05 09:05:09 -06:00
|
|
|
case widget.SetText:
|
|
|
|
switch n.WidgetType {
|
|
|
|
case widget.Dropdown:
|
|
|
|
me.SetText(n, widget.GetString(a.State.Value))
|
|
|
|
case widget.Combobox:
|
|
|
|
me.SetText(n, widget.GetString(a.State.Value))
|
|
|
|
case widget.Window:
|
|
|
|
me.SetTitle(n, a.State.Label)
|
|
|
|
default:
|
|
|
|
// buttons, checkboxes, groups, etc
|
|
|
|
me.SetLabel(n, a.State.Label)
|
|
|
|
}
|
|
|
|
case widget.AddText:
|
|
|
|
switch n.WidgetType {
|
|
|
|
case widget.Dropdown:
|
|
|
|
me.AddText(n, widget.GetString(a.State.Value))
|
|
|
|
case widget.Combobox:
|
|
|
|
me.AddText(n, widget.GetString(a.State.Value))
|
|
|
|
default:
|
|
|
|
log.Warn("AddText() not supported on widget", n.WidgetType, n.String())
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
me.NodeAction(n, a.ActionType)
|
2024-02-05 07:20:57 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-18 00:05:54 -06:00
|
|
|
func (me *TreeInfo) catchActionChannel() {
|
|
|
|
defer func() {
|
|
|
|
if r := recover(); r != nil {
|
2024-01-18 14:58:48 -06:00
|
|
|
log.Warn(me.PluginName, "tree YAHOOOO Recovered in simpleStdin()", r)
|
2024-01-19 12:08:21 -06:00
|
|
|
me.SendToolkitPanic()
|
2024-01-18 00:05:54 -06:00
|
|
|
panic(-1)
|
|
|
|
}
|
|
|
|
}()
|
2024-01-21 10:25:41 -06:00
|
|
|
log.Log(TREE, "catchActionChannel() START")
|
2024-01-18 00:05:54 -06:00
|
|
|
for {
|
2024-01-21 10:25:41 -06:00
|
|
|
log.Log(TREE, "catchActionChannel() for loop")
|
2024-01-18 04:08:11 -06:00
|
|
|
select {
|
2024-01-18 00:05:54 -06:00
|
|
|
case a := <-me.pluginChan:
|
2024-01-18 21:26:36 -06:00
|
|
|
log.Verbose("catchActionChannel() on ", a.WidgetId, a.WidgetType, a.ProgName)
|
2024-01-18 00:05:54 -06:00
|
|
|
muAction.Lock()
|
2024-01-19 12:08:21 -06:00
|
|
|
if me.ActionFromChannel == nil {
|
|
|
|
log.Error(errors.New("toolkit ActionFromChannel == nil"), a.WidgetId, a.ActionType, a.WidgetType)
|
|
|
|
} else {
|
2024-01-21 14:43:46 -06:00
|
|
|
// send this to the toolkit
|
2024-02-05 09:05:09 -06:00
|
|
|
me.newAction(a)
|
2024-01-19 12:08:21 -06:00
|
|
|
me.ActionFromChannel(a)
|
|
|
|
}
|
2024-01-18 00:05:54 -06:00
|
|
|
muAction.Unlock()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func New() *TreeInfo {
|
|
|
|
me := new(TreeInfo)
|
|
|
|
me.pluginChan = make(chan widget.Action, 1)
|
|
|
|
|
2024-01-21 10:25:41 -06:00
|
|
|
/*
|
2024-01-21 14:43:46 -06:00
|
|
|
full := "go.wit.com/gui"
|
|
|
|
short := "gui"
|
|
|
|
TREE = log.NewFlag("TREE", true, full, short, "treeRoot info")
|
2024-01-21 10:25:41 -06:00
|
|
|
*/
|
|
|
|
|
|
|
|
log.Log(TREE, "Init() start channel reciever")
|
2024-01-18 00:05:54 -06:00
|
|
|
go me.catchActionChannel()
|
2024-01-21 10:25:41 -06:00
|
|
|
log.Log(TREE, "Init() END")
|
2024-01-18 00:05:54 -06:00
|
|
|
return me
|
|
|
|
}
|