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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
|
package gui
// Lots of debugging things:
// A function dump out the binary tree
import (
"strconv"
"git.wit.org/wit/gui/toolkit"
)
// various debugging flags
var debugNow bool = true // useful for active development
var debugGui bool = false
var debugError bool = true
var debugDump bool = false
var debugNode bool = false
var debugTabs bool = false
var debugFlags bool = false
var debugChange bool = false // shows user events like mouse and keyboard
var debugPlugin bool = false
var debugAction bool = false
// for printing out the binary tree
var listChildrenParent *Node
var listChildrenDepth int = 0
var defaultPadding = " "
func SetDebug (s bool) {
debugGui = s
debugTabs = s
SetFlag("Node", s)
SetFlag("Tabs", s)
SetFlag("Dump", s)
SetFlag("Flags", s)
SetFlag("Plugin", s)
SetFlag("Change", s)
SetFlag("Error", s)
// This flag is only for the internal toolkit debugging
SetFlag("Toolkit", s)
}
func SetFlag (s string, b bool) {
switch s {
case "Toolkit":
// This flag is only for internal toolkit debugging
case "Tabs":
debugTabs = b
case "Node":
debugNode = b
case "Dump":
debugDump = b
case "Error":
debugError = b
case "Change":
debugChange = b
case "Flags":
debugFlags = b
case "Plugin":
debugPlugin = b
case "Show":
// ShowDebugValues() // print them here?
default:
log(debugGui, "Can't set unknown flag", s)
}
// send the flag to the toolkit
// n := Config.flag
// log(debugChange, "Set() toolkit flag", s, "to", b)
// n.widget.Action = "Set"
// n.widget.S = s
// n.widget.B = b
// send(nil, n) // set flag in the plugin
var a toolkit.Action
a.Type = toolkit.SetFlag
a.S = s
a.B = b
// a.Widget = &newNode.widget
// a.Where = &n.widget
// action(&a)
newaction(&a, nil, nil)
}
func ShowDebugValues() {
// The order here should match the order in the GUI
// TODO: get the order from the node binary tree
log(true, "Debug =", debugGui)
log(true, "DebugError =", debugError)
log(true, "DebugChange =", debugChange)
log(true, "DebugDump =", debugDump)
log(true, "DebugTabs =", debugTabs)
log(true, "DebugPlugin =", debugPlugin)
log(true, "DebugNode =", debugNode)
SetFlag("Show", true)
}
func (n *Node) Dump(b bool) {
// log("Dump() dump =", b)
if ! b {
return
}
Indent(b, "NODE DUMP START")
Indent(b, "id = ", n.id)
Indent(b, "Name = ", n.Name)
Indent(b, "Width = ", n.Width)
Indent(b, "Height = ", n.Height)
Indent(b, "(X,Y) = ", n.X, n.Y)
Indent(b, "Next (X,Y) = ", n.NextX, n.NextY)
Indent(b, "Widget Name = ", n.widget.Name)
Indent(b, "Widget Type = ", n.widget.Type)
Indent(b, "Widget Id = ", n.widget.GetId())
if (n.parent == nil) {
Indent(b, "parent = nil")
} else {
Indent(b, "parent.id =", n.parent.id)
}
if (n.children != nil) {
Indent(b, "children = ", n.children)
}
if (n.Custom != nil) {
Indent(b, "Custom = ", n.Custom)
}
Indent(b, "NODE DUMP END")
}
func Indent(b bool, a ...interface{}) {
logindent(b, listChildrenDepth, defaultPadding, a...)
}
func (n *Node) dumpWidget(b bool) string {
var info, d string
if (n == nil) {
log(debugError, "dumpWidget() node == nil")
return ""
}
info = n.widget.Type.String()
info += ", " + n.widget.Name
if (n.Name != n.widget.Name) {
info += " NAME MISMATCH"
}
if (n.widget.Type == toolkit.Checkbox) {
info += " = " + strconv.FormatBool(n.widget.B)
}
d = strconv.Itoa(n.id) + " " + info
var tabs string
for i := 0; i < listChildrenDepth; i++ {
tabs = tabs + defaultPadding
}
d = tabs + d
logindent(b, listChildrenDepth, defaultPadding, n.id, info)
return d
}
// func (n *Node) ListChildren(dump bool, dropdown *Node, mapNodes map[string]*Node) {
func (n *Node) ListChildren(dump bool) {
if (n == nil) {
return
}
n.dumpWidget(dump)
// n.Dump(dump)
if len(n.children) == 0 {
if (n.parent == nil) {
return
}
log(debugNode, "\t\t\tparent =",n.parent.id)
if (listChildrenParent != nil) {
log(debugNode, "\t\t\tlistChildrenParent =",listChildrenParent.id)
if (listChildrenParent.id != n.parent.id) {
log("parent =",n.parent.id, n.parent.Name)
log("listChildrenParent =",listChildrenParent.id, listChildrenParent.Name)
log(listChildrenParent.id, "!=", n.parent.id)
exit("parent.child does not match child.parent")
}
}
log(debugNode, "\t\t", n.id, "has no children")
return
}
for _, child := range n.children {
if (child.parent != nil) {
log(debugNode, "\t\t\tparent =",child.parent.id)
} else {
log(debugGui, "\t\t\tno parent")
// memory corruption? non-threadsafe access?
// can all binary tree changes to Node.parent & Node.child be forced into a singular goroutine?
panic("something is wrong with the wit golang gui logic and the binary tree is broken. child has no parent")
}
child.Dump(debugDump)
if (child.children == nil) {
log(debugNode, "\t\t", child.id, "has no children")
} else {
log(debugNode, "\t\t\tHas children:", child.children)
}
listChildrenParent = n
listChildrenDepth += 1
// child.ListChildren(dump, dropdown, mapNodes)
child.ListChildren(dump)
listChildrenDepth -= 1
}
return
}
|