pixelgl/action.go

106 lines
2.4 KiB
Go
Raw Normal View History

package main
/*
a simple function to handle widget actions
You can tie this into your toolkit here.
*/
import (
"go.wit.com/log"
"go.wit.com/toolkits/tree"
"go.wit.com/widget"
)
func Add(n *tree.Node) {
log.Log(INFO, "Add() END =", n.WidgetType, n.String())
if n == nil {
log.Warn("Tree Error: Add() sent n == nil")
return
}
switch n.WidgetType {
case widget.Root:
me.treeRoot = n
log.Log(INFO, "Add() found treeRoot")
return
}
log.Log(INFO, "Add() END =", n.WidgetType, n.String())
}
func newaction(n *tree.Node, atype widget.ActionType) {
log.Log(INFO, "newaction() START", atype)
if n == nil {
log.Warn("Tree Error: Add() sent n == nil")
return
}
if n.TK == nil {
log.Warn("Tree sent an action on a widget we didn't seem to have.")
// do this init here again? Probably something
// went wrong and we should reset the our while gocui.View tree
// n.TK = initWidget(n)
}
// w := n.TK.(*guiWidget)
switch atype {
case widget.Show:
log.Log(NOW, "Show() HERE. a.Hidden() was =", n.Hidden())
// w.Show()
case widget.Hide:
log.Log(NOW, "Hide() HERE. a.State.Hidden was =", n.Hidden())
// w.Hide()
case widget.Move:
log.Log(NOW, "attempt to move() =", atype, n.WidgetType, n.ProgName())
case widget.Enable:
// w.enable = true
// w.enableColor()
case widget.Disable:
// w.enable = false
// w.disableColor()
case widget.Delete:
log.Info("newaction() DeleteNode()")
n.DeleteNode()
case widget.ToolkitClose:
log.Info("newaction() toolkit closed. are the channels cleand up?")
return
default:
log.Log(ERROR, "newaction() UNHANDLED Action Type =", atype, "WidgetType =", n.WidgetType, "Name =", n.ProgName())
}
log.Log(INFO, "newaction() END", atype, n.String())
}
func SetTitle(n *tree.Node, s string) {
SetText(n, s)
}
func SetLabel(n *tree.Node, s string) {
SetText(n, s)
}
func SetText(n *tree.Node, s string) {
if n == nil {
log.Warn("Tree Error: Add() sent n == nil")
return
}
if n.TK == nil {
log.Warn("Tree sent an action on a widget we didn't seem to have.")
return
}
// w := n.TK.(*guiWidget)
// w.SetText(s)
log.Info("SetText()", n.WidgetType, n.String())
}
func AddText(n *tree.Node, s string) {
if n == nil {
log.Warn("Tree Error: Add() sent n == nil")
return
}
if n.TK == nil {
log.Warn("Tree sent an action on a widget we didn't seem to have.")
return
}
log.Info("AddText()", n.WidgetType, n.String())
// w := n.TK.(*guiWidget)
// w.AddText(s)
}