summaryrefslogtreecommitdiff
path: root/event.go
blob: 62b43c23dc694a04538b457e754d683af888deb1 (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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
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("SendEnableDebugger() 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("SendToolkitLoad() callback == nil")
		return
	}
	var a widget.Action
	a.ActionType = widget.ToolkitLoad
	a.ProgName = me.PluginName
	a.Value = s
	log.Warn("SendToolkitLoad() START: toolkit load", s)
	me.callback <- a
	log.Warn("SendToolkitLoad() END:   toolkit load", s)
	return
}

func (me *TreeInfo) SendToolkitPanic() {
	if me.callback == nil {
		log.Warn("SendToolkitPanic() callback == nil")
		return
	}
	var a widget.Action
	a.ActionType = widget.ToolkitPanic
	a.ProgName = me.PluginName
	log.Log(TREE, "SendToolkitPanic() START")
	me.callback <- a
	log.Log(TREE, "SendToolkitPanic() END")
	return
}

func (me *TreeInfo) SendWindowCloseEvent(n *Node) {
	if me.callback == nil {
		log.Warn("SendWindowClose() callback == nil", n.WidgetId)
		return
	}
	var a widget.Action
	a.WidgetId = n.WidgetId
	a.ActionType = widget.CloseWindow
	log.Log(TREE, "SendWindowClose() START: user closed the window", n.GetProgName())
	me.callback <- a
	log.Log(TREE, "SendWindowClose() END:   user closed the window", n.GetProgName())
	return
}

// 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)
}

// 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.State = n.State
	a.ActionType = widget.User
	if n.WidgetType == widget.Checkbox {
		log.Log(TREE, "SendUserEvent() checkbox going to send:", a.Value)
	}
	log.Log(TREE, "SendUserEvent() START: send a user event to the callback channel")
	me.callback <- a
	log.Log(TREE, "SendUserEvent() END:   sent a user event to the callback channel")
	return
}