2024-01-18 00:05:54 -06:00
|
|
|
package tree
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
2024-02-09 10:26:42 -06:00
|
|
|
"os"
|
2024-02-09 09:30:50 -06:00
|
|
|
"runtime/debug"
|
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:13:55 -06:00
|
|
|
// TODO: add checks for nil function pointers
|
2024-02-05 09:05:09 -06:00
|
|
|
func (me *TreeInfo) newAction(a widget.Action) {
|
2024-02-09 10:26:42 -06:00
|
|
|
n := 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-09 09:48:40 -06:00
|
|
|
log.Log(TREEWARN, "attempting to re-add widget", a.WidgetId, a.WidgetType, a.ActionType)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if n == nil {
|
|
|
|
log.Log(TREEWARN, "tree.FindWidgetId() n == nil", a.WidgetId, a.WidgetType, a.ActionType)
|
|
|
|
log.Log(TREEWARN, "tree.FindWidgetId() n == nil", a.State.CurrentS)
|
|
|
|
log.Log(TREEWARN, "tree.FindWidgetId() n == nil. This should not happen. Bug in gui or tree package?")
|
2024-02-09 10:50:39 -06:00
|
|
|
log.Log(TREEWARN, "tree.FindWidgetId() n == nil. A bug in your application?")
|
|
|
|
return
|
2024-02-09 09:48:40 -06:00
|
|
|
}
|
|
|
|
switch a.ActionType {
|
2024-02-05 09:05:09 -06:00
|
|
|
case widget.SetText:
|
2024-02-07 07:41:35 -06:00
|
|
|
log.Log(TREE, "tree.SetText() a.State.CurrentS =", a.State.CurrentS)
|
|
|
|
log.Log(TREE, "tree.SetText() a.State.DefaultS =", a.State.DefaultS)
|
|
|
|
log.Log(TREE, "tree.SetText() a.State.NewString =", a.State.NewString)
|
2024-02-05 09:05:09 -06:00
|
|
|
switch n.WidgetType {
|
|
|
|
case widget.Dropdown:
|
2024-02-05 15:03:11 -06:00
|
|
|
me.SetText(n, a.State.NewString)
|
2024-02-05 09:05:09 -06:00
|
|
|
case widget.Combobox:
|
2024-02-05 15:03:11 -06:00
|
|
|
me.SetText(n, a.State.NewString)
|
|
|
|
case widget.Textbox:
|
|
|
|
me.SetText(n, a.State.NewString)
|
2024-02-05 09:05:09 -06:00
|
|
|
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:
|
2024-02-09 03:43:55 -06:00
|
|
|
n.ddStrings = append(n.ddStrings, a.State.NewString)
|
2024-02-05 15:03:11 -06:00
|
|
|
me.AddText(n, a.State.NewString)
|
2024-02-05 09:05:09 -06:00
|
|
|
case widget.Combobox:
|
2024-02-09 03:43:55 -06:00
|
|
|
n.ddStrings = append(n.ddStrings, a.State.NewString)
|
2024-02-05 15:03:11 -06:00
|
|
|
me.AddText(n, a.State.NewString)
|
2024-02-05 09:05:09 -06:00
|
|
|
default:
|
2024-02-07 07:41:35 -06:00
|
|
|
log.Log(TREEWARN, "AddText() not supported on widget", n.WidgetType, n.String())
|
|
|
|
}
|
|
|
|
case widget.Checked:
|
|
|
|
switch n.WidgetType {
|
|
|
|
case widget.Checkbox:
|
2024-02-07 15:22:47 -06:00
|
|
|
if me.SetChecked == nil {
|
|
|
|
log.Log(TREEWARN, "SetChecked() == nil in toolkit", me.PluginName)
|
|
|
|
} else {
|
|
|
|
me.SetChecked(n, a.State.Checked)
|
|
|
|
}
|
2024-02-07 07:41:35 -06:00
|
|
|
default:
|
|
|
|
log.Log(TREEWARN, "SetChecked() not supported on widget", n.WidgetType, n.String())
|
2024-02-05 09:05:09 -06:00
|
|
|
}
|
|
|
|
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-02-07 15:22:47 -06:00
|
|
|
log.Log(TREEWARN, "YAHOOOO Recovered in tree.catchActionChannel()", r)
|
|
|
|
log.Log(TREEWARN, "YAHOOOO Recovered in tree.catchActionChannel() Plugin:", me.PluginName)
|
2024-01-19 12:08:21 -06:00
|
|
|
me.SendToolkitPanic()
|
2024-02-09 09:30:50 -06:00
|
|
|
debug.PrintStack()
|
2024-02-07 15:22:47 -06:00
|
|
|
me.ToolkitClose()
|
2024-02-09 10:26:42 -06:00
|
|
|
if me.PluginName == "nocui" {
|
|
|
|
os.Exit(-1)
|
|
|
|
}
|
2024-01-18 00:05:54 -06:00
|
|
|
}
|
|
|
|
}()
|
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-02-05 09:13:55 -06:00
|
|
|
if me.newAction == nil {
|
|
|
|
log.Error(errors.New("toolkit newAction == nil"), a.WidgetId, a.ActionType, a.WidgetType)
|
2024-01-19 12:08:21 -06:00
|
|
|
} 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-02-05 09:13:55 -06:00
|
|
|
// me.ActionFromChannel(a)
|
2024-01-19 12:08:21 -06:00
|
|
|
}
|
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
|
|
|
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
|
|
|
|
}
|