debian/andlabs/setText.go

129 lines
3.2 KiB
Go
Raw Normal View History

2024-01-01 16:11:54 -06:00
package main
import (
"go.wit.com/gui/widget"
2024-01-01 16:11:54 -06:00
)
func (n *node) setText(a *widget.Action) {
2024-01-01 16:11:54 -06:00
log(debugChange, "setText() START with a.S =", a.S)
t := n.tk
if (t == nil) {
log(debugError, "setText error. tk == nil", n.Name, n.WidgetId)
actionDump(debugError, a)
return
}
log(debugChange, "setText() Attempt on", n.WidgetType, "with", a.S)
switch n.WidgetType {
case widget.Window:
2024-01-01 16:11:54 -06:00
t.uiWindow.SetTitle(a.S)
case widget.Tab:
case widget.Group:
2024-01-01 16:11:54 -06:00
t.uiGroup.SetTitle(a.S)
case widget.Checkbox:
2024-01-01 16:11:54 -06:00
switch a.ActionType {
case widget.SetText:
2024-01-01 16:11:54 -06:00
t.uiCheckbox.SetText(a.S)
case widget.Get:
2024-01-01 16:11:54 -06:00
n.B = t.uiCheckbox.Checked()
case widget.Set:
2024-01-01 16:11:54 -06:00
// TODO: commented out while working on chan
t.uiCheckbox.SetChecked(a.B)
default:
log(debugError, "setText() unknown", a.ActionType, "on checkbox", n.Name)
}
case widget.Textbox:
2024-01-01 16:11:54 -06:00
switch a.ActionType {
case widget.Set:
2024-01-01 16:11:54 -06:00
if (t.uiEntry != nil) {
t.uiEntry.SetText(a.S)
}
if (t.uiMultilineEntry != nil) {
t.uiMultilineEntry.SetText(a.S)
}
case widget.SetText:
2024-01-01 16:11:54 -06:00
if (t.uiEntry != nil) {
t.uiEntry.SetText(a.S)
}
if (t.uiMultilineEntry != nil) {
t.uiMultilineEntry.SetText(a.S)
}
default:
log(debugError, "setText() unknown", a.ActionType, "on checkbox", n.Name)
}
case widget.Label:
2024-01-01 16:11:54 -06:00
t.uiLabel.SetText(a.S)
case widget.Button:
2024-01-01 16:11:54 -06:00
t.uiButton.SetText(a.S)
case widget.Slider:
2024-01-01 16:11:54 -06:00
switch a.ActionType {
case widget.Get:
2024-01-01 16:11:54 -06:00
n.I = t.uiSlider.Value()
case widget.Set:
2024-01-01 16:11:54 -06:00
t.uiSlider.SetValue(a.I)
default:
log(debugError, "setText() unknown", a.ActionType, "on checkbox", n.Name)
}
case widget.Spinner:
2024-01-01 16:11:54 -06:00
switch a.ActionType {
case widget.Get:
2024-01-01 16:11:54 -06:00
n.I = t.uiSpinbox.Value()
case widget.Set:
2024-01-01 16:11:54 -06:00
t.uiSpinbox.SetValue(a.I)
default:
log(debugError, "setText() unknown", a.ActionType, "on checkbox", n.Name)
}
case widget.Dropdown:
2024-01-01 16:11:54 -06:00
switch a.ActionType {
case widget.AddText:
2024-01-01 16:11:54 -06:00
n.AddDropdownName(a.S)
case widget.Set:
2024-01-01 16:11:54 -06:00
var orig int
var i int = -1
var s string
orig = t.uiCombobox.Selected()
log(debugChange, "try to set the Dropdown to", a.S, "from", orig)
// try to find the string
for i, s = range t.val {
log(debugChange, "i, s", i, s)
if (a.S == s) {
t.uiCombobox.SetSelected(i)
log(debugChange, "setText() Dropdown worked.", n.S)
return
}
}
log(debugError, "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.Get:
2024-01-01 16:11:54 -06:00
// t.S = t.s
case widget.GetText:
2024-01-01 16:11:54 -06:00
// t.S = t.s
default:
log(debugError, "setText() unknown", a.ActionType, "on checkbox", n.Name)
}
case widget.Combobox:
2024-01-01 16:11:54 -06:00
switch a.ActionType {
case widget.AddText:
2024-01-01 16:11:54 -06:00
t.AddComboboxName(a.S)
case widget.Set:
2024-01-01 16:11:54 -06:00
t.uiEditableCombobox.SetText(a.S)
n.S = a.S
case widget.SetText:
2024-01-01 16:11:54 -06:00
t.uiEditableCombobox.SetText(a.S)
n.S = a.S
default:
log(debugError, "setText() unknown", a.ActionType, "on checkbox", n.Name)
}
default:
log(debugError, "plugin Send() Don't know how to setText on", n.WidgetType, "yet", a.ActionType)
}
log(debugChange, "setText() END with a.S =", a.S)
}