a simpler time
This commit is contained in:
parent
dcfa5d03ee
commit
a75f0be460
|
@ -0,0 +1,87 @@
|
|||
// Although most code from WIT.COM Inc is under the GPL
|
||||
// This code is more generic because it must be able
|
||||
// to be used in any GUI plugin
|
||||
|
||||
package tree
|
||||
|
||||
import (
|
||||
"go.wit.com/log"
|
||||
"go.wit.com/widget"
|
||||
)
|
||||
|
||||
// everything from the application goes through here
|
||||
func (me *TreeInfo) doAction(a widget.Action) {
|
||||
n := treeRoot.FindWidgetId(a.WidgetId)
|
||||
switch a.ActionType {
|
||||
case widget.Add:
|
||||
if n == nil {
|
||||
n := me.AddNode(&a)
|
||||
me.Add(n)
|
||||
return
|
||||
}
|
||||
log.Log(TREEWARN, "attempting to re-add widget", a.WidgetId, a.WidgetType, a.ActionType)
|
||||
return
|
||||
}
|
||||
if n == nil {
|
||||
// log.Log(TREEWARN, "tree.FindWidgetId() n == nil", a.WidgetId, a.WidgetType, a.ActionType)
|
||||
// log.Log(TREEWARN, "tree.FindWidgetId() n == nil", a.State.CurrentS)
|
||||
// log.Log(TREEWARN, "tree.FindWidgetId() n == nil. A bug in your application?")
|
||||
log.Log(TREEWARN, "tree.doAction() bug in gui. trying to do action", a.ActionType, "before widget init() wId =", a.WidgetId)
|
||||
return
|
||||
}
|
||||
|
||||
switch a.ActionType {
|
||||
case widget.SetText:
|
||||
log.Log(TREE, "tree.SetText() a.State.CurrentS =", a.State.CurrentS)
|
||||
log.Log(TREE, "tree.SetText() a.State.DefaultS =", a.State.DefaultS)
|
||||
log.Log(TREE, "tree.SetText() a.State.NewString =", a.State.NewString)
|
||||
switch n.WidgetType {
|
||||
case widget.Dropdown:
|
||||
me.SetText(n, a.State.NewString)
|
||||
case widget.Combobox:
|
||||
me.SetText(n, a.State.NewString)
|
||||
case widget.Textbox:
|
||||
me.SetText(n, a.State.NewString)
|
||||
case widget.Window:
|
||||
me.SetTitle(n, a.State.Label)
|
||||
default:
|
||||
// buttons, checkboxes, groups, etc
|
||||
me.SetLabel(n, a.State.Label)
|
||||
}
|
||||
case widget.AddText:
|
||||
switch n.WidgetType {
|
||||
case widget.Dropdown:
|
||||
n.ddStrings = append(n.ddStrings, a.State.NewString)
|
||||
me.AddText(n, a.State.NewString)
|
||||
case widget.Combobox:
|
||||
n.ddStrings = append(n.ddStrings, a.State.NewString)
|
||||
me.AddText(n, a.State.NewString)
|
||||
default:
|
||||
log.Log(TREEWARN, "AddText() not supported on widget", n.WidgetType, n.String())
|
||||
}
|
||||
case widget.Checked:
|
||||
switch n.WidgetType {
|
||||
case widget.Checkbox:
|
||||
if me.SetChecked == nil {
|
||||
log.Log(TREEWARN, "SetChecked() == nil in toolkit", me.PluginName)
|
||||
} else {
|
||||
me.SetChecked(n, a.State.Checked)
|
||||
}
|
||||
default:
|
||||
log.Log(TREEWARN, "SetChecked() not supported on widget", n.WidgetType, n.String())
|
||||
}
|
||||
case widget.Show:
|
||||
n.State.Hidden = false
|
||||
me.Show(n)
|
||||
case widget.Hide:
|
||||
n.State.Hidden = true
|
||||
me.Hide(n)
|
||||
case widget.Enable:
|
||||
me.Enable(n)
|
||||
case widget.Disable:
|
||||
me.Disable(n)
|
||||
default:
|
||||
log.Log(TREEWARN, "tree.Action() unknown action", a.ActionType, "on wId", a.WidgetId)
|
||||
// me.NodeAction(n, a.ActionType)
|
||||
}
|
||||
}
|
68
init.go
68
init.go
|
@ -16,72 +16,6 @@ import (
|
|||
|
||||
var muAction sync.Mutex
|
||||
|
||||
// TODO: add checks for nil function pointers
|
||||
func (me *TreeInfo) newAction(a widget.Action) {
|
||||
n := treeRoot.FindWidgetId(a.WidgetId)
|
||||
switch a.ActionType {
|
||||
case widget.Add:
|
||||
if n == nil {
|
||||
n := me.AddNode(&a)
|
||||
me.Add(n)
|
||||
return
|
||||
}
|
||||
log.Log(TREEWARN, "attempting to re-add widget", a.WidgetId, a.WidgetType, a.ActionType)
|
||||
return
|
||||
}
|
||||
if n == nil {
|
||||
// log.Log(TREEWARN, "tree.FindWidgetId() n == nil", a.WidgetId, a.WidgetType, a.ActionType)
|
||||
// log.Log(TREEWARN, "tree.FindWidgetId() n == nil", a.State.CurrentS)
|
||||
// log.Log(TREEWARN, "tree.FindWidgetId() n == nil. This should not happen. Bug in gui or tree package?")
|
||||
// log.Log(TREEWARN, "tree.FindWidgetId() n == nil. A bug in your application?")
|
||||
return
|
||||
}
|
||||
|
||||
switch a.ActionType {
|
||||
case widget.SetText:
|
||||
log.Log(TREE, "tree.SetText() a.State.CurrentS =", a.State.CurrentS)
|
||||
log.Log(TREE, "tree.SetText() a.State.DefaultS =", a.State.DefaultS)
|
||||
log.Log(TREE, "tree.SetText() a.State.NewString =", a.State.NewString)
|
||||
switch n.WidgetType {
|
||||
case widget.Dropdown:
|
||||
me.SetText(n, a.State.NewString)
|
||||
case widget.Combobox:
|
||||
me.SetText(n, a.State.NewString)
|
||||
case widget.Textbox:
|
||||
me.SetText(n, a.State.NewString)
|
||||
case widget.Window:
|
||||
me.SetTitle(n, a.State.Label)
|
||||
default:
|
||||
// buttons, checkboxes, groups, etc
|
||||
me.SetLabel(n, a.State.Label)
|
||||
}
|
||||
case widget.AddText:
|
||||
switch n.WidgetType {
|
||||
case widget.Dropdown:
|
||||
n.ddStrings = append(n.ddStrings, a.State.NewString)
|
||||
me.AddText(n, a.State.NewString)
|
||||
case widget.Combobox:
|
||||
n.ddStrings = append(n.ddStrings, a.State.NewString)
|
||||
me.AddText(n, a.State.NewString)
|
||||
default:
|
||||
log.Log(TREEWARN, "AddText() not supported on widget", n.WidgetType, n.String())
|
||||
}
|
||||
case widget.Checked:
|
||||
switch n.WidgetType {
|
||||
case widget.Checkbox:
|
||||
if me.SetChecked == nil {
|
||||
log.Log(TREEWARN, "SetChecked() == nil in toolkit", me.PluginName)
|
||||
} else {
|
||||
me.SetChecked(n, a.State.Checked)
|
||||
}
|
||||
default:
|
||||
log.Log(TREEWARN, "SetChecked() not supported on widget", n.WidgetType, n.String())
|
||||
}
|
||||
default:
|
||||
me.NodeAction(n, a.ActionType)
|
||||
}
|
||||
}
|
||||
|
||||
func (me *TreeInfo) catchActionChannel() {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
|
@ -102,7 +36,7 @@ func (me *TreeInfo) catchActionChannel() {
|
|||
case a := <-me.pluginChan:
|
||||
log.Verbose("catchActionChannel() on ", a.WidgetId, a.WidgetType, a.ProgName)
|
||||
muAction.Lock()
|
||||
me.newAction(a)
|
||||
me.doAction(a)
|
||||
muAction.Unlock()
|
||||
}
|
||||
}
|
||||
|
|
32
structs.go
32
structs.go
|
@ -17,21 +17,25 @@ import (
|
|||
var treeRoot *Node
|
||||
|
||||
type TreeInfo struct {
|
||||
ok bool // indicates the plugin actually initialized
|
||||
PluginName string // used to identify the plugin
|
||||
config *ToolkitConfigs // protobuf of plugin settings
|
||||
callback chan widget.Action // mouse clicks or keyboard events back to the program
|
||||
pluginChan chan widget.Action // this is the channel we get requests to make widgets
|
||||
NodeAction func(*Node, widget.ActionType) // deprecate
|
||||
Add func(*Node) // add a new widget
|
||||
AddText func(*Node, string) // add a string to a dropdown widget
|
||||
SetText func(*Node, string) // set the text of a widget
|
||||
SetTitle func(*Node, string) // update the title of a window or tab
|
||||
SetLabel func(*Node, string) // update the "label" (aka "Name") for a widget
|
||||
SetChecked func(*Node, bool) // set the state of a checkbox
|
||||
ToolkitClose func() // shutdown and unload the plugin
|
||||
ShowTable func(*Node) // attempt at sending a whole table
|
||||
ok bool // indicates the plugin actually initialized
|
||||
PluginName string // used to identify the plugin
|
||||
config *ToolkitConfigs // protobuf of plugin settings
|
||||
callback chan widget.Action // mouse clicks or keyboard events back to the program
|
||||
pluginChan chan widget.Action // this is the channel we get requests to make widgets
|
||||
Add func(*Node) // add a new widget
|
||||
AddText func(*Node, string) // add a string to a dropdown widget
|
||||
SetText func(*Node, string) // set the text of a widget
|
||||
SetTitle func(*Node, string) // update the title of a window or tab
|
||||
SetLabel func(*Node, string) // update the "label" (aka "Name") for a widget
|
||||
SetChecked func(*Node, bool) // set the state of a checkbox
|
||||
ToolkitClose func() // shutdown and unload the plugin
|
||||
ShowTable func(*Node) // attempt at sending a whole table
|
||||
Show func(*Node) // show a widget
|
||||
Hide func(*Node) // hide a widget
|
||||
Enable func(*Node) // enable a widget
|
||||
Disable func(*Node) // disable a widget
|
||||
// NodeI interface{} // is an interface useful here?
|
||||
// NodeAction func(*Node, widget.ActionType) // deprecate
|
||||
}
|
||||
|
||||
type Node struct {
|
||||
|
|
Loading…
Reference in New Issue