2024-01-17 23:54:19 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"go.wit.com/dev/andlabs/ui"
|
|
|
|
_ "go.wit.com/dev/andlabs/ui/winmanifest"
|
|
|
|
|
|
|
|
"go.wit.com/log"
|
|
|
|
"go.wit.com/toolkits/tree"
|
|
|
|
)
|
|
|
|
|
|
|
|
func newCombobox(p, n *tree.Node) {
|
|
|
|
if notNew(n) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
newt := new(guiWidget)
|
|
|
|
|
|
|
|
cb := ui.NewEditableCombobox()
|
|
|
|
newt.uiEditableCombobox = cb
|
|
|
|
newt.uiControl = cb
|
|
|
|
|
|
|
|
// initialize the index
|
|
|
|
newt.c = 0
|
|
|
|
newt.val = make(map[int]string)
|
|
|
|
|
|
|
|
cb.OnChanged(func(spin *ui.EditableCombobox) {
|
2024-02-05 15:04:01 -06:00
|
|
|
n.State.CurrentS = spin.Text()
|
2024-01-21 11:30:12 -06:00
|
|
|
log.Log(ANDLABS, "combobox changed ="+spin.Text()+".")
|
2024-01-19 02:52:57 -06:00
|
|
|
me.myTree.SendUserEvent(n)
|
2024-01-17 23:54:19 -06:00
|
|
|
})
|
|
|
|
|
|
|
|
n.TK = newt
|
|
|
|
place(p, n)
|
|
|
|
|
2024-01-21 11:30:12 -06:00
|
|
|
log.Log(ANDLABS, "add combobox entries on create:", n.State.Strings)
|
2024-01-17 23:54:19 -06:00
|
|
|
// add the initial combobox entries
|
|
|
|
for i, s := range n.State.Strings {
|
2024-02-07 07:31:28 -06:00
|
|
|
log.Log(ANDLABS, "add combobox entries on create progname:", n.GetProgName(), "State.Strings =", i, s)
|
2024-01-17 23:54:19 -06:00
|
|
|
addComboboxName(n, s)
|
|
|
|
}
|
2024-02-07 07:31:28 -06:00
|
|
|
cur := n.CurrentS()
|
|
|
|
log.Log(ANDLABS, "add combobox: set default value on create to", cur)
|
2024-01-17 23:54:19 -06:00
|
|
|
setComboboxName(n, cur)
|
|
|
|
}
|
|
|
|
|
|
|
|
func addComboboxName(n *tree.Node, s string) {
|
|
|
|
if !ready(n) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
var tk *guiWidget
|
|
|
|
tk = n.TK.(*guiWidget)
|
2024-02-07 07:31:28 -06:00
|
|
|
log.Log(ANDLABS, "addComboboxName()", n.WidgetId, "add:", s)
|
2024-01-17 23:54:19 -06:00
|
|
|
|
|
|
|
tk.uiEditableCombobox.Append(s)
|
|
|
|
if tk.val == nil {
|
|
|
|
log.Log(INFO, "make map didn't work")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
tk.val[tk.c] = s
|
|
|
|
|
|
|
|
// If this is the first menu added, set the dropdown to it
|
|
|
|
if tk.c == 0 {
|
2024-02-07 07:31:28 -06:00
|
|
|
log.Log(ANDLABS, "addComboboxName() first string:", s)
|
2024-01-17 23:54:19 -06:00
|
|
|
tk.uiEditableCombobox.SetText(s)
|
|
|
|
}
|
|
|
|
tk.c = tk.c + 1
|
|
|
|
}
|
|
|
|
|
|
|
|
func setComboboxName(n *tree.Node, s string) bool {
|
|
|
|
if !ready(n) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
var tk *guiWidget
|
|
|
|
tk = n.TK.(*guiWidget)
|
2024-02-07 07:31:28 -06:00
|
|
|
log.Log(ANDLABS, "SetComboboxName()", n.WidgetId, ",", s)
|
2024-01-17 23:54:19 -06:00
|
|
|
tk.uiEditableCombobox.SetText(s)
|
|
|
|
return false
|
|
|
|
}
|