2019-05-22 22:49:28 -05:00
|
|
|
package gui
|
|
|
|
|
|
|
|
import "log"
|
2019-05-24 23:07:40 -05:00
|
|
|
import "time"
|
2019-05-27 19:23:19 -05:00
|
|
|
import "regexp"
|
2019-05-30 03:58:05 -05:00
|
|
|
import "os"
|
2019-05-30 02:51:59 -05:00
|
|
|
// import "reflect"
|
2019-05-22 22:49:28 -05:00
|
|
|
|
|
|
|
import "github.com/andlabs/ui"
|
|
|
|
import _ "github.com/andlabs/ui/winmanifest"
|
|
|
|
|
2019-05-24 22:54:09 -05:00
|
|
|
import pb "git.wit.com/wit/witProtobuf"
|
2019-05-24 23:07:40 -05:00
|
|
|
|
2019-05-29 09:24:40 -05:00
|
|
|
// import "github.com/davecgh/go-spew/spew"
|
2019-05-22 22:49:28 -05:00
|
|
|
|
2019-05-30 10:52:28 -05:00
|
|
|
func makeCloudInfoBox(wm *GuiWindow) *ui.Box {
|
2019-05-22 22:49:28 -05:00
|
|
|
hbox := ui.NewHorizontalBox()
|
|
|
|
hbox.SetPadded(true)
|
|
|
|
|
2019-05-24 20:17:05 -05:00
|
|
|
if (Data.Debug) {
|
2019-05-29 15:11:08 -05:00
|
|
|
log.Println("makeCloudInfoBox() add debugging buttons")
|
2019-05-24 02:40:52 -05:00
|
|
|
vbox := ui.NewVerticalBox()
|
|
|
|
vbox.SetPadded(true)
|
|
|
|
hbox.Append(vbox, false)
|
2019-05-22 22:49:28 -05:00
|
|
|
|
2019-05-29 21:57:15 -05:00
|
|
|
addDebuggingButtons(wm, vbox)
|
2019-05-22 22:49:28 -05:00
|
|
|
|
2019-05-24 02:40:52 -05:00
|
|
|
hbox.Append(ui.NewVerticalSeparator(), false)
|
|
|
|
}
|
2019-05-22 22:49:28 -05:00
|
|
|
|
2019-05-24 02:40:52 -05:00
|
|
|
vbox := ui.NewVerticalBox()
|
2019-05-22 22:49:28 -05:00
|
|
|
vbox.SetPadded(true)
|
|
|
|
hbox.Append(vbox, true)
|
|
|
|
|
2019-05-24 02:04:14 -05:00
|
|
|
hostnamebox := ui.NewHorizontalBox()
|
|
|
|
hostnamebox.SetPadded(true)
|
|
|
|
vbox.Append(hostnamebox, false)
|
|
|
|
|
2019-05-22 22:49:28 -05:00
|
|
|
entryForm := ui.NewForm()
|
|
|
|
entryForm.SetPadded(true)
|
2019-05-24 02:04:14 -05:00
|
|
|
hostnamebox.Append(entryForm, true)
|
2019-05-22 22:49:28 -05:00
|
|
|
|
|
|
|
hostnameEntry := ui.NewEntry()
|
|
|
|
entryForm.Append("hostname:", hostnameEntry, false)
|
2019-05-24 02:04:14 -05:00
|
|
|
tmp := Data.Hostname + " (" + Data.IPv6 + ")"
|
|
|
|
hostnameEntry.SetText(tmp)
|
|
|
|
hostnameEntry.SetReadOnly(true)
|
2019-05-22 22:49:28 -05:00
|
|
|
|
2019-05-30 13:41:23 -05:00
|
|
|
anew := CreateButton(wm, nil, nil, "Edit", "EDIT", nil)
|
|
|
|
hostnamebox.Append(anew.B, false)
|
2019-05-22 22:49:28 -05:00
|
|
|
|
2019-05-23 11:48:12 -05:00
|
|
|
vbox.Append(ui.NewHorizontalSeparator(), false)
|
|
|
|
|
|
|
|
agrid := ui.NewGrid()
|
|
|
|
agrid.SetPadded(true)
|
|
|
|
|
2019-05-23 17:07:10 -05:00
|
|
|
agrid.Append(ui.NewLabel("Accounts:"), 0, 0, 1, 1, true, ui.AlignFill, false, ui.AlignFill)
|
|
|
|
agrid.Append(ui.NewLabel("Nickname"), 1, 0, 1, 1, true, ui.AlignFill, false, ui.AlignFill)
|
|
|
|
agrid.Append(ui.NewLabel("Username"), 2, 0, 1, 1, true, ui.AlignFill, false, ui.AlignFill)
|
|
|
|
agrid.Append(ui.NewLabel("Domain Name"), 3, 0, 1, 1, true, ui.AlignFill, false, ui.AlignFill)
|
|
|
|
|
|
|
|
row := 1
|
|
|
|
|
2019-05-27 23:29:30 -05:00
|
|
|
for key, a := range Data.Config.Accounts {
|
|
|
|
log.Println("account = ", key, a)
|
2019-05-26 04:19:09 -05:00
|
|
|
log.Println("Accounts[key] = ", Data.Config.Accounts[key])
|
|
|
|
log.Println("account.Nick = ", Data.Config.Accounts[key].Nick)
|
2019-05-24 20:17:05 -05:00
|
|
|
log.Println("account.Username = ", Data.Config.Accounts[key].Username)
|
2019-05-26 04:19:09 -05:00
|
|
|
log.Println("account.Token = ", Data.Config.Accounts[key].Token)
|
2019-05-23 17:07:10 -05:00
|
|
|
|
2019-05-26 04:19:09 -05:00
|
|
|
agrid.Append(ui.NewLabel(Data.Config.Accounts[key].Nick), 1, row, 1, 1, true, ui.AlignFill, false, ui.AlignFill)
|
|
|
|
agrid.Append(ui.NewLabel(Data.Config.Accounts[key].Username), 2, row, 1, 1, true, ui.AlignFill, false, ui.AlignFill)
|
|
|
|
agrid.Append(ui.NewLabel(Data.Config.Accounts[key].Domain), 3, row, 1, 1, true, ui.AlignFill, false, ui.AlignFill)
|
2019-05-23 19:44:00 -05:00
|
|
|
|
2019-05-24 22:54:09 -05:00
|
|
|
name := "Login " + Data.Config.Accounts[key].Nick
|
2019-05-29 21:57:15 -05:00
|
|
|
l := CreateButton(wm, Data.Config.Accounts[key], nil, name, "LOGIN", nil)
|
2019-05-30 13:41:23 -05:00
|
|
|
agrid.Append(l.B, 4, row, 1, 1, true, ui.AlignFill, false, ui.AlignFill)
|
2019-05-24 02:04:14 -05:00
|
|
|
|
2019-05-24 22:54:09 -05:00
|
|
|
name = "Show " + Data.Config.Accounts[key].Nick
|
2019-05-29 21:57:15 -05:00
|
|
|
b := CreateButton(wm, Data.Config.Accounts[key], nil, name, "SHOW", nil)
|
2019-05-30 13:41:23 -05:00
|
|
|
agrid.Append(b.B, 5, row, 1, 1, true, ui.AlignFill, false, ui.AlignFill)
|
2019-05-23 17:07:10 -05:00
|
|
|
|
|
|
|
row += 1
|
2019-05-23 11:48:12 -05:00
|
|
|
}
|
2019-05-24 20:17:05 -05:00
|
|
|
|
2019-05-24 02:40:52 -05:00
|
|
|
row += 1
|
|
|
|
agrid.Append(ui.NewLabel(""), 1, row, 1, 1, true, ui.AlignFill, false, ui.AlignFill)
|
|
|
|
row += 1
|
2019-05-29 21:57:15 -05:00
|
|
|
a := CreateButton(wm, nil, nil, "Add Account", "ADD TAB", nil)
|
2019-05-30 13:41:23 -05:00
|
|
|
agrid.Append(a.B, 4, row, 1, 1, true, ui.AlignFill, false, ui.AlignFill)
|
2019-05-29 21:57:15 -05:00
|
|
|
q := CreateButton(wm, nil, nil, "Quit", "QUIT", nil)
|
2019-05-30 13:41:23 -05:00
|
|
|
agrid.Append(q.B, 5, row, 1, 1, true, ui.AlignFill, false, ui.AlignFill)
|
2019-05-23 17:07:10 -05:00
|
|
|
|
|
|
|
vbox.Append(agrid, false)
|
2019-05-22 22:49:28 -05:00
|
|
|
return hbox
|
|
|
|
}
|
|
|
|
|
2019-05-24 23:07:40 -05:00
|
|
|
//
|
|
|
|
// THIS IS THE STANDARD VM DISPLAY TABLE
|
|
|
|
// This maps the 'human' indexed cells in the table
|
|
|
|
// to the machine's andlabs/libui values. That way
|
|
|
|
// if you want to work against column 4, then you
|
|
|
|
// can just reference 4 instead of the internal number
|
|
|
|
// which could be anything since TEXTCOLOR, TEXT, BG, etc
|
|
|
|
// fields use between 1 and 3 values internally
|
|
|
|
//
|
2019-05-30 10:52:28 -05:00
|
|
|
func AddVmsTab(wm *GuiWindow, name string, count int, a *pb.Account) *TableData {
|
2019-05-22 22:49:28 -05:00
|
|
|
var parts []TableColumnData
|
|
|
|
|
|
|
|
human := 0
|
|
|
|
|
|
|
|
tmp := TableColumnData{}
|
|
|
|
tmp.CellType = "BG"
|
|
|
|
tmp.Heading = "background"
|
|
|
|
tmp.Index = human
|
|
|
|
parts = append(parts, tmp)
|
|
|
|
human += 1
|
|
|
|
|
|
|
|
tmp = TableColumnData{}
|
|
|
|
tmp.CellType = "TEXTCOLOR"
|
|
|
|
tmp.Heading = "name"
|
|
|
|
tmp.Index = human
|
|
|
|
parts = append(parts, tmp)
|
|
|
|
human += 1
|
|
|
|
|
|
|
|
tmp = TableColumnData{}
|
|
|
|
tmp.CellType = "TEXTCOLOR"
|
|
|
|
tmp.Heading = "hostname"
|
|
|
|
tmp.Index = human
|
|
|
|
parts = append(parts, tmp)
|
|
|
|
human += 1
|
|
|
|
|
|
|
|
tmp = TableColumnData{}
|
|
|
|
tmp.CellType = "TEXTCOLOR"
|
|
|
|
tmp.Heading = "IPv6"
|
|
|
|
tmp.Index = human
|
|
|
|
parts = append(parts, tmp)
|
|
|
|
human += 1
|
|
|
|
|
|
|
|
tmp = TableColumnData{}
|
|
|
|
tmp.CellType = "TEXTCOLOR"
|
|
|
|
tmp.Heading = "cpus"
|
|
|
|
tmp.Index = human
|
|
|
|
parts = append(parts, tmp)
|
|
|
|
human += 1
|
|
|
|
|
|
|
|
tmp = TableColumnData{}
|
|
|
|
tmp.CellType = "TEXTCOLOR"
|
|
|
|
tmp.Heading = "memory"
|
|
|
|
tmp.Index = human
|
|
|
|
parts = append(parts, tmp)
|
|
|
|
human += 1
|
|
|
|
|
|
|
|
tmp = TableColumnData{}
|
|
|
|
tmp.CellType = "BUTTON"
|
2019-05-24 23:07:40 -05:00
|
|
|
tmp.Heading = "Details"
|
2019-05-22 22:49:28 -05:00
|
|
|
tmp.Index = human
|
|
|
|
parts = append(parts, tmp)
|
|
|
|
human += 1
|
|
|
|
|
2019-05-29 21:57:15 -05:00
|
|
|
mh := AddTableTab(wm, wm.T, 1, name, count, parts, a)
|
2019-05-22 22:49:28 -05:00
|
|
|
return mh
|
|
|
|
}
|
2019-05-24 23:07:40 -05:00
|
|
|
|
2019-05-30 10:52:28 -05:00
|
|
|
func ShowAccountQuestionTab(wm *GuiWindow) {
|
2019-05-30 03:58:05 -05:00
|
|
|
log.Println("ShowAccountQuestionTab() wm =", wm)
|
|
|
|
if (wm.T == nil) {
|
|
|
|
log.Println("ShowAccountQuestionTab() wm.T = nil THIS IS BAD")
|
|
|
|
os.Exit(-1)
|
|
|
|
}
|
2019-05-29 21:57:15 -05:00
|
|
|
wm.T.Delete(0)
|
2019-05-24 23:07:40 -05:00
|
|
|
|
|
|
|
log.Println("Sleep(200)")
|
|
|
|
time.Sleep(200 * time.Millisecond)
|
|
|
|
|
2019-05-29 21:57:15 -05:00
|
|
|
wm.Box2 = AddAccountQuestionBox(wm)
|
|
|
|
wm.T.InsertAt("New Account?", 0, wm.Box2)
|
|
|
|
wm.T.SetMargined(0, true)
|
2019-05-24 23:07:40 -05:00
|
|
|
}
|
|
|
|
|
2019-05-30 10:52:28 -05:00
|
|
|
func ShowAccountTab(wm *GuiWindow, i int) {
|
2019-05-27 17:25:30 -05:00
|
|
|
log.Println("ShowAccountTab() START")
|
2019-05-24 23:07:40 -05:00
|
|
|
|
|
|
|
log.Println("Sleep(200)")
|
|
|
|
time.Sleep(200 * time.Millisecond)
|
|
|
|
|
2019-05-25 03:36:36 -05:00
|
|
|
// Create the things for the Account Tab
|
2019-05-29 21:57:15 -05:00
|
|
|
abox := AddAccountBox(wm)
|
2019-05-25 03:36:36 -05:00
|
|
|
|
|
|
|
// Set the parents and data structure links
|
2019-05-29 21:57:15 -05:00
|
|
|
// aTab.me = wm.T
|
2019-05-29 14:21:10 -05:00
|
|
|
// aTab.parentWindow = Data.Window1.W
|
2019-05-27 17:25:30 -05:00
|
|
|
// aTab.tabOffset = 0
|
2019-05-27 12:55:10 -05:00
|
|
|
|
|
|
|
if (i >= 0) {
|
2019-05-27 17:25:30 -05:00
|
|
|
log.Println("ShowAccountTab() InsertAt i=", i)
|
2019-05-29 21:57:15 -05:00
|
|
|
wm.T.Delete(0)
|
|
|
|
wm.T.InsertAt("Add Account", i, abox)
|
|
|
|
wm.T.SetMargined(0, true)
|
2019-05-27 12:55:10 -05:00
|
|
|
} else {
|
2019-05-27 17:25:30 -05:00
|
|
|
// TODO: After append try to discover the tab index #
|
|
|
|
log.Println("ShowAccountTab() Append")
|
2019-05-29 21:57:15 -05:00
|
|
|
AddBoxToTab("Create New Account", wm.T, abox)
|
2019-05-27 12:55:10 -05:00
|
|
|
}
|
2019-05-24 23:07:40 -05:00
|
|
|
}
|
|
|
|
|
2019-05-30 10:52:28 -05:00
|
|
|
func ShowMainTab(wm *GuiWindow) {
|
2019-05-29 21:57:15 -05:00
|
|
|
log.Println("ShowMainTab() wm =", wm)
|
|
|
|
log.Println("ShowMainTab() wm.T =", wm.T)
|
|
|
|
log.Println("ShowMainTab() wm.T =", wm.T)
|
|
|
|
wm.T.Delete(0)
|
2019-05-24 23:07:40 -05:00
|
|
|
|
|
|
|
log.Println("Sleep(200)")
|
|
|
|
time.Sleep(200 * time.Millisecond)
|
|
|
|
|
2019-05-29 21:57:15 -05:00
|
|
|
wm.Box2 = makeCloudInfoBox(wm)
|
|
|
|
wm.T.InsertAt("Main", 0, wm.Box2)
|
|
|
|
wm.T.SetMargined(0, true)
|
2019-05-24 23:07:40 -05:00
|
|
|
}
|
|
|
|
|
2019-05-30 00:24:41 -05:00
|
|
|
func StartNewWindow(c *pb.Config, bg bool, action string) {
|
2019-05-29 21:57:15 -05:00
|
|
|
log.Println("InitNewWindow() Create a new window")
|
2019-05-30 10:52:28 -05:00
|
|
|
var newGuiWindow GuiWindow
|
|
|
|
newGuiWindow.C = c
|
|
|
|
newGuiWindow.Action = action
|
|
|
|
Data.Windows = append(Data.Windows, &newGuiWindow)
|
2019-05-29 21:57:15 -05:00
|
|
|
|
2019-05-29 22:48:26 -05:00
|
|
|
ui.OnShouldQuit(func() bool {
|
|
|
|
// mouseClick(&newBM)
|
|
|
|
ui.Quit()
|
|
|
|
return true
|
|
|
|
})
|
|
|
|
|
2019-05-30 02:51:59 -05:00
|
|
|
if (bg) {
|
|
|
|
log.Println("ShowWindow() IN NEW GOROUTINE")
|
|
|
|
go ui.Main(func() {
|
2019-05-30 10:52:28 -05:00
|
|
|
InitWindow(&newGuiWindow)
|
2019-05-30 02:51:59 -05:00
|
|
|
})
|
|
|
|
time.Sleep(2000 * time.Millisecond)
|
|
|
|
} else {
|
|
|
|
log.Println("ShowWindow() WAITING for ui.Main()")
|
|
|
|
ui.Main(func() {
|
2019-05-30 10:52:28 -05:00
|
|
|
InitWindow(&newGuiWindow)
|
2019-05-30 02:51:59 -05:00
|
|
|
})
|
2019-05-29 23:07:19 -05:00
|
|
|
}
|
2019-05-29 21:57:15 -05:00
|
|
|
}
|
|
|
|
|
2019-05-30 02:51:59 -05:00
|
|
|
func getSplashText(a string) *ui.AttributedString {
|
2019-05-29 21:57:15 -05:00
|
|
|
var aText *ui.AttributedString
|
2019-05-30 02:51:59 -05:00
|
|
|
aText = ui.NewAttributedString(a)
|
2019-05-29 21:57:15 -05:00
|
|
|
return aText
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-30 10:52:28 -05:00
|
|
|
func InitWindow(wm *GuiWindow) {
|
2019-05-30 00:24:41 -05:00
|
|
|
log.Println("InitWindow() THIS WINDOW IS NOT YET SHOWN")
|
2019-05-29 21:57:15 -05:00
|
|
|
|
2019-05-30 02:51:59 -05:00
|
|
|
c := wm.C
|
|
|
|
wm.W = ui.NewWindow("", int(c.Width), int(c.Height), true)
|
|
|
|
wm.W.SetBorderless(false)
|
2019-05-29 21:57:15 -05:00
|
|
|
|
|
|
|
// create a 'fake' button entry for the mouse clicks
|
2019-05-30 10:55:54 -05:00
|
|
|
var newBM GuiButton
|
2019-05-29 21:57:15 -05:00
|
|
|
newBM.Action = "QUIT"
|
2019-05-30 02:51:59 -05:00
|
|
|
newBM.W = wm.W
|
|
|
|
newBM.WM = wm
|
2019-05-29 21:57:15 -05:00
|
|
|
Data.AllButtons = append(Data.AllButtons, newBM)
|
|
|
|
|
2019-05-30 02:51:59 -05:00
|
|
|
wm.W.OnClosing(func(*ui.Window) bool {
|
|
|
|
log.Println("InitWindow() OnClosing() THIS WINDOW IS CLOSING wm=", wm)
|
2019-05-30 00:24:41 -05:00
|
|
|
// mouseClick(&newBM)
|
2019-05-29 21:57:15 -05:00
|
|
|
ui.Quit()
|
|
|
|
return true
|
|
|
|
})
|
|
|
|
|
2019-05-30 02:51:59 -05:00
|
|
|
wm.T = ui.NewTab()
|
|
|
|
wm.W.SetChild(wm.T)
|
|
|
|
wm.W.SetMargined(true)
|
2019-05-29 21:57:15 -05:00
|
|
|
|
2019-05-30 02:51:59 -05:00
|
|
|
log.Println("InitWindow() wm =", wm)
|
|
|
|
log.Println("InitWindow() wm.Action =", wm.Action)
|
2019-05-29 21:57:15 -05:00
|
|
|
|
2019-05-30 02:51:59 -05:00
|
|
|
if (wm.Action == "SPLASH") {
|
2019-05-29 21:57:15 -05:00
|
|
|
log.Println("InitWindow() TRYING SPLASH")
|
2019-05-30 02:51:59 -05:00
|
|
|
damnit := "click" + string(c.Hostname)
|
|
|
|
tmp := getSplashText(damnit)
|
2019-05-29 21:57:15 -05:00
|
|
|
log.Println("InitWindow() TRYING SPLASH tmp =", tmp)
|
2019-05-30 02:51:59 -05:00
|
|
|
wm.Box1 = ShowSplashBox(wm, tmp)
|
2019-05-29 21:57:15 -05:00
|
|
|
|
2019-05-30 02:51:59 -05:00
|
|
|
wm.T.Append("WIT Splash", wm.Box1)
|
|
|
|
wm.T.SetMargined(0, true)
|
2019-05-29 21:57:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
Data.State = "splash"
|
2019-05-30 02:51:59 -05:00
|
|
|
wm.W.Show()
|
2019-05-29 21:57:15 -05:00
|
|
|
}
|
2019-05-24 23:07:40 -05:00
|
|
|
|
|
|
|
// makeEntryBox(box, "hostname:", "blah.foo.org") {
|
2019-05-30 10:52:28 -05:00
|
|
|
func makeEntryVbox(hbox *ui.Box, a string, startValue string, edit bool, action string) *GuiEntry {
|
2019-05-24 23:07:40 -05:00
|
|
|
// Start 'Nickname' vertical box
|
|
|
|
vboxN := ui.NewVerticalBox()
|
|
|
|
vboxN.SetPadded(true)
|
|
|
|
vboxN.Append(ui.NewLabel(a), false)
|
|
|
|
|
2019-05-27 19:23:19 -05:00
|
|
|
e := defaultMakeEntry(startValue, edit, action)
|
2019-05-24 23:07:40 -05:00
|
|
|
|
2019-05-27 19:23:19 -05:00
|
|
|
vboxN.Append(e.E, false)
|
2019-05-24 23:07:40 -05:00
|
|
|
hbox.Append(vboxN, false)
|
|
|
|
// End 'Nickname' vertical box
|
2019-05-27 23:29:30 -05:00
|
|
|
|
|
|
|
return e
|
2019-05-24 23:07:40 -05:00
|
|
|
}
|
|
|
|
|
2019-05-27 19:23:19 -05:00
|
|
|
/*
|
|
|
|
// string handling examples that might be helpful for normalizeInt()
|
|
|
|
isAlpha := regexp.MustCompile(`^[A-Za-z]+$`).MatchString
|
|
|
|
|
|
|
|
for _, username := range []string{"userone", "user2", "user-three"} {
|
|
|
|
if !isAlpha(username) {
|
|
|
|
fmt.Printf("%q is not valid\n", username)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const alpha = "abcdefghijklmnopqrstuvwxyz"
|
|
|
|
|
|
|
|
func alphaOnly(s string) bool {
|
|
|
|
for _, char := range s {
|
|
|
|
if !strings.Contains(alpha, strings.ToLower(string(char))) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
func normalizeInt(s string) string {
|
|
|
|
// reg, err := regexp.Compile("[^a-zA-Z0-9]+")
|
|
|
|
reg, err := regexp.Compile("[^0-9]+")
|
|
|
|
if err != nil {
|
|
|
|
log.Println("normalizeInt() regexp.Compile() ERROR =", err)
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
clean := reg.ReplaceAllString(s, "")
|
|
|
|
log.Println("normalizeInt() s =", clean)
|
|
|
|
return clean
|
|
|
|
}
|
|
|
|
|
2019-05-27 18:27:43 -05:00
|
|
|
func defaultEntryChange(e *ui.Entry) {
|
2019-05-27 23:29:30 -05:00
|
|
|
for key, em := range Data.AllEntries {
|
2019-05-27 18:27:43 -05:00
|
|
|
if (Data.Debug) {
|
2019-05-27 23:29:30 -05:00
|
|
|
log.Println("\tdefaultEntryChange() Data.AllEntries =", key, em)
|
2019-05-27 18:27:43 -05:00
|
|
|
}
|
|
|
|
if Data.AllEntries[key].E == e {
|
2019-05-27 19:23:19 -05:00
|
|
|
log.Println("defaultEntryChange() FOUND",
|
|
|
|
"action =", Data.AllEntries[key].Action,
|
|
|
|
"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)
|
|
|
|
}
|
2019-05-27 18:27:43 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
log.Println("defaultEntryChange() ERROR. MISSING ENTRY MAP. e.Text() =", e.Text())
|
|
|
|
}
|
|
|
|
|
2019-05-30 10:52:28 -05:00
|
|
|
func defaultMakeEntry(startValue string, edit bool, action string) *GuiEntry {
|
2019-05-27 18:27:43 -05:00
|
|
|
e := ui.NewEntry()
|
|
|
|
e.SetText(startValue)
|
|
|
|
if (edit == false) {
|
|
|
|
e.SetReadOnly(true)
|
|
|
|
}
|
|
|
|
e.OnChanged(defaultEntryChange)
|
|
|
|
|
|
|
|
// add the entry field to the global map
|
2019-05-30 10:52:28 -05:00
|
|
|
var newEntry GuiEntry
|
|
|
|
newEntry.E = e
|
|
|
|
newEntry.Edit = edit
|
|
|
|
newEntry.Action = action
|
2019-05-27 19:23:19 -05:00
|
|
|
if (action == "Memory") {
|
2019-05-30 10:52:28 -05:00
|
|
|
newEntry.Normalize = normalizeInt
|
2019-05-27 19:23:19 -05:00
|
|
|
}
|
2019-05-30 10:52:28 -05:00
|
|
|
Data.AllEntries = append(Data.AllEntries, &newEntry)
|
2019-05-27 18:27:43 -05:00
|
|
|
|
2019-05-30 10:52:28 -05:00
|
|
|
return &newEntry
|
2019-05-27 18:27:43 -05:00
|
|
|
}
|
|
|
|
|
2019-05-30 10:52:28 -05:00
|
|
|
func makeEntryHbox(hbox *ui.Box, a string, startValue string, edit bool, action string) *GuiEntry {
|
2019-05-24 23:07:40 -05:00
|
|
|
// Start 'Nickname' vertical box
|
|
|
|
hboxN := ui.NewHorizontalBox()
|
|
|
|
hboxN.SetPadded(true)
|
|
|
|
hboxN.Append(ui.NewLabel(a), false)
|
|
|
|
|
2019-05-27 19:23:19 -05:00
|
|
|
e := defaultMakeEntry(startValue, edit, action)
|
|
|
|
hboxN.Append(e.E, false)
|
2019-05-24 23:07:40 -05:00
|
|
|
|
|
|
|
hbox.Append(hboxN, false)
|
|
|
|
// End 'Nickname' vertical box
|
2019-05-27 19:23:19 -05:00
|
|
|
|
|
|
|
return e
|
2019-05-24 23:07:40 -05:00
|
|
|
}
|
|
|
|
|
2019-05-27 17:25:30 -05:00
|
|
|
func AddBoxToTab(name string, tab *ui.Tab, box *ui.Box) {
|
|
|
|
tab.Append(name, box)
|
|
|
|
tab.SetMargined(0, true)
|
|
|
|
}
|