summaryrefslogtreecommitdiff
path: root/plugin.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-01-28 02:20:31 -0600
committerJeff Carr <[email protected]>2024-01-28 02:20:31 -0600
commit4fbbd2cee13546dbe570509e2c2e0755225a1489 (patch)
tree8e5c8238e0b28b2a03b682789095b5f61b72b3c5 /plugin.go
parenta9913b70edec4cf4e5bf51dadebfb64c87085fd6 (diff)
large refactor to use the tree package
Things build and now need to be fixed treeRoot has no children lists all widgets works shows help module loads Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'plugin.go')
-rw-r--r--plugin.go83
1 files changed, 45 insertions, 38 deletions
diff --git a/plugin.go b/plugin.go
index e18d4d1..7bf6757 100644
--- a/plugin.go
+++ b/plugin.go
@@ -7,19 +7,27 @@ import (
"go.wit.com/widget"
)
-func action(a *widget.Action) {
+func action(a widget.Action) {
log.Log(INFO, "action() START", a.WidgetId, a.ActionType, a.WidgetType, a.ProgName)
- n := me.rootNode.findWidgetId(a.WidgetId)
+ // n := me.rootNode.findWidgetId(a.WidgetId)
+ n := me.treeRoot.FindWidgetId(a.WidgetId)
var w *guiWidget
if n != nil {
- w = n.tk
+ w = n.TK.(*guiWidget)
}
switch a.ActionType {
case widget.Add:
if w == nil {
- n := addNode(a)
- // w = n.tk
- n.addWidget()
+ n := me.myTree.AddNode(&a)
+ if n == nil {
+ log.Warn("WTF")
+ panic("WTF")
+ }
+ n.TK = initWidget(n)
+ if n.WidgetType == widget.Root {
+ me.treeRoot = n
+ }
+ addWidget(n)
} else {
// this is done to protect the plugin being 'refreshed' with the
// widget binary tree. TODO: find a way to keep them in sync
@@ -28,42 +36,42 @@ func action(a *widget.Action) {
}
case widget.Show:
if widget.GetBool(a.Value) {
- n.showView()
+ w.showView()
} else {
- n.hideWidgets()
+ w.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)
+ log.Log(NOW, "TODO: n.WidgetType =", n.WidgetType, "n.String() =", a.ProgName)
} 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)
+ log.Log(ERROR, "TODO: Set here. id =", a.WidgetId, "n.String() =", n.String())
} else {
- n.Set(a.Value)
+ w.Set(a.Value)
}
}
case widget.SetText:
- n.SetText(widget.GetString(a.Value))
+ w.SetText(widget.GetString(a.Value))
case widget.AddText:
- n.AddText(widget.GetString(a.Value))
+ w.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")
standardExit()
case widget.Enable:
- if n.Visible() {
+ if w.Visible() {
// widget was already shown
} else {
- log.Log(INFO, "Setting Visable to true", a.ProgName)
- n.SetVisible(true)
+ log.Log(INFO, "Setting Visible to true", a.ProgName)
+ SetVisible(n, true)
}
case widget.Disable:
- if n.Visible() {
- log.Log(INFO, "Setting Visable to false", a.ProgName)
- n.SetVisible(false)
+ if w.Visible() {
+ log.Log(INFO, "Setting Visible to false", a.ProgName)
+ SetVisible(n, false)
} else {
// widget was already hidden
}
@@ -73,45 +81,44 @@ func action(a *widget.Action) {
log.Log(INFO, "action() END")
}
-func (n *node) AddText(text string) {
- if n == nil {
+func (w *guiWidget) AddText(text string) {
+ if w == nil {
log.Log(NOW, "widget is nil")
return
}
- n.vals = append(n.vals, text)
- for i, s := range n.vals {
- log.Log(NOW, "AddText()", n.progname, i, s)
+ w.vals = append(w.vals, text)
+ for i, s := range w.vals {
+ log.Log(NOW, "AddText()", w.String(), i, s)
}
- n.SetText(text)
+ w.SetText(text)
}
-func (n *node) SetText(text string) {
+func (w *guiWidget) SetText(text string) {
var changed bool = false
- if n == nil {
+ if w == nil {
log.Log(NOW, "widget is nil")
return
}
- if widget.GetString(n.value) != text {
- n.value = text
+ if widget.GetString(w.value) != text {
+ w.value = text
changed = true
}
if !changed {
return
}
- if n.Visible() {
- n.textResize()
- n.deleteView()
- n.showView()
+ if w.Visible() {
+ w.textResize()
+ w.deleteView()
+ w.showView()
}
}
-func (n *node) Set(val any) {
- // w := n.tk
+func (w *guiWidget) Set(val any) {
log.Log(INFO, "Set() value =", val)
- n.value = val
- if n.WidgetType != widget.Checkbox {
- n.setCheckbox(val)
+ w.value = val.(string)
+ if w.node.WidgetType != widget.Checkbox {
+ w.setCheckbox(val)
}
}