92 lines
2.3 KiB
Go
92 lines
2.3 KiB
Go
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"
|
|
"go.wit.com/widget"
|
|
)
|
|
|
|
func (me *TreeInfo) SendEnableDebugger() {
|
|
if me.callback == nil {
|
|
log.Warn("SendUserEvent() toolkit panic() callback == nil")
|
|
return
|
|
}
|
|
var a widget.Action
|
|
a.ActionType = widget.EnableDebug
|
|
a.ProgName = me.PluginName
|
|
me.callback <- a
|
|
return
|
|
}
|
|
|
|
func (me *TreeInfo) SendToolkitLoad(s string) {
|
|
if me.callback == nil {
|
|
log.Warn("SendUserEvent() toolkit load callback == nil")
|
|
return
|
|
}
|
|
var a widget.Action
|
|
a.ActionType = widget.ToolkitLoad
|
|
a.ProgName = me.PluginName
|
|
a.Value = s
|
|
log.Warn("SendUserEvent() START: toolkit load", s)
|
|
me.callback <- a
|
|
log.Warn("SendUserEvent() END: toolkit load", s)
|
|
return
|
|
}
|
|
|
|
func (me *TreeInfo) SendToolkitPanic() {
|
|
if me.callback == nil {
|
|
log.Warn("SendUserEvent() toolkit panic() callback == nil")
|
|
return
|
|
}
|
|
var a widget.Action
|
|
a.ActionType = widget.ToolkitPanic
|
|
a.ProgName = me.PluginName
|
|
log.Info("SendUserEvent() START: toolkit panic()")
|
|
me.callback <- a
|
|
log.Info("SendUserEvent() END: toolkit panic()")
|
|
return
|
|
}
|
|
|
|
func (me *TreeInfo) SendWindowCloseEvent(n *Node) {
|
|
if me.callback == nil {
|
|
log.Warn("SendUserEvent() callback == nil", n.WidgetId)
|
|
return
|
|
}
|
|
var a widget.Action
|
|
a.WidgetId = n.WidgetId
|
|
a.ActionType = widget.CloseWindow
|
|
log.Info("SendUserEvent() START: user closed the window", n.GetProgName())
|
|
me.callback <- a
|
|
log.Info("SendUserEvent() END: user closed the window", n.GetProgName())
|
|
return
|
|
}
|
|
|
|
// Other goroutines must use this to access the GUI
|
|
func (me *TreeInfo) SendUserEvent(n *Node) {
|
|
if me.callback == nil {
|
|
log.Warn("SendUserEvent() callback == nil", n.WidgetId)
|
|
return
|
|
}
|
|
var a widget.Action
|
|
a.WidgetId = n.WidgetId
|
|
a.Value = n.State.Value
|
|
a.ActionType = widget.User
|
|
if n.WidgetType == widget.Checkbox {
|
|
log.Info("SendUserEvent() checkbox going to send:", a.Value)
|
|
}
|
|
log.Info("SendUserEvent() START: send a user event to the callback channel")
|
|
me.callback <- a
|
|
log.Info("SendUserEvent() END: sent a user event to the callback channel")
|
|
return
|
|
}
|