1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
// Although most code from WIT.COM Inc is under the GPL
// This code is more generic because it must be able
// to be used in any GUI plugin
package tree
import (
"fmt"
"os"
"runtime/debug"
"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 := treeRoot.FindWidgetId(a.WidgetId)
switch a.ActionType {
case widget.Add:
if n == nil {
n := me.AddNode(&a)
me.Add(n)
return
}
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?")
// log.Log(TREEWARN, "tree.FindWidgetId() n == nil. A bug in your application?")
return
}
switch a.ActionType {
case widget.SetText:
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)
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:
n.ddStrings = append(n.ddStrings, a.State.NewString)
me.AddText(n, a.State.NewString)
case widget.Combobox:
n.ddStrings = append(n.ddStrings, a.State.NewString)
me.AddText(n, a.State.NewString)
default:
log.Log(TREEWARN, "AddText() not supported on widget", n.WidgetType, n.String())
}
case widget.Checked:
switch n.WidgetType {
case widget.Checkbox:
if me.SetChecked == nil {
log.Log(TREEWARN, "SetChecked() == nil in toolkit", me.PluginName)
} else {
me.SetChecked(n, a.State.Checked)
}
default:
log.Log(TREEWARN, "SetChecked() 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.Log(TREEWARN, "YAHOOOO. Recovered in tree.catchActionChannel()", r)
log.Log(TREEWARN, "YAHOOOO. Recovered in tree.catchActionChannel() Plugin:", me.PluginName)
me.SendToolkitPanic()
debug.PrintStack()
me.ToolkitClose()
if me.PluginName == "nocui" {
os.Exit(-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()
me.newAction(a)
muAction.Unlock()
}
}
}
func New() *TreeInfo {
me := new(TreeInfo)
me.pluginChan = make(chan widget.Action, 1)
me.config = configLoad()
log.Log(TREE, "Init() start channel reciever")
go me.catchActionChannel()
log.Log(TREE, "Init() END")
return me
}
func (t *TreeInfo) ConfigFind(n string) (string, error) {
all := t.config.All() // get the list of repos
for all.Scan() {
r := all.Next()
if t.PluginName != r.Plugin {
continue
}
if n == r.Name {
return r.Value, nil
}
log.Info("toolkit config", r.Plugin, r.Name, r.Value, n)
}
return "", fmt.Errorf("toolkit config %s not found", n)
}
|