2024-01-01 16:11:54 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2024-01-15 16:11:40 -06:00
|
|
|
"go.wit.com/dev/andlabs/ui"
|
|
|
|
_ "go.wit.com/dev/andlabs/ui/winmanifest"
|
2024-01-01 16:11:54 -06:00
|
|
|
|
2024-01-08 21:19:42 -06:00
|
|
|
"go.wit.com/log"
|
2024-01-17 21:31:49 -06:00
|
|
|
"go.wit.com/gui/toolkits/tree"
|
2024-01-01 16:11:54 -06:00
|
|
|
)
|
|
|
|
|
2024-01-17 21:31:49 -06:00
|
|
|
func newDropdown(p, n *tree.Node) {
|
|
|
|
if notNew(n) { return }
|
2024-01-01 16:11:54 -06:00
|
|
|
newt := new(guiWidget)
|
2024-01-17 21:31:49 -06:00
|
|
|
log.Log(INFO, "gui.Toolbox.newDropdown() START", n.GetProgName())
|
2024-01-01 16:11:54 -06:00
|
|
|
|
|
|
|
cb := ui.NewCombobox()
|
|
|
|
newt.uiCombobox = cb
|
|
|
|
newt.uiControl = cb
|
|
|
|
|
|
|
|
// initialize the index
|
|
|
|
newt.c = 0
|
|
|
|
newt.val = make(map[int]string)
|
|
|
|
|
|
|
|
cb.OnSelected(func(spin *ui.Combobox) {
|
|
|
|
i := spin.Selected()
|
|
|
|
if (newt.val == nil) {
|
2024-01-08 21:19:42 -06:00
|
|
|
log.Log(ERROR, "make map didn't work")
|
2024-01-17 21:31:49 -06:00
|
|
|
n.SetValue("map did not work. ui.Combobox error")
|
2024-01-01 16:11:54 -06:00
|
|
|
} else {
|
2024-01-17 21:31:49 -06:00
|
|
|
n.SetValue(newt.val[i])
|
2024-01-01 16:11:54 -06:00
|
|
|
}
|
2024-01-17 21:31:49 -06:00
|
|
|
me.myTree.DoUserEvent(n)
|
2024-01-01 16:11:54 -06:00
|
|
|
})
|
|
|
|
|
2024-01-13 21:28:41 -06:00
|
|
|
|
2024-01-17 21:31:49 -06:00
|
|
|
n.TK = newt
|
|
|
|
place(p, n)
|
2024-01-01 16:11:54 -06:00
|
|
|
|
2024-01-17 21:31:49 -06:00
|
|
|
log.Warn("add dropdown entries on create:", n.State.Strings)
|
|
|
|
log.Warn("add dropdown entries on create:", n.State.Strings)
|
|
|
|
log.Warn("add dropdown entries on create:", n.State.Strings)
|
|
|
|
if n.State.Strings == nil {return}
|
2024-01-13 21:28:41 -06:00
|
|
|
// add the initial dropdown entries
|
2024-01-17 21:31:49 -06:00
|
|
|
for i, s := range n.State.Strings {
|
|
|
|
log.Warn("add dropdown: add entries on create", n.GetProgName(), i, s)
|
|
|
|
addDropdownName(n, s)
|
2024-01-01 16:11:54 -06:00
|
|
|
}
|
2024-01-17 21:31:49 -06:00
|
|
|
cur := n.String()
|
|
|
|
log.Warn("add dropdown: set default value on create", n.GetProgName(), cur)
|
|
|
|
setDropdownName(n, cur)
|
2024-01-01 16:11:54 -06:00
|
|
|
}
|
|
|
|
|
2024-01-17 21:31:49 -06:00
|
|
|
func setDropdownInt(n *tree.Node, i int) {
|
|
|
|
if ! ready(n) { return }
|
|
|
|
var tk *guiWidget
|
|
|
|
tk = n.TK.(*guiWidget)
|
|
|
|
tk.uiCombobox.SetSelected(i)
|
2024-01-01 16:11:54 -06:00
|
|
|
}
|
|
|
|
|
2024-01-17 21:31:49 -06:00
|
|
|
func addDropdownName(n *tree.Node, s string) {
|
|
|
|
if ! ready(n) { return }
|
|
|
|
var tk *guiWidget
|
|
|
|
tk = n.TK.(*guiWidget)
|
2024-01-13 21:28:41 -06:00
|
|
|
log.Log(INFO, "addDropdownName()", n.WidgetId, "add:", s)
|
2024-01-01 16:11:54 -06:00
|
|
|
|
2024-01-17 21:31:49 -06:00
|
|
|
tk.uiCombobox.Append(s)
|
|
|
|
if (tk.val == nil) {
|
2024-01-13 21:28:41 -06:00
|
|
|
log.Log(INFO, "make map didn't work")
|
2024-01-01 16:11:54 -06:00
|
|
|
return
|
|
|
|
}
|
2024-01-17 21:31:49 -06:00
|
|
|
tk.val[tk.c] = s
|
2024-01-13 21:28:41 -06:00
|
|
|
|
|
|
|
// If this is the first menu added, set the dropdown to it
|
2024-01-17 21:31:49 -06:00
|
|
|
if (tk.c == 0) {
|
2024-01-13 21:28:41 -06:00
|
|
|
log.Log(INFO, "THIS IS THE FIRST Dropdown", s)
|
2024-01-17 21:31:49 -06:00
|
|
|
tk.uiCombobox.SetSelected(0)
|
2024-01-13 21:28:41 -06:00
|
|
|
}
|
2024-01-17 21:31:49 -06:00
|
|
|
tk.c = tk.c + 1
|
2024-01-01 16:11:54 -06:00
|
|
|
}
|
|
|
|
|
2024-01-17 21:31:49 -06:00
|
|
|
func setDropdownName(n *tree.Node, s string) bool {
|
|
|
|
if ! ready(n) { return false}
|
|
|
|
var tk *guiWidget
|
|
|
|
tk = n.TK.(*guiWidget)
|
2024-01-13 21:28:41 -06:00
|
|
|
log.Log(INFO, "SetDropdownName()", n.WidgetId, ",", s)
|
2024-01-01 16:11:54 -06:00
|
|
|
|
2024-01-17 21:31:49 -06:00
|
|
|
for i, tmp := range tk.val {
|
2024-01-13 21:28:41 -06:00
|
|
|
if s == tmp {
|
2024-01-17 21:31:49 -06:00
|
|
|
n.SetValue(s)
|
|
|
|
setDropdownInt(n, i)
|
2024-01-13 21:28:41 -06:00
|
|
|
log.Warn("SetDropdownInt() worked", tmp, i)
|
|
|
|
return true
|
|
|
|
}
|
2024-01-01 16:11:54 -06:00
|
|
|
}
|
2024-01-13 21:28:41 -06:00
|
|
|
log.Warn("SetDropdownName() failed", s)
|
|
|
|
return false
|
2024-01-01 16:11:54 -06:00
|
|
|
}
|