summaryrefslogtreecommitdiff
path: root/action.go
diff options
context:
space:
mode:
Diffstat (limited to 'action.go')
-rw-r--r--action.go87
1 files changed, 87 insertions, 0 deletions
diff --git a/action.go b/action.go
new file mode 100644
index 0000000..3ae03e4
--- /dev/null
+++ b/action.go
@@ -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)
+ }
+}