package debugger import ( "os" "go.wit.com/gui" "go.wit.com/lib/gadgets" "go.wit.com/lib/gui/logsettings" "go.wit.com/log" ) /* Creates a window helpful for debugging this package */ func DebugWindow() { if me != nil { log.Warn("Draw then Toggle() debuging window here") me.bugWin.Toggle() return } me = new(debuggerSettings) me.treeRoot = gui.TreeRoot() me.bugWin = gadgets.NewBasicWindow(me.treeRoot, "go.wit.com/gui debug window") me.bugWin.Make() DebugWindow2(me.bugWin.Box(), "Debug Tab") me.bugWin.Show() if ArgDebug() { // log.SetTmp() } } func DebugWindow2(newB *gui.Node, title string) *gui.Node { var gr *gui.Node //////////////////////// main debug things ////////////////////////////////// gr = newB.NewGroup("Debugging Windows:") gr.NewButton("logging", func() { logsettings.LogWindow() }) gr.NewButton("Widgets Window", func() { if me.widgets == nil { me.widgets = DebugWidgetWindow() return } me.widgets.Toggle() }) gr.NewLabel("Force Quit:") gr.NewButton("os.Exit()", func() { os.Exit(0) }) //////////////////////// window debugging things ////////////////////////////////// gr = newB.NewGroup("list things") gr.NewButton("List Windows", func() { dropdownWindow(gr) }) gr.NewButton("List Window Widgets", func() { dropdownWindowWidgets(gr) }) gr.NewButton("Node.ListChildren(true)", func() { if activeWidget == nil { activeWidget = bugWin } activeWidget.ListChildren(true) }) gr = newB.NewGroup("plugins") gr.NewButton("List Toolkits", func() { me.treeRoot.ListToolkits() }) gr.NewButton("load toolkit 'nocui'", func() { bugWin.LoadToolkit("nocui") }) gr.NewButton("unload toolkit 'nocui'", func() { bugWin.CloseToolkit("nocui") }) gr.NewButton("load toolkit 'gocui'", func() { bugWin.LoadToolkit("gocui") }) gr.NewButton("unload toolkit 'gocui'", func() { bugWin.CloseToolkit("gocui") }) gr.NewButton("load toolkit 'andlabs'", func() { bugWin.LoadToolkit("andlabs") }) gr.NewButton("unload toolkit 'andlabs'", func() { bugWin.CloseToolkit("andlabs") }) gr = newB.NewGroup("Learn GO") gr.NewButton("GO Language Internals", func() { if me.golang == nil { me.golang = DebugGolangWindow() return } log.Warn("going to toggle golang window") if me.golang.Ready() { me.golang.Toggle() } }) gr.NewButton("GO Channels debug", func() { if me.gochan == nil { me.gochan = DebugGoChannels() return } log.Warn("going to toggle go channels window") if me.gochan.Ready() { me.gochan.Toggle() } }) gr.NewButton("test conc", func() { log.Log(WARN, "TODO: fix me") // makeConc() }) return newB } func dropdownWindow(p *gui.Node) { var mapWindows map[string]*gui.Node mapWindows = make(map[string]*gui.Node) dd := p.NewDropdown() dd.Custom = func() { name := dd.String() activeWidget = mapWindows[name] setActiveWidget(activeWidget) log.Log(INFO, "The Window was set to", name) } log.Log(INFO, "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 p.Children() { log.Log(INFO, "\t\t", child.GetProgName()) dd.AddText(child.GetProgName()) // last = child.Name mapWindows[child.GetProgName()] = child if activeWidget == nil { activeWidget = child } } // dd.SetDropdownName(last) } func dropdownWindowWidgets(p *gui.Node) { var mapWindows map[string]*gui.Node mapWindows = make(map[string]*gui.Node) dd := p.NewDropdown() dd.Custom = func() { name := dd.String() activeWidget = mapWindows[name] setActiveWidget(activeWidget) } log.Log(INFO, "dd =", dd) // log.Log("dumpWidget() ", b, listChildrenDepth, defaultPadding, n.id, info) var addDropdowns func(*gui.Node) addDropdowns = func(n *gui.Node) { // s := n.dumpWidget(true) s := n.GetProgName() dd.AddText(s) mapWindows[s] = n for _, child := range n.Children() { addDropdowns(child) } } // list everything in the binary tree addDropdowns(bugWin) } func setActiveWidget(w *gui.Node) { log.Warn("TODO: setActiveWidget()") }