2024-01-01 16:11:54 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
// if you include more than just this import
|
|
|
|
// then your plugin might be doing something un-ideal (just a guess from 2023/02/27)
|
2024-01-08 20:52:10 -06:00
|
|
|
"go.wit.com/log"
|
2024-01-05 13:35:01 -06:00
|
|
|
"go.wit.com/gui/widget"
|
2024-01-01 16:11:54 -06:00
|
|
|
)
|
|
|
|
|
2024-01-05 13:35:01 -06:00
|
|
|
func action(a *widget.Action) {
|
2024-01-11 19:10:24 -06:00
|
|
|
log.Log(INFO, "action() START", a.WidgetId, a.ActionType, a.WidgetType, a.ProgName)
|
2024-01-01 16:11:54 -06:00
|
|
|
n := me.rootNode.findWidgetId(a.WidgetId)
|
|
|
|
var w *guiWidget
|
|
|
|
if (n != nil) {
|
|
|
|
w = n.tk
|
|
|
|
}
|
|
|
|
switch a.ActionType {
|
2024-01-05 13:35:01 -06:00
|
|
|
case widget.Add:
|
2024-01-01 16:11:54 -06:00
|
|
|
if (w == nil) {
|
|
|
|
n := addNode(a)
|
|
|
|
// w = n.tk
|
|
|
|
n.addWidget()
|
|
|
|
} else {
|
|
|
|
// this is done to protect the plugin being 'refreshed' with the
|
|
|
|
// widget binary tree. TODO: find a way to keep them in sync
|
2024-01-08 20:52:10 -06:00
|
|
|
log.Log(ERROR, "action() Add ignored for already defined widget",
|
2024-01-11 19:10:24 -06:00
|
|
|
a.WidgetId, a.ActionType, a.WidgetType, a.ProgName)
|
2024-01-01 16:11:54 -06:00
|
|
|
}
|
2024-01-05 13:35:01 -06:00
|
|
|
case widget.Show:
|
2024-01-11 19:10:24 -06:00
|
|
|
if widget.GetBool(a.Value) {
|
2024-01-01 16:11:54 -06:00
|
|
|
n.showView()
|
|
|
|
} else {
|
|
|
|
n.hideWidgets()
|
|
|
|
}
|
2024-01-05 13:35:01 -06:00
|
|
|
case widget.Set:
|
|
|
|
if a.WidgetType == widget.Flag {
|
2024-01-11 19:10:24 -06:00
|
|
|
log.Log(NOW, "TODO: set flag here", a.ActionType, a.WidgetType, a.ProgName)
|
|
|
|
log.Log(NOW, "TODO: n.WidgetType =", n.WidgetType, "n.progname =", a.ProgName)
|
2024-01-01 16:11:54 -06:00
|
|
|
} else {
|
2024-01-11 19:10:24 -06:00
|
|
|
if (a.Value == nil) {
|
|
|
|
log.Log(ERROR, "TODO: Set here. a == nil id =", a.WidgetId, "type =", a.WidgetType, "Name =", a.ProgName)
|
|
|
|
log.Log(ERROR, "TODO: Set here. id =", a.WidgetId, "n.progname =", n.progname)
|
2024-01-01 16:11:54 -06:00
|
|
|
} else {
|
2024-01-11 19:10:24 -06:00
|
|
|
n.Set(a.Value)
|
2024-01-01 16:11:54 -06:00
|
|
|
}
|
|
|
|
}
|
2024-01-05 13:35:01 -06:00
|
|
|
case widget.SetText:
|
2024-01-11 19:10:24 -06:00
|
|
|
n.SetText(widget.GetString(a.Value))
|
2024-01-05 13:35:01 -06:00
|
|
|
case widget.AddText:
|
2024-01-11 19:10:24 -06:00
|
|
|
n.AddText(widget.GetString(a.Value))
|
2024-01-05 13:35:01 -06:00
|
|
|
case widget.Move:
|
2024-01-11 19:10:24 -06:00
|
|
|
log.Log(NOW, "attempt to move() =", a.ActionType, a.WidgetType, a.ProgName)
|
2024-01-17 21:31:49 -06:00
|
|
|
case widget.ToolkitClose:
|
2024-01-08 20:52:10 -06:00
|
|
|
log.Log(NOW, "attempting to close the plugin and release stdout and stderr")
|
2024-01-01 16:11:54 -06:00
|
|
|
standardExit()
|
2024-01-05 13:35:01 -06:00
|
|
|
case widget.Enable:
|
2024-01-01 16:11:54 -06:00
|
|
|
if n.Visible() {
|
|
|
|
// widget was already shown
|
|
|
|
} else {
|
2024-01-11 19:10:24 -06:00
|
|
|
log.Log(INFO, "Setting Visable to true", a.ProgName)
|
2024-01-01 16:11:54 -06:00
|
|
|
n.SetVisible(true)
|
|
|
|
}
|
2024-01-05 13:35:01 -06:00
|
|
|
case widget.Disable:
|
2024-01-01 16:11:54 -06:00
|
|
|
if n.Visible() {
|
2024-01-11 19:10:24 -06:00
|
|
|
log.Log(INFO, "Setting Visable to false", a.ProgName)
|
2024-01-01 16:11:54 -06:00
|
|
|
n.SetVisible(false)
|
|
|
|
} else {
|
|
|
|
// widget was already hidden
|
|
|
|
}
|
|
|
|
default:
|
2024-01-11 19:10:24 -06:00
|
|
|
log.Log(ERROR, "action() ActionType =", a.ActionType, "WidgetType =", a.WidgetType, "Name =", a.ProgName)
|
2024-01-01 16:11:54 -06:00
|
|
|
}
|
2024-01-08 20:52:10 -06:00
|
|
|
log.Log(INFO, "action() END")
|
2024-01-01 16:11:54 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func (n *node) AddText(text string) {
|
|
|
|
if (n == nil) {
|
2024-01-08 20:52:10 -06:00
|
|
|
log.Log(NOW, "widget is nil")
|
2024-01-01 16:11:54 -06:00
|
|
|
return
|
|
|
|
}
|
|
|
|
n.vals = append(n.vals, text)
|
|
|
|
for i, s := range n.vals {
|
2024-01-11 19:10:24 -06:00
|
|
|
log.Log(NOW, "AddText()", n.progname, i, s)
|
2024-01-01 16:11:54 -06:00
|
|
|
}
|
|
|
|
n.SetText(text)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n *node) SetText(text string) {
|
|
|
|
var changed bool = false
|
|
|
|
if (n == nil) {
|
2024-01-08 20:52:10 -06:00
|
|
|
log.Log(NOW, "widget is nil")
|
2024-01-01 16:11:54 -06:00
|
|
|
return
|
|
|
|
}
|
2024-01-11 19:10:24 -06:00
|
|
|
if widget.GetString(n.value) != text {
|
|
|
|
n.value = text
|
2024-01-01 16:11:54 -06:00
|
|
|
changed = true
|
|
|
|
}
|
|
|
|
if (! changed) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n.Visible()) {
|
|
|
|
n.textResize()
|
|
|
|
n.deleteView()
|
|
|
|
n.showView()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n *node) Set(val any) {
|
|
|
|
// w := n.tk
|
2024-01-08 20:52:10 -06:00
|
|
|
log.Log(INFO, "Set() value =", val)
|
2024-01-01 16:11:54 -06:00
|
|
|
|
2024-01-11 19:10:24 -06:00
|
|
|
n.value = val
|
|
|
|
if (n.WidgetType != widget.Checkbox) {
|
|
|
|
n.setCheckbox(val)
|
2024-01-01 16:11:54 -06:00
|
|
|
}
|
|
|
|
}
|