summaryrefslogtreecommitdiff
path: root/andlabs/setText.go
blob: b89787d5b6e1017ffc53718475a72fe419879399 (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
107
108
109
110
111
112
113
114
115
116
117
118
package main

import (
	"go.wit.com/log"
	"go.wit.com/gui/widget"
)

func (n *node) setText(a *widget.Action) {
	log.Log(CHANGE, "setText() START with a.S =", a.S)
	t := n.tk
	if (t == nil) {
		log.Log(ERROR, "setText error. tk == nil", n.Name, n.WidgetId)
		actionDump(debugError, a)
		return
	}
	log.Log(CHANGE, "setText() Attempt on", n.WidgetType, "with", a.S)

	switch n.WidgetType {
	case widget.Window:
		t.uiWindow.SetTitle(a.S)
	case widget.Tab:
	case widget.Group:
		t.uiGroup.SetTitle(a.S)
	case widget.Checkbox:
		switch a.ActionType {
		case widget.SetText:
			t.uiCheckbox.SetText(a.S)
		case widget.Get:
			n.B = t.uiCheckbox.Checked()
		case widget.Set:
			// TODO: commented out while working on chan
			t.uiCheckbox.SetChecked(a.B)
		default:
			log.Log(ERROR, "setText() unknown", a.ActionType, "on checkbox", n.Name)
		}
	case widget.Textbox:
		switch a.ActionType {
		case widget.Set:
			if (t.uiEntry != nil) {
				t.uiEntry.SetText(a.S)
			}
			if (t.uiMultilineEntry != nil) {
				t.uiMultilineEntry.SetText(a.S)
			}
		case widget.SetText:
			if (t.uiEntry != nil) {
				t.uiEntry.SetText(a.S)
			}
			if (t.uiMultilineEntry != nil) {
				t.uiMultilineEntry.SetText(a.S)
			}
		default:
			log.Log(ERROR, "setText() unknown", a.ActionType, "on checkbox", n.Name)
		}
	case widget.Label:
		t.uiLabel.SetText(a.S)
	case widget.Button:
		t.uiButton.SetText(a.S)
	case widget.Slider:
		switch a.ActionType {
		case widget.Get:
			n.I = t.uiSlider.Value()
		case widget.Set:
			t.uiSlider.SetValue(a.I)
		default:
			log.Log(ERROR, "setText() unknown", a.ActionType, "on checkbox", n.Name)
		}
	case widget.Spinner:
		switch a.ActionType {
		case widget.Get:
			n.I = t.uiSpinbox.Value()
		case widget.Set:
			t.uiSpinbox.SetValue(a.I)
		default:
			log.Log(ERROR, "setText() unknown", a.ActionType, "on checkbox", n.Name)
		}
	case widget.Dropdown:
		var orig int
		var i int = -1
		var s string
		orig = t.uiCombobox.Selected()
		log.Log(CHANGE, "try to set the Dropdown to", a.S, "from", orig)
		// try to find the string
		for i, s = range t.val {
			log.Log(CHANGE, "i, s", i, s)
			if (a.S == s) {
				t.uiCombobox.SetSelected(i)
				log.Log(CHANGE, "setText() Dropdown worked.", n.S)
				return
			}
		}
		log.Log(ERROR, "setText() Dropdown did not find:", a.S)
		// if i == -1, then there are not any things in the menu to select
		if (i == -1) {
			return
		}
		// if the string was never set, then set the dropdown to the last thing added to the menu
		if (orig == -1) {
			t.uiCombobox.SetSelected(i)
		}
	case widget.Combobox:
		switch a.ActionType {
		case widget.AddText:
			t.AddComboboxName(a.S)
		case widget.Set:
			t.uiEditableCombobox.SetText(a.S)
			n.S = a.S
		case widget.SetText:
			t.uiEditableCombobox.SetText(a.S)
			n.S = a.S
		default:
			log.Log(ERROR, "setText() unknown", a.ActionType, "on checkbox", n.Name)
		}
	default:
		log.Log(ERROR, "plugin Send() Don't know how to setText on", n.WidgetType, "yet", a.ActionType)
	}
	log.Log(CHANGE, "setText() END with a.S =", a.S)
}