2024-01-18 00:05:54 -06:00
|
|
|
package tree
|
|
|
|
|
|
|
|
/*
|
|
|
|
These code should be common to all gui plugins
|
|
|
|
|
|
|
|
There are some helper functions that are probably going to be
|
|
|
|
the same everywhere. Mostly due to handling the binary tree structure
|
|
|
|
and the channel communication
|
|
|
|
|
|
|
|
For now, it's just a symlink to the 'master' version in
|
|
|
|
./toolkit/nocui/common.go
|
|
|
|
*/
|
|
|
|
|
|
|
|
import (
|
|
|
|
"go.wit.com/log"
|
2024-01-18 04:08:11 -06:00
|
|
|
"go.wit.com/widget"
|
2024-01-18 00:05:54 -06:00
|
|
|
)
|
|
|
|
|
2024-01-19 12:08:21 -06:00
|
|
|
func (me *TreeInfo) SendEnableDebugger() {
|
2024-01-18 04:08:11 -06:00
|
|
|
if me.callback == nil {
|
2024-02-07 07:41:35 -06:00
|
|
|
log.Log(TREEWARN, "SendEnableDebugger() callback == nil")
|
2024-01-18 00:05:54 -06:00
|
|
|
return
|
|
|
|
}
|
|
|
|
var a widget.Action
|
|
|
|
a.ActionType = widget.EnableDebug
|
|
|
|
a.ProgName = me.PluginName
|
|
|
|
me.callback <- a
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-01-19 12:08:21 -06:00
|
|
|
func (me *TreeInfo) SendToolkitLoad(s string) {
|
2024-01-18 04:08:11 -06:00
|
|
|
if me.callback == nil {
|
2024-02-07 07:41:35 -06:00
|
|
|
log.Log(TREEWARN, "SendToolkitLoad() callback == nil")
|
2024-01-18 00:05:54 -06:00
|
|
|
return
|
|
|
|
}
|
2024-02-09 03:43:55 -06:00
|
|
|
log.Log(TREEWARN, "SendToolkitLoad() START: toolkit load", s)
|
2024-01-18 00:05:54 -06:00
|
|
|
var a widget.Action
|
|
|
|
a.ActionType = widget.ToolkitLoad
|
|
|
|
a.Value = s
|
2024-02-09 03:43:55 -06:00
|
|
|
a.ProgName = me.PluginName
|
2024-01-18 00:05:54 -06:00
|
|
|
me.callback <- a
|
2024-02-07 07:41:35 -06:00
|
|
|
log.Log(TREEWARN, "SendToolkitLoad() END: toolkit load", s)
|
2024-01-18 00:05:54 -06:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-01-19 12:08:21 -06:00
|
|
|
func (me *TreeInfo) SendToolkitPanic() {
|
2024-01-18 04:08:11 -06:00
|
|
|
if me.callback == nil {
|
2024-02-07 07:41:35 -06:00
|
|
|
log.Log(TREEWARN, "SendToolkitPanic() callback == nil")
|
2024-01-18 00:05:54 -06:00
|
|
|
return
|
|
|
|
}
|
2024-02-09 03:43:55 -06:00
|
|
|
log.Log(TREEWARN, "SendToolkitPanic() START")
|
2024-01-18 00:05:54 -06:00
|
|
|
var a widget.Action
|
|
|
|
a.ActionType = widget.ToolkitPanic
|
|
|
|
a.ProgName = me.PluginName
|
|
|
|
me.callback <- a
|
2024-02-09 03:43:55 -06:00
|
|
|
log.Log(TREEWARN, "SendToolkitPanic() END")
|
2024-01-18 00:05:54 -06:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-01-19 12:08:21 -06:00
|
|
|
func (me *TreeInfo) SendWindowCloseEvent(n *Node) {
|
2024-01-18 04:08:11 -06:00
|
|
|
if me.callback == nil {
|
2024-02-07 07:41:35 -06:00
|
|
|
log.Log(TREEWARN, "SendWindowClose() callback == nil", n.WidgetId)
|
2024-01-18 00:05:54 -06:00
|
|
|
return
|
|
|
|
}
|
2024-02-09 03:43:55 -06:00
|
|
|
log.Log(TREE, "SendWindowClose() START: user closed the window", n.GetProgName())
|
2024-01-18 00:05:54 -06:00
|
|
|
var a widget.Action
|
|
|
|
a.WidgetId = n.WidgetId
|
|
|
|
a.ActionType = widget.CloseWindow
|
2024-02-09 03:43:55 -06:00
|
|
|
a.ProgName = me.PluginName
|
2024-01-18 00:05:54 -06:00
|
|
|
me.callback <- a
|
2024-02-01 11:59:37 -06:00
|
|
|
log.Log(TREE, "SendWindowClose() END: user closed the window", n.GetProgName())
|
2024-01-18 00:05:54 -06:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-02-02 15:11:53 -06:00
|
|
|
// this name is better, but I can't use it
|
|
|
|
// is multiple toolkit support worth this sacrifice?
|
|
|
|
// func (n *Node) SendWidgetEvent() {
|
|
|
|
// }
|
|
|
|
|
|
|
|
// The user clicked on something. Or typed something
|
|
|
|
func (me *TreeInfo) SendWidgetEvent(n *Node) {
|
|
|
|
me.SendUserEvent(n)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (me *TreeInfo) SendFromUser(n *Node) {
|
|
|
|
me.SendUserEvent(n)
|
|
|
|
}
|
|
|
|
|
2024-01-18 00:05:54 -06:00
|
|
|
// Other goroutines must use this to access the GUI
|
2024-01-19 12:08:21 -06:00
|
|
|
func (me *TreeInfo) SendUserEvent(n *Node) {
|
2024-01-18 04:08:11 -06:00
|
|
|
if me.callback == nil {
|
2024-02-07 07:41:35 -06:00
|
|
|
log.Log(TREEWARN, "SendUserEvent() callback == nil", n.WidgetId)
|
2024-01-18 00:05:54 -06:00
|
|
|
return
|
|
|
|
}
|
2024-02-09 03:43:55 -06:00
|
|
|
log.Log(TREE, "SendUserEvent() START: send a user event to the callback channel")
|
2024-01-18 00:05:54 -06:00
|
|
|
var a widget.Action
|
|
|
|
a.WidgetId = n.WidgetId
|
2024-02-01 11:59:37 -06:00
|
|
|
a.State = n.State
|
2024-01-18 00:05:54 -06:00
|
|
|
a.ActionType = widget.User
|
2024-02-09 03:43:55 -06:00
|
|
|
a.ProgName = me.PluginName
|
2024-01-18 00:05:54 -06:00
|
|
|
me.callback <- a
|
2024-01-21 10:25:41 -06:00
|
|
|
log.Log(TREE, "SendUserEvent() END: sent a user event to the callback channel")
|
2024-01-18 00:05:54 -06:00
|
|
|
return
|
|
|
|
}
|