new-gui/debugWindow.go

186 lines
4.0 KiB
Go

package gui
import (
newlog "go.wit.com/log"
)
// TODO: move all this shit into somewhere not global
// main debugging window
var bugWin *Node
var mapWindows map[string]*Node
var checkd, checkdn, checkdt, checkdtk, lb1, lb2 *Node
var myButton *Node
/*
Creates a window helpful for debugging this package
*/
func (n *Node) DebugWindow() {
newlog.Warn("Don't use DebugWindow() directly anymore")
DebugWindow() // todo, remove the non-binary tree access
}
func DebugWindow() {
bugWin = me.rootNode.NewWindow("go.wit.com/gui debug window").DebugTab("Debug Tab")
bugWin.Custom = bugWin.StandardClose
if ArgDebug() {
newlog.SetTmp()
bugWin.DebugFlags()
}
}
// should the debugging windows be new windows or tabs
// var makeTabs bool = true
func (n *Node) UseTabs() bool {
return me.makeTabs
}
func (n *Node) SetTabs(b bool) {
me.makeTabs = b
}
func (n *Node) DebugTab(title string) *Node {
var newN, gog, g1 *Node
// var logSettings *gadgets.LogSettings
// time.Sleep(1 * time.Second)
newN = n.NewTab(title)
//////////////////////// main debug things //////////////////////////////////
gog = newN.NewGroup("Debugging Windows:")
// generally useful debugging
cb := gog.NewCheckbox("Seperate windows")
cb.Custom = func() {
log(debugGui, "Custom() n.widget =", cb.Name, cb.B)
n.SetTabs(cb.B)
}
cb.Set(false)
n.SetTabs(false)
gog.NewButton("logging", func () {
bugWin.DebugFlags()
})
gog.NewButton("Debug Widgets", func () {
DebugWidgetWindow(newN)
})
gog.NewButton("GO Language Internals", func () {
bugWin.DebugGolangWindow()
})
gog.NewButton("GO Channels debug", func () {
bugWin.DebugGoChannels()
})
gog.NewLabel("Force Quit:")
gog.NewButton("os.Exit()", func () {
exit()
})
//////////////////////// window debugging things //////////////////////////////////
g1 = newN.NewGroup("list things")
g1.NewButton("List toolkits", func () {
dropdownWindow(g1)
me.rootNode.ListToolkits()
})
g1.NewButton("List Windows", func () {
dropdownWindow(g1)
})
g1.NewButton("List Window Widgets", func () {
dropdownWindowWidgets(g1)
})
g2 := newN.NewGroup("more things")
g2.NewButton("Node.ListChildren(true)", func () {
if (activeWidget == nil) {
activeWidget = me.rootNode
}
activeWidget.ListChildren(true)
})
g2.NewButton("test conc", func () {
makeConc()
})
g2.NewButton("List Plugins", func () {
for _, aplug := range allPlugins {
log(true, "Loaded plugin:", aplug.name, aplug.filename)
}
})
g2.NewButton("load toolkit 'gocui'", func () {
me.rootNode.LoadToolkit("gocui")
})
g2.NewButton("load toolkit 'andlabs'", func () {
me.rootNode.LoadToolkit("andlabs")
})
return newN
}
func dropdownWindow(p *Node) {
var mapWindows map[string]*Node
mapWindows = make(map[string]*Node)
dd := p.NewDropdown("Window Dropdown")
dd.Custom = func() {
name := dd.S
activeWidget = mapWindows[name]
setActiveWidget(activeWidget)
log(true, "The Window was set to", name)
}
log(debugGui, "dd =", dd)
if (activeWidget == nil) {
// the debug window doesn't exist yet so you can't display the change
// TODO: make a fake binary tree for this(?)
return
}
// var last = ""
for _, child := range me.rootNode.children {
log(logInfo, "\t\t", child.id, child.Name)
dd.AddDropdownName(child.Name)
// last = child.Name
mapWindows[child.Name] = child
if (activeWidget == nil) {
activeWidget = child
}
}
// dd.SetDropdownName(last)
}
func dropdownWindowWidgets(p *Node) {
var mapWindows map[string]*Node
mapWindows = make(map[string]*Node)
dd := p.NewDropdown("Window Widgets Dropdown")
dd.Custom = func() {
name := dd.S
activeWidget = mapWindows[name]
setActiveWidget(activeWidget)
}
log(debugGui, "dd =", dd)
// log("dumpWidget() ", b, listChildrenDepth, defaultPadding, n.id, info)
var addDropdowns func (*Node)
addDropdowns = func (n *Node) {
s := n.dumpWidget(true)
dd.AddDropdownName(s)
mapWindows[s] = n
for _, child := range n.children {
listChildrenDepth += 1
addDropdowns(child)
listChildrenDepth -= 1
}
}
// list everything in the binary tree
addDropdowns(me.rootNode)
}