From 238c39de36931ad81427d964228cd5bc0c3ea60a Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Fri, 24 May 2019 12:51:04 -0700 Subject: [PATCH] clean more of the button handling Signed-off-by: Jeff Carr --- gui.go | 22 ++++++++++++++-- structs.go | 1 + tableCallbacks.go | 4 ++- vmWindow.go | 67 ++++++++++++++++++++++++++++++++++++++++------- 4 files changed, 82 insertions(+), 12 deletions(-) diff --git a/gui.go b/gui.go index 254458c..a583305 100644 --- a/gui.go +++ b/gui.go @@ -114,6 +114,18 @@ func mouseClick(b *ButtonMap, s string) { } } +// This is one of the routines that is called from the +// defaultButtonClick() below when the button is found +// in the AllButtons %map +func buttonMapClick(b *ButtonMap, s string) { + log.Println("gui.buttonVmClick() START") + if (Data.MouseClick != nil) { + log.Println("Data.ButtonClick() START") + Data.MouseClick(nil) + } +} + +// This is the raw routine passed to every button in andlabs libui / ui func defaultButtonClick(button *ui.Button) { log.Println("defaultButtonClick() button =", button) for key, foo := range Data.AllButtons { @@ -128,7 +140,7 @@ func defaultButtonClick(button *ui.Button) { return } if (Data.MouseClick != nil) { - Data.MouseClick( &Data.AllButtons[key]) + Data.MouseClick(&Data.AllButtons[key]) } return } @@ -140,6 +152,9 @@ func defaultButtonClick(button *ui.Button) { } } +// This is the raw routine passed to every button in andlabs libui / ui +// (this has to be different for FontButtons) +// TODO; merge the logic with the function above func defaultFontButtonClick(button *ui.FontButton) { log.Println("defaultButtonClick() button =", button) for key, foo := range Data.AllButtons { @@ -224,7 +239,10 @@ func closeButton(name string, mytab *ui.Tab) ui.Control { func addVmButtonClick(button *ui.Button) { log.Println("addVMButtonClick()") - spew.Dump(button) + if (Data.Debug) { + spew.Dump(button) + } + createAddVmBox(Data.cloudTab, "Create New Virtual Machine", buttonMapClick) } func addVmButton(name string) ui.Control { diff --git a/structs.go b/structs.go index a080e34..bbbbfaf 100644 --- a/structs.go +++ b/structs.go @@ -176,6 +176,7 @@ type TableData struct { lastRow int lastColumn int + parentTab *ui.Tab } // diff --git a/tableCallbacks.go b/tableCallbacks.go index 6c5fdae..67e414b 100644 --- a/tableCallbacks.go +++ b/tableCallbacks.go @@ -106,7 +106,9 @@ func defaultSetCellValue(mh *TableData, row int, column int) { if (Data.Debug) { go ui.Main(ShowVM) } else { - AddVmConfigureTab(vmname, mh.Rows[row].PbVM) + // AddVmConfigureTab(vmname, mh.Rows[row].PbVM) + // createVmBox(Data.cloudTab, buttonVmClick, mh.Rows[row].PbVM) + createVmBox(Data.cloudTab, buttonMapClick, mh.Rows[row].PbVM) } } } diff --git a/vmWindow.go b/vmWindow.go index 75b703a..1864670 100644 --- a/vmWindow.go +++ b/vmWindow.go @@ -27,7 +27,7 @@ func ShowVM() { VMwin.SetChild(VMtab) VMwin.SetMargined(true) - createVmBox(VMtab, buttonVmClick, Data.CurrentPbVM) + createVmBox(VMtab, buttonMapClick, Data.CurrentPbVM) // vmBox := createVmBox(buttonVmClick) // VMtab.Append(Data.CurrentVM, vmBox) // VMtab.SetMargined(0, true) @@ -36,14 +36,14 @@ func ShowVM() { } func AddVmConfigureTab(name string, pbVM *pb.Event_VM) { - createVmBox(Data.cloudTab, buttonVmClick, Data.CurrentPbVM) + createVmBox(Data.cloudTab, buttonMapClick, Data.CurrentPbVM) // vmBox := createVmBox(Data.cloudTab, buttonVmClick) // Data.cloudTab.Append(name, vmBox) // Data.cloudTab.SetMargined(0, true) } // makeEntryBox(box, "hostname:", "blah.foo.org") { -func makeEntryBox(hbox *ui.Box, a string, b string, edit bool) { +func makeEntryVbox(hbox *ui.Box, a string, b string, edit bool) { // Start 'Nickname' vertical box vboxN := ui.NewVerticalBox() vboxN.SetPadded(true) @@ -65,6 +65,28 @@ func makeEntryBox(hbox *ui.Box, a string, b string, edit bool) { // End 'Nickname' vertical box } +func makeEntryHbox(hbox *ui.Box, a string, b string, edit bool) { + // Start 'Nickname' vertical box + hboxN := ui.NewHorizontalBox() + hboxN.SetPadded(true) + hboxN.Append(ui.NewLabel(a), false) + + entryNick := ui.NewEntry() + entryNick.SetText(b) + if (edit == false) { + entryNick.SetReadOnly(true) + } + + hboxN.Append(entryNick, false) + + entryNick.OnChanged(func(*ui.Entry) { + log.Println("OK. TEXT WAS CHANGED TO =", entryNick.Text()) + // Data.AccNick = entryNick.Text() + }) + hbox.Append(hboxN, false) + // End 'Nickname' vertical box +} + func createVmBox(tab *ui.Tab, custom func(b *ButtonMap,s string), pbVM *pb.Event_VM) { log.Println("createVmBox() START") log.Println("createVmBox() pbVM.Name", pbVM.Name) @@ -80,12 +102,12 @@ func createVmBox(tab *ui.Tab, custom func(b *ButtonMap,s string), pbVM *pb.Event vbox.Append(hboxAccount, false) // Add hostname entry box - makeEntryBox(hboxAccount, "hostname:", pbVM.Hostname, true) - makeEntryBox(hboxAccount, "IPv6:", pbVM.IPv6, true) - makeEntryBox(hboxAccount, "RAM:", fmt.Sprintf("%d",pbVM.Memory), true) - makeEntryBox(hboxAccount, "CPU:", fmt.Sprintf("%d",pbVM.Cpus), true) - makeEntryBox(hboxAccount, "Disk (GB):", fmt.Sprintf("%d",pbVM.Disk), true) - makeEntryBox(hboxAccount, "OS Image:", pbVM.BaseImage, true) + makeEntryVbox(hboxAccount, "hostname:", pbVM.Hostname, true) + makeEntryVbox(hboxAccount, "IPv6:", pbVM.IPv6, true) + makeEntryVbox(hboxAccount, "RAM:", fmt.Sprintf("%d",pbVM.Memory), true) + makeEntryVbox(hboxAccount, "CPU:", fmt.Sprintf("%d",pbVM.Cpus), true) + makeEntryVbox(hboxAccount, "Disk (GB):", fmt.Sprintf("%d",pbVM.Disk), true) + makeEntryVbox(hboxAccount, "OS Image:", pbVM.BaseImage, true) vbox.Append(ui.NewHorizontalSeparator(), false) @@ -104,6 +126,32 @@ func createVmBox(tab *ui.Tab, custom func(b *ButtonMap,s string), pbVM *pb.Event tab.SetMargined(0, true) } +func createAddVmBox(tab *ui.Tab, name string, custom func(b *ButtonMap,s string)) { + log.Println("createAddVmBox() START") + vbox := ui.NewVerticalBox() + vbox.SetPadded(true) + + hboxAccount := ui.NewHorizontalBox() + hboxAccount.SetPadded(true) + vbox.Append(hboxAccount, false) + + // Add hostname entry box + makeEntryHbox(hboxAccount, "hostname:", "", true) + + vbox.Append(ui.NewHorizontalSeparator(), false) + + hboxButtons := ui.NewHorizontalBox() + hboxButtons.SetPadded(true) + vbox.Append(hboxButtons, false) + + hboxButtons.Append(CreateButton("Add Virtual Machine", "CREATE", custom), false) + hboxButtons.Append(CreateButton("Cancel", "DONE", custom), false) + + tab.Append(name, vbox) + tab.SetMargined(0, true) +} + +/* func buttonVmClick(b *ButtonMap, s string) { log.Println("gui.buttonVmClick() START") if (Data.MouseClick != nil) { @@ -111,3 +159,4 @@ func buttonVmClick(b *ButtonMap, s string) { Data.MouseClick(nil) } } +*/