debian/gocui/plugin.go

118 lines
2.8 KiB
Go
Raw Normal View History

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)
"go.wit.com/log"
"go.wit.com/gui/widget"
2024-01-01 16:11:54 -06:00
)
func action(a *widget.Action) {
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 {
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
log.Log(ERROR, "action() Add ignored for already defined widget",
a.WidgetId, a.ActionType, a.WidgetType, a.ProgName)
2024-01-01 16:11:54 -06:00
}
case widget.Show:
if widget.GetBool(a.Value) {
2024-01-01 16:11:54 -06:00
n.showView()
} else {
n.hideWidgets()
}
case widget.Set:
if a.WidgetType == widget.Flag {
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 {
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 {
n.Set(a.Value)
2024-01-01 16:11:54 -06:00
}
}
case widget.SetText:
n.SetText(widget.GetString(a.Value))
case widget.AddText:
n.AddText(widget.GetString(a.Value))
case widget.Move:
log.Log(NOW, "attempt to move() =", a.ActionType, a.WidgetType, a.ProgName)
case widget.ToolkitClose:
log.Log(NOW, "attempting to close the plugin and release stdout and stderr")
2024-01-01 16:11:54 -06:00
standardExit()
case widget.Enable:
2024-01-01 16:11:54 -06:00
if n.Visible() {
// widget was already shown
} else {
log.Log(INFO, "Setting Visable to true", a.ProgName)
2024-01-01 16:11:54 -06:00
n.SetVisible(true)
}
case widget.Disable:
2024-01-01 16:11:54 -06:00
if n.Visible() {
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:
log.Log(ERROR, "action() ActionType =", a.ActionType, "WidgetType =", a.WidgetType, "Name =", a.ProgName)
2024-01-01 16:11:54 -06:00
}
log.Log(INFO, "action() END")
2024-01-01 16:11:54 -06:00
}
func (n *node) AddText(text string) {
if (n == nil) {
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 {
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) {
log.Log(NOW, "widget is nil")
2024-01-01 16:11:54 -06:00
return
}
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
log.Log(INFO, "Set() value =", val)
2024-01-01 16:11:54 -06:00
n.value = val
if (n.WidgetType != widget.Checkbox) {
n.setCheckbox(val)
2024-01-01 16:11:54 -06:00
}
}