2024-01-18 00:08:37 -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"
|
2024-02-05 09:04:38 -06:00
|
|
|
"go.wit.com/toolkits/tree"
|
2024-01-18 04:10:08 -06:00
|
|
|
"go.wit.com/widget"
|
2024-01-18 00:08:37 -06:00
|
|
|
)
|
|
|
|
|
2024-02-05 09:04:38 -06:00
|
|
|
func newAdd(n *tree.Node) {
|
|
|
|
if n == nil {
|
|
|
|
log.Warn("Tree Error: Add() sent n == nil")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if n.TK != nil {
|
|
|
|
log.Warn("Tree Add() sent a widget we aleady seem to have")
|
|
|
|
// this is done to protect the plugin being 'refreshed' with the
|
|
|
|
// widget binary tree. TODO: find a way to keep them in sync
|
|
|
|
return
|
|
|
|
}
|
|
|
|
n.TK = initWidget(n)
|
|
|
|
if n.WidgetType == widget.Root {
|
|
|
|
me.treeRoot = n
|
|
|
|
}
|
|
|
|
addWidget(n)
|
|
|
|
/*
|
|
|
|
TODO: removed while refactoring tree
|
|
|
|
if w.enable {
|
|
|
|
// don't change the color
|
|
|
|
} else {
|
|
|
|
w = n.TK.(*guiWidget)
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
// w.setColor(&colorDisabled)
|
|
|
|
w := n.TK.(*guiWidget)
|
|
|
|
w.Show()
|
|
|
|
}
|
|
|
|
|
|
|
|
func newSetTitle(n *tree.Node, s string) {
|
|
|
|
newSetText(n, s)
|
|
|
|
}
|
|
|
|
|
|
|
|
func newSetLabel(n *tree.Node, s string) {
|
|
|
|
newSetText(n, s)
|
|
|
|
}
|
|
|
|
|
|
|
|
func newSetText(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)
|
|
|
|
}
|
|
|
|
|
|
|
|
func newAddText(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.AddText(s)
|
|
|
|
}
|
|
|
|
|
2024-02-05 07:31:04 -06:00
|
|
|
func newaction(n *tree.Node, atype widget.ActionType) {
|
2024-02-05 09:04:38 -06:00
|
|
|
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:
|
|
|
|
w.Show()
|
|
|
|
case widget.Hide:
|
|
|
|
w.Hide()
|
|
|
|
case widget.Move:
|
|
|
|
log.Log(NOW, "attempt to move() =", atype, n.WidgetType, n.ProgName())
|
|
|
|
case widget.ToolkitClose:
|
|
|
|
log.Log(NOW, "attempting to close the plugin and release stdout and stderr")
|
|
|
|
standardClose()
|
|
|
|
case widget.Enable:
|
|
|
|
w.enable = true
|
|
|
|
w.enableColor()
|
|
|
|
case widget.Disable:
|
|
|
|
w.enable = false
|
|
|
|
w.disableColor()
|
|
|
|
case widget.Delete:
|
|
|
|
if w == nil {
|
|
|
|
return
|
|
|
|
} else {
|
|
|
|
w.hideWidgets()
|
|
|
|
w.deleteNode()
|
|
|
|
}
|
|
|
|
n.DeleteNode()
|
|
|
|
wRoot := me.treeRoot.TK.(*guiWidget)
|
|
|
|
wRoot.redoWindows(0, 0)
|
|
|
|
default:
|
|
|
|
log.Log(ERROR, "newaction() UNHANDLED Action Type =", atype, "WidgetType =", n.WidgetType, "Name =", n.ProgName())
|
|
|
|
}
|
|
|
|
log.Log(INFO, "newaction() END", atype, n.String())
|
2024-02-05 07:31:04 -06:00
|
|
|
}
|
|
|
|
|
2024-02-01 10:37:33 -06:00
|
|
|
func (w *guiWidget) deleteGocuiViews() {
|
|
|
|
if w.v == nil {
|
|
|
|
// no gocui view to delete for this widget
|
|
|
|
} else {
|
|
|
|
me.baseGui.DeleteView(w.cuiName)
|
|
|
|
w.v = nil
|
|
|
|
}
|
|
|
|
for _, child := range w.children {
|
|
|
|
child.deleteGocuiViews()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-30 01:20:36 -06:00
|
|
|
func (w *guiWidget) deleteNode() {
|
|
|
|
p := w.parent
|
|
|
|
for i, child := range p.children {
|
|
|
|
log.Log(NOW, "parent has child:", i, child.cuiName, child.String())
|
|
|
|
if w == child {
|
|
|
|
log.Log(NOW, "Found child ==", i, child.cuiName, child.String())
|
|
|
|
log.Log(NOW, "Found n ==", i, w.cuiName, w.String())
|
|
|
|
p.children = append(p.children[:i], p.children[i+1:]...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for i, child := range p.children {
|
|
|
|
log.Log(NOW, "parent now has child:", i, child.cuiName, child.String())
|
|
|
|
}
|
2024-02-01 10:37:33 -06:00
|
|
|
w.deleteGocuiViews()
|
2024-01-30 01:20:36 -06:00
|
|
|
}
|
|
|
|
|
2024-01-28 02:20:31 -06:00
|
|
|
func (w *guiWidget) AddText(text string) {
|
|
|
|
if w == nil {
|
2024-01-18 00:08:37 -06:00
|
|
|
log.Log(NOW, "widget is nil")
|
|
|
|
return
|
|
|
|
}
|
2024-01-28 02:20:31 -06:00
|
|
|
w.vals = append(w.vals, text)
|
|
|
|
for i, s := range w.vals {
|
|
|
|
log.Log(NOW, "AddText()", w.String(), i, s)
|
2024-01-18 00:08:37 -06:00
|
|
|
}
|
2024-01-28 02:20:31 -06:00
|
|
|
w.SetText(text)
|
2024-01-18 00:08:37 -06:00
|
|
|
}
|
|
|
|
|
2024-01-28 02:20:31 -06:00
|
|
|
func (w *guiWidget) SetText(text string) {
|
2024-01-18 00:08:37 -06:00
|
|
|
var changed bool = false
|
2024-01-28 02:20:31 -06:00
|
|
|
if w == nil {
|
2024-01-18 00:08:37 -06:00
|
|
|
log.Log(NOW, "widget is nil")
|
|
|
|
return
|
|
|
|
}
|
2024-01-28 03:33:08 -06:00
|
|
|
if w.labelN != text {
|
|
|
|
w.labelN = text
|
2024-01-18 00:08:37 -06:00
|
|
|
changed = true
|
|
|
|
}
|
|
|
|
if !changed {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-01-28 02:20:31 -06:00
|
|
|
if w.Visible() {
|
|
|
|
w.textResize()
|
2024-02-05 03:05:37 -06:00
|
|
|
w.Hide()
|
|
|
|
w.Show()
|
2024-01-18 00:08:37 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-28 02:20:31 -06:00
|
|
|
func (w *guiWidget) Set(val any) {
|
2024-02-01 09:41:16 -06:00
|
|
|
if w == nil {
|
|
|
|
log.Log(WARN, "Set() w == nil. val =", val)
|
|
|
|
return
|
|
|
|
}
|
2024-01-18 00:08:37 -06:00
|
|
|
log.Log(INFO, "Set() value =", val)
|
|
|
|
|
2024-01-28 02:20:31 -06:00
|
|
|
w.value = val.(string)
|
2024-02-01 11:59:21 -06:00
|
|
|
if w.node.WidgetType == widget.Checkbox {
|
|
|
|
w.node.State.Checked = widget.GetBool(val)
|
|
|
|
w.setCheckbox()
|
|
|
|
}
|
|
|
|
if w.node.WidgetType == widget.Label {
|
|
|
|
w.labelN = widget.GetString(val)
|
2024-01-18 00:08:37 -06:00
|
|
|
}
|
|
|
|
}
|