summaryrefslogtreecommitdiff
path: root/action.go
blob: ca8b089ee47e358366a064a93e920dae0df262e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package main

/*
	a simple function to handle widget actions

	You can tie this into your toolkit here.
*/

import (
	"go.wit.com/log"
	"go.wit.com/widget"
	// "go.wit.com/toolkits/tree"
)

func doAction(a widget.Action) {
	log.Log(INFO, "doAction() START a.ActionType =", a.ActionType)
	log.Log(INFO, "doAction() START a.ProgName =", a.ProgName)

	if a.ActionType == widget.ToolkitInit {
		return
	}

	log.Log(INFO, "doAction() START a.WidgetId =", a.WidgetId, "a.ParentId =", a.ParentId)
	switch a.WidgetType {
	case widget.Root:
		me.treeRoot = me.myTree.AddNode(&a)
		log.Log(INFO, "doAction() found treeRoot")
		return
	}

	switch a.ActionType {
	case widget.Add:
		me.myTree.AddNode(&a)
		return
	}

	n := me.treeRoot.FindWidgetId(a.WidgetId)
	if n == nil {
		log.Warn("FindId() n == nil", a.WidgetId, a.ActionType)
		log.Warn("FindId() n == nil", a.WidgetId, a.ActionType)
		log.Warn("FindId() n == nil", a.WidgetId, a.ActionType)
		log.Warn("Aaaaa!, return")
		return
	}

	switch a.ActionType {
	case widget.Show:
		n.State.Hidden = true
	case widget.Hide:
		n.State.Hidden = false
	case widget.Enable:
		n.State.Enable = true
	case widget.Disable:
		n.State.Enable = false
	case widget.Get:
		log.Warn("value =", n.State.Value)
	case widget.GetText:
		log.Warn("value =", n.String())
	case widget.Set:
		n.State.Value = a.State.Value
	case widget.SetText:
		log.Warn("GOT TO SetText()", a.WidgetId)
		log.Warn("GOT TO SetText()", a.WidgetId)
		log.Warn("GOT TO SetText()", a.WidgetId)
		log.Warn("GOT TO SetText()", a.WidgetId)
		if n == nil {
			log.Warn("HOT DIGGITY. n == nil")
		}
		n.State.Value = a.State.Value
	case widget.AddText:
		n.State.Strings = append(a.State.Strings, widget.GetString(a.State.Value))
	case widget.Margin:
		n.State.Pad = true
	case widget.Unmargin:
		n.State.Pad = false
	case widget.Pad:
		n.State.Pad = true
	case widget.Unpad:
		n.State.Pad = false
	case widget.Delete:
		log.Warn("doAction() TODO: Delete()")
		n.DeleteNode()
	case widget.Move:
		log.Warn("doAction() TODO: Move()")
	case widget.ToolkitClose:
		log.Warn("doAction() toolkit closed. are the channels cleand up?")
		return
	default:
		log.Log(ERROR, "doAction() Unknown =", a.ActionType, a.WidgetType)
	}
	log.Log(INFO, "doAction() END =", a.ActionType, a.WidgetType)
}