2019-06-02 15:40:44 -05:00
|
|
|
package gui
|
|
|
|
|
|
|
|
import "log"
|
|
|
|
import "fmt"
|
|
|
|
|
|
|
|
import "github.com/andlabs/ui"
|
|
|
|
import _ "github.com/andlabs/ui/winmanifest"
|
|
|
|
import "github.com/davecgh/go-spew/spew"
|
|
|
|
|
2019-06-02 17:19:53 -05:00
|
|
|
// functions for handling text entry boxes
|
2019-06-02 15:40:44 -05:00
|
|
|
|
|
|
|
func NewLabel(box *GuiBox, text string) {
|
2021-10-05 10:23:27 -05:00
|
|
|
box.Append(ui.NewLabel(text), false)
|
2019-06-02 15:40:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func GetText(box *GuiBox, name string) string {
|
|
|
|
if (box == nil) {
|
|
|
|
log.Println("gui.GetText() ERROR box == nil")
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
if (box.Window.EntryMap == nil) {
|
|
|
|
log.Println("gui.GetText() ERROR b.Box.Window.EntryMap == nil")
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
spew.Dump(box.Window.EntryMap)
|
|
|
|
if (box.Window.EntryMap[name] == nil) {
|
|
|
|
log.Println("gui.GetText() ERROR box.Window.EntryMap[", name, "] == nil ")
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
e := box.Window.EntryMap[name]
|
|
|
|
log.Println("gui.GetText() box.Window.EntryMap[", name, "] = ", e.UiEntry.Text())
|
|
|
|
log.Println("gui.GetText() END")
|
|
|
|
return e.UiEntry.Text()
|
|
|
|
}
|
|
|
|
|
|
|
|
func SetText(box *GuiBox, name string, value string) error {
|
|
|
|
if (box == nil) {
|
|
|
|
return fmt.Errorf("gui.SetText() ERROR box == nil")
|
|
|
|
}
|
|
|
|
if (box.Window.EntryMap == nil) {
|
|
|
|
return fmt.Errorf("gui.SetText() ERROR b.Box.Window.EntryMap == nil")
|
|
|
|
}
|
|
|
|
spew.Dump(box.Window.EntryMap)
|
|
|
|
if (box.Window.EntryMap[name] == nil) {
|
|
|
|
return fmt.Errorf("gui.SetText() ERROR box.Window.EntryMap[", name, "] == nil ")
|
|
|
|
}
|
|
|
|
e := box.Window.EntryMap[name]
|
|
|
|
log.Println("gui.SetText() box.Window.EntryMap[", name, "] = ", e.UiEntry.Text())
|
|
|
|
e.UiEntry.SetText(value)
|
|
|
|
log.Println("gui.SetText() box.Window.EntryMap[", name, "] = ", e.UiEntry.Text())
|
|
|
|
log.Println("gui.SetText() END")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// makeEntryBox(box, "hostname:", "blah.foo.org") {
|
|
|
|
func MakeEntryVbox(box *GuiBox, a string, startValue string, edit bool, action string) *GuiEntry {
|
|
|
|
// Start 'Nickname' vertical box
|
|
|
|
vboxN := ui.NewVerticalBox()
|
|
|
|
vboxN.SetPadded(true)
|
|
|
|
vboxN.Append(ui.NewLabel(a), false)
|
|
|
|
|
|
|
|
e := defaultMakeEntry(startValue, edit, action)
|
|
|
|
|
|
|
|
vboxN.Append(e.UiEntry, false)
|
|
|
|
box.UiBox.Append(vboxN, false)
|
|
|
|
// End 'Nickname' vertical box
|
|
|
|
|
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
|
|
|
func MakeEntryHbox(box *GuiBox, a string, startValue string, edit bool, action string) *GuiEntry {
|
|
|
|
hboxN := ui.NewHorizontalBox()
|
|
|
|
hboxN.SetPadded(true)
|
|
|
|
hboxN.Append(ui.NewLabel(a), false)
|
|
|
|
|
|
|
|
e := defaultMakeEntry(startValue, edit, action)
|
2019-06-13 20:53:06 -05:00
|
|
|
hboxN.Append(e.UiEntry, true)
|
2019-06-02 15:40:44 -05:00
|
|
|
|
2019-06-13 20:53:06 -05:00
|
|
|
box.UiBox.Append(hboxN, true)
|
2019-06-02 15:40:44 -05:00
|
|
|
|
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
|
|
|
func AddEntry(box *GuiBox, name string) *GuiEntry {
|
|
|
|
var ge *GuiEntry
|
|
|
|
ge = new(GuiEntry)
|
|
|
|
|
|
|
|
ue := ui.NewEntry()
|
|
|
|
ue.SetReadOnly(false)
|
|
|
|
ue.OnChanged(func(*ui.Entry) {
|
|
|
|
log.Println("gui.AddEntry() OK. ue.Text() =", ue.Text())
|
|
|
|
})
|
|
|
|
box.UiBox.Append(ue, false)
|
|
|
|
|
|
|
|
ge.UiEntry = ue
|
|
|
|
box.Window.EntryMap[name] = ge
|
|
|
|
|
|
|
|
return ge
|
|
|
|
}
|
2019-06-02 15:44:21 -05:00
|
|
|
|
|
|
|
func defaultEntryChange(e *ui.Entry) {
|
|
|
|
for key, em := range Data.AllEntries {
|
2019-06-02 17:49:52 -05:00
|
|
|
if (Config.Debug) {
|
2019-06-02 15:44:21 -05:00
|
|
|
log.Println("\tdefaultEntryChange() Data.AllEntries =", key, em)
|
|
|
|
}
|
|
|
|
if Data.AllEntries[key].UiEntry == e {
|
|
|
|
log.Println("defaultEntryChange() FOUND",
|
2019-06-02 23:56:43 -05:00
|
|
|
"Name =", Data.AllEntries[key].Name,
|
2019-06-02 15:44:21 -05:00
|
|
|
"Last =", Data.AllEntries[key].Last,
|
|
|
|
"e.Text() =", e.Text())
|
|
|
|
Data.AllEntries[key].Last = e.Text()
|
|
|
|
if Data.AllEntries[key].Normalize != nil {
|
|
|
|
fixed := Data.AllEntries[key].Normalize(e.Text())
|
|
|
|
e.SetText(fixed)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
log.Println("defaultEntryChange() ERROR. MISSING ENTRY MAP. e.Text() =", e.Text())
|
|
|
|
}
|
|
|
|
|
|
|
|
func defaultMakeEntry(startValue string, edit bool, action string) *GuiEntry {
|
|
|
|
e := ui.NewEntry()
|
|
|
|
e.SetText(startValue)
|
|
|
|
if (edit == false) {
|
|
|
|
e.SetReadOnly(true)
|
|
|
|
}
|
|
|
|
e.OnChanged(defaultEntryChange)
|
|
|
|
|
|
|
|
// add the entry field to the global map
|
|
|
|
var newEntry GuiEntry
|
|
|
|
newEntry.UiEntry = e
|
|
|
|
newEntry.Edit = edit
|
2019-06-02 23:56:43 -05:00
|
|
|
newEntry.Name = action
|
2019-06-02 23:01:18 -05:00
|
|
|
if (action == "INT") {
|
2019-06-02 15:44:21 -05:00
|
|
|
newEntry.Normalize = normalizeInt
|
|
|
|
}
|
|
|
|
Data.AllEntries = append(Data.AllEntries, &newEntry)
|
|
|
|
|
|
|
|
return &newEntry
|
|
|
|
}
|