2024-01-18 00:11:03 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
/*
|
|
|
|
a simple function to handle widget actions
|
|
|
|
|
|
|
|
You can tie this into your toolkit here.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import (
|
|
|
|
"go.wit.com/log"
|
2024-02-05 12:26:05 -06:00
|
|
|
"go.wit.com/toolkits/tree"
|
2024-01-18 04:08:32 -06:00
|
|
|
"go.wit.com/widget"
|
2024-01-18 00:11:03 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2024-02-05 12:26:05 -06:00
|
|
|
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")
|
2024-01-18 00:11:03 -06:00
|
|
|
return
|
|
|
|
}
|
2024-02-05 12:26:05 -06:00
|
|
|
switch n.WidgetType {
|
2024-01-18 00:11:03 -06:00
|
|
|
case widget.Root:
|
2024-02-05 12:26:05 -06:00
|
|
|
me.treeRoot = n
|
|
|
|
log.Log(INFO, "Add() found treeRoot")
|
2024-01-18 00:11:03 -06:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-02-05 12:26:05 -06:00
|
|
|
log.Log(INFO, "Add() END =", n.WidgetType, n.String())
|
|
|
|
}
|
2024-01-18 00:11:03 -06:00
|
|
|
|
2024-02-05 12:26:05 -06:00
|
|
|
func newaction(n *tree.Node, atype widget.ActionType) {
|
|
|
|
log.Log(INFO, "newaction() START", atype)
|
2024-01-18 00:11:03 -06:00
|
|
|
if n == nil {
|
2024-02-05 12:26:05 -06:00
|
|
|
log.Warn("Tree Error: Add() sent n == nil")
|
2024-01-18 00:11:03 -06:00
|
|
|
return
|
|
|
|
}
|
2024-02-05 12:26:05 -06:00
|
|
|
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 {
|
2024-01-18 00:11:03 -06:00
|
|
|
case widget.Show:
|
2024-02-05 12:26:05 -06:00
|
|
|
log.Log(NOW, "Show() HERE. a.Hidden() was =", n.Hidden())
|
|
|
|
// w.Show()
|
2024-01-18 00:11:03 -06:00
|
|
|
case widget.Hide:
|
2024-02-05 12:26:05 -06:00
|
|
|
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())
|
2024-01-18 00:11:03 -06:00
|
|
|
case widget.Enable:
|
2024-02-05 12:26:05 -06:00
|
|
|
// w.enable = true
|
|
|
|
// w.enableColor()
|
2024-01-18 00:11:03 -06:00
|
|
|
case widget.Disable:
|
2024-02-05 12:26:05 -06:00
|
|
|
// w.enable = false
|
|
|
|
// w.disableColor()
|
2024-01-18 00:11:03 -06:00
|
|
|
case widget.Delete:
|
2024-02-05 12:26:05 -06:00
|
|
|
log.Info("newaction() DeleteNode()")
|
2024-01-18 23:07:56 -06:00
|
|
|
n.DeleteNode()
|
|
|
|
case widget.ToolkitClose:
|
2024-02-05 12:26:05 -06:00
|
|
|
log.Info("newaction() toolkit closed. are the channels cleand up?")
|
2024-01-18 23:07:56 -06:00
|
|
|
return
|
2024-01-18 00:11:03 -06:00
|
|
|
default:
|
2024-02-05 12:26:05 -06:00
|
|
|
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
|
2024-01-18 00:11:03 -06:00
|
|
|
}
|
2024-02-05 12:26:05 -06:00
|
|
|
log.Info("AddText()", n.WidgetType, n.String())
|
|
|
|
// w := n.TK.(*guiWidget)
|
|
|
|
// w.AddText(s)
|
2024-01-18 00:11:03 -06:00
|
|
|
}
|