package tree import ( "errors" "sync" "go.wit.com/log" "go.wit.com/widget" ) var muAction sync.Mutex // TODO: add checks for nil function pointers func (me *TreeInfo) newAction(a widget.Action) { n := me.treeRoot.FindWidgetId(a.WidgetId) switch a.ActionType { case widget.Add: if n == nil { n := me.AddNode(&a) me.Add(n) return } case widget.SetText: log.Info("tree.SetText() a.State.CurrentS =", a.State.CurrentS) log.Info("tree.SetText() a.State.DefaultS =", a.State.DefaultS) log.Info("tree.SetText() a.State.NewString =", a.State.NewString) switch n.WidgetType { case widget.Dropdown: me.SetText(n, a.State.NewString) case widget.Combobox: me.SetText(n, a.State.NewString) case widget.Textbox: me.SetText(n, a.State.NewString) 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, a.State.NewString) case widget.Combobox: me.AddText(n, a.State.NewString) default: log.Warn("AddText() not supported on widget", n.WidgetType, n.String()) } default: me.NodeAction(n, a.ActionType) } } func (me *TreeInfo) catchActionChannel() { defer func() { if r := recover(); r != nil { log.Warn(me.PluginName, "tree YAHOOOO Recovered in simpleStdin()", r) me.SendToolkitPanic() panic(-1) } }() log.Log(TREE, "catchActionChannel() START") for { log.Log(TREE, "catchActionChannel() for loop") select { case a := <-me.pluginChan: log.Verbose("catchActionChannel() on ", a.WidgetId, a.WidgetType, a.ProgName) muAction.Lock() if me.newAction == nil { log.Error(errors.New("toolkit newAction == nil"), a.WidgetId, a.ActionType, a.WidgetType) } else { // send this to the toolkit me.newAction(a) // me.ActionFromChannel(a) } muAction.Unlock() } } } 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") return me }