2022-11-13 08:53:03 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2023-03-12 08:47:16 -05:00
|
|
|
// if you include more than just this import
|
|
|
|
// then your plugin might be doing something un-ideal (just a guess from 2023/02/27)
|
2022-11-13 08:53:03 -06:00
|
|
|
"git.wit.org/wit/gui/toolkit"
|
|
|
|
)
|
|
|
|
|
2023-04-08 08:40:31 -05:00
|
|
|
func action(a *toolkit.Action) {
|
|
|
|
log(logInfo, "action() START", a.WidgetId, a.ActionType, a.WidgetType, a.Name)
|
2023-12-02 19:02:51 -06:00
|
|
|
n := me.rootNode.findWidgetId(a.WidgetId)
|
|
|
|
var w *cuiWidget
|
|
|
|
if (n != nil) {
|
|
|
|
w = n.tk
|
|
|
|
}
|
2023-04-03 10:26:47 -05:00
|
|
|
switch a.ActionType {
|
|
|
|
case toolkit.Add:
|
2023-04-07 09:18:03 -05:00
|
|
|
if (w == nil) {
|
2023-12-02 19:02:51 -06:00
|
|
|
n := addNode(a)
|
|
|
|
// w = n.tk
|
|
|
|
n.addWidget()
|
2023-04-07 09:18:03 -05:00
|
|
|
} else {
|
|
|
|
// this is done to protect the plugin being 'refreshed' with the
|
|
|
|
// widget binary tree. TODO: find a way to keep them in sync
|
2023-04-08 08:40:31 -05:00
|
|
|
log(logError, "action() Add ignored for already defined widget",
|
2023-04-07 09:18:03 -05:00
|
|
|
a.WidgetId, a.ActionType, a.WidgetType, a.Name)
|
|
|
|
}
|
2023-04-03 10:26:47 -05:00
|
|
|
case toolkit.Show:
|
|
|
|
if (a.B) {
|
2023-12-02 19:02:51 -06:00
|
|
|
n.showView()
|
2023-04-03 10:26:47 -05:00
|
|
|
} else {
|
2023-12-02 19:02:51 -06:00
|
|
|
n.hideWidgets()
|
2023-04-03 10:26:47 -05:00
|
|
|
}
|
|
|
|
case toolkit.Set:
|
2023-12-02 19:02:51 -06:00
|
|
|
if a.WidgetType == toolkit.Flag {
|
|
|
|
log(logNow, "TODO: set flag here", a.ActionType, a.WidgetType, a.Name)
|
|
|
|
log(logNow, "TODO: n.WidgetType =", n.WidgetType, "n.Name =", a.Name)
|
|
|
|
} else {
|
|
|
|
if (a.A == nil) {
|
|
|
|
log(logError, "TODO: Set here. a == nil", a.ActionType, "WidgetType =", a.WidgetType, "Name =", a.Name)
|
|
|
|
} else {
|
|
|
|
n.Set(a.A)
|
|
|
|
}
|
|
|
|
}
|
2023-04-03 10:26:47 -05:00
|
|
|
case toolkit.SetText:
|
2023-12-02 19:02:51 -06:00
|
|
|
n.SetText(a.S)
|
2023-04-03 10:26:47 -05:00
|
|
|
case toolkit.AddText:
|
2023-12-02 19:02:51 -06:00
|
|
|
n.AddText(a.S)
|
2023-04-03 10:26:47 -05:00
|
|
|
case toolkit.Move:
|
|
|
|
log(logNow, "attempt to move() =", a.ActionType, a.WidgetType, a.Name)
|
2023-04-22 12:25:50 -05:00
|
|
|
case toolkit.CloseToolkit:
|
|
|
|
log(logNow, "attempting to close the plugin and release stdout and stderr")
|
2023-04-26 21:36:56 -05:00
|
|
|
standardExit()
|
2023-04-03 10:26:47 -05:00
|
|
|
default:
|
2023-04-08 08:40:31 -05:00
|
|
|
log(logError, "action() Unknown =", a.ActionType, a.WidgetType, a.Name)
|
2022-11-13 08:53:03 -06:00
|
|
|
}
|
2023-04-08 08:40:31 -05:00
|
|
|
log(logInfo, "action() END")
|
2022-11-13 08:53:03 -06:00
|
|
|
}
|
|
|
|
|
2023-12-02 19:02:51 -06:00
|
|
|
func (n *node) AddText(text string) {
|
|
|
|
if (n == nil) {
|
2023-04-03 10:26:47 -05:00
|
|
|
log(logNow, "widget is nil")
|
|
|
|
return
|
|
|
|
}
|
2023-12-02 19:02:51 -06:00
|
|
|
n.vals = append(n.vals, text)
|
|
|
|
for i, s := range n.vals {
|
|
|
|
log(logNow, "AddText()", n.Name, i, s)
|
2023-03-12 08:47:16 -05:00
|
|
|
}
|
2023-12-02 19:02:51 -06:00
|
|
|
n.SetText(text)
|
2023-04-03 10:26:47 -05:00
|
|
|
}
|
2023-03-12 08:47:16 -05:00
|
|
|
|
2023-12-02 19:02:51 -06:00
|
|
|
func (n *node) SetText(text string) {
|
|
|
|
if (n == nil) {
|
2023-04-03 10:26:47 -05:00
|
|
|
log(logNow, "widget is nil")
|
2023-03-12 08:47:16 -05:00
|
|
|
return
|
|
|
|
}
|
2023-12-02 19:02:51 -06:00
|
|
|
n.S = text
|
|
|
|
n.Text = text
|
|
|
|
|
|
|
|
n.textResize()
|
|
|
|
n.deleteView()
|
|
|
|
n.showView()
|
2023-04-03 10:26:47 -05:00
|
|
|
}
|
2023-03-12 08:47:16 -05:00
|
|
|
|
2023-12-02 19:02:51 -06:00
|
|
|
func (n *node) Set(val any) {
|
|
|
|
// w := n.tk
|
2023-04-03 10:26:47 -05:00
|
|
|
log(logInfo, "Set() value =", val)
|
|
|
|
|
|
|
|
switch v := val.(type) {
|
|
|
|
case bool:
|
2023-12-02 19:02:51 -06:00
|
|
|
n.B = val.(bool)
|
|
|
|
n.setCheckbox(val.(bool))
|
2023-04-03 10:26:47 -05:00
|
|
|
case string:
|
2023-12-02 19:02:51 -06:00
|
|
|
n.SetText(val.(string))
|
2023-04-03 10:26:47 -05:00
|
|
|
case int:
|
2023-12-02 19:02:51 -06:00
|
|
|
n.I = val.(int)
|
2023-03-12 08:47:16 -05:00
|
|
|
default:
|
2023-04-08 08:40:31 -05:00
|
|
|
log(logError, "Set() unknown type =", val, v)
|
2023-03-12 08:47:16 -05:00
|
|
|
}
|
|
|
|
}
|
2023-12-02 19:02:51 -06:00
|
|
|
|
|
|
|
// this passes the user event back from the plugin
|
|
|
|
func (n *node) doUserEvent() {
|
|
|
|
if (me.callback == nil) {
|
|
|
|
log(logError, "doUserEvent() no callback channel was configured")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
var a toolkit.Action
|
|
|
|
a.WidgetId = n.WidgetId
|
|
|
|
a.Name = n.Name
|
|
|
|
a.Text = n.Text
|
|
|
|
a.B = n.B
|
|
|
|
a.ActionType = toolkit.User
|
|
|
|
log(logInfo, "doUserEvent() START: send a button click callback()", a.WidgetId, a.Name)
|
|
|
|
me.callback <- a
|
|
|
|
log(logInfo, "doUserEvent() END: sent a button click callback()", a.WidgetId, a.Name)
|
|
|
|
}
|