diff --git a/area.go b/area.go index 3582900..42ea850 100644 --- a/area.go +++ b/area.go @@ -75,7 +75,9 @@ func (ah GuiArea) MouseEvent(a *ui.Area, me *ui.AreaMouseEvent) { log.Println("GOT MOUSE UP") log.Println("GOT MOUSE UP ah.Button =", ah.Button) log.Println("GOT MOUSE UP ah.Button.FB =", ah.Button.FB) - mouseClick(ah.Button) + if (Data.MouseClick != nil) { + Data.MouseClick(ah.Button) + } } } diff --git a/gui.go b/gui.go index 7090a5f..0906e58 100644 --- a/gui.go +++ b/gui.go @@ -10,7 +10,7 @@ import pb "git.wit.com/wit/witProtobuf" import "github.com/davecgh/go-spew/spew" -// THIS IS CLEAN (all that is left is the 'createAddVmBox') +// THIS IS CLEAN (all that is left is the 'ADD VM') func InitColumns(mh *TableData, parts []TableColumnData) { tmpBTindex := 0 @@ -96,16 +96,12 @@ func AddTableTab(gw *GuiWindow, name string, rowcount int, parts []TableColumnDa vbox.Append(table, true) gw.UiTab.Append(name, vbox) - // mytab.SetMargined(mytabcount, true) vbox.Append(ui.NewVerticalSeparator(), false) hbox := ui.NewHorizontalBox() hbox.SetPadded(true) -// a := CreateButton(gb, account, nil, "Add Virtual Machine", "createAddVmBox", nil) -// hbox.Append(a.B, false) - vbox.Append(hbox, false) return mh @@ -124,47 +120,6 @@ func ErrorWindow(gw *GuiWindow, msg1 string, msg2 string) { // something specific will fall into this routine // By default, all it runs is the call back to // the main program that is using this library - -// This is one of the routines that is called from the -// defaultButtonClick() below when the button is found -// in the AllButtons %map -// TODO: clean up the text above -// TODO: remove this all together going only to main() -func mouseClick(b *GuiButton) { - log.Println("gui.mouseClick() START") - if (b == nil) { - log.Println("\tgui.mouseClick() START b = nil") - } else { - log.Println("\tgui.mouseClick() START b.Action =", b.Action) - /* - if (b.Action == "CreateAddVmBox") { - log.Println("\tgui.mouseClick() CreateAddVmBox for b =", b) - CreateAddVmBox(b.GW, b) - return - } - */ - /* - if (b.Action == "WINDOW CLOSE") { - b.W.Hide() - // TODO: fix this (seems to crash? maybe because we are in the button here?) - // b.W.Destroy() - return - } - if (b.Action == "ADD") { - log.Println("\tgui.mouseClick() SHOULD ADD VM HERE?") - } - */ - } - - if (Data.MouseClick == nil) { - log.Println("\tgui.mouseClick() Data.MouseClick() IS nil. NOT DOING ANYTHING") - log.Println("\tgui.mouseClick() Your application did not set a MouseClick() callback function") - } else { - log.Println("\tgui.mouseClick() Data.MouseClick() START") - Data.MouseClick(b) - } -} - // // This routine MUST be here as this is how the andlabs/ui works // This is the raw routine passed to every button in andlabs libui / ui @@ -177,21 +132,21 @@ func defaultButtonClick(button *ui.Button) { for key, foo := range Data.AllButtons { if (Data.Debug) { log.Println("defaultButtonClick() Data.AllButtons =", key, foo) - spew.Dump(foo) + // spew.Dump(foo) } if Data.AllButtons[key].B == button { log.Println("\tdefaultButtonClick() BUTTON MATCHED") - // log.Println("\tData.AllButtons[key].Name =", Data.AllButtons[key].Name) log.Println("\tdefaultButtonClick() Data.AllButtons[key].Action =", Data.AllButtons[key].Action) if Data.AllButtons[key].custom != nil { log.Println("\tdefaultButtonClick() DOING CUSTOM FUNCTION") - var tmp *GuiButton - tmp = Data.AllButtons[key] - // spew.Dump(tmp) - Data.AllButtons[key].custom(tmp) + Data.AllButtons[key].custom(Data.AllButtons[key]) return } - mouseClick(Data.AllButtons[key]) + if (Data.MouseClick != nil) { + Data.MouseClick(Data.AllButtons[key]) + } else { + log.Println("\tdefaultButtonClick() IGNORING BUTTON. MouseClick() is nil") + } return } } @@ -199,7 +154,6 @@ func defaultButtonClick(button *ui.Button) { if (Data.Debug) { panic("defaultButtonClick() SHOULD NOT HAVE UNMAPPED BUTTONS") } - mouseClick(nil) } func AddButton(b *GuiButton, name string) *ui.Button { @@ -249,7 +203,9 @@ func CreateFontButton(box *GuiBox, action string) *GuiButton { newGB.FB.OnChanged(func (*ui.FontButton) { log.Println("FontButton.OnChanged() START mouseClick(&newBM)", newGB) - mouseClick(&newGB) + if (Data.MouseClick != nil) { + Data.MouseClick(&newGB) + } }) return &newGB } @@ -345,6 +301,11 @@ func AddEntry(box *GuiBox, name string) *GuiEntry { return ge } +func HorizontalBreak(box *GuiBox) { + tmp := ui.NewHorizontalSeparator() + box.UiBox.Append(tmp, false) +} + func AddGenericBox(gw *GuiWindow) *GuiBox { var gb *GuiBox gb = new(GuiBox) @@ -365,7 +326,23 @@ func AddGenericBox(gw *GuiWindow) *GuiBox { return gb } -func HorizontalBreak(box *GuiBox) { - tmp := ui.NewHorizontalSeparator() - box.UiBox.Append(tmp, false) +func CreateGenericBox(gw *GuiWindow, b *GuiButton, name string) *GuiBox{ + log.Println("CreateAddVmBox() START name =", name) + + var box *GuiBox + box = new(GuiBox) + + vbox := ui.NewVerticalBox() + vbox.SetPadded(true) + box.UiBox = vbox + box.W = gw + gw.BoxMap["ADD VM" + name] = box + + hbox := ui.NewHorizontalBox() + hbox.SetPadded(true) + vbox.Append(hbox, false) + + AddBoxToTab(name, gw.UiTab, vbox) + + return box } diff --git a/tableCallbacks.go b/tableCallbacks.go index df9c408..f71cabc 100644 --- a/tableCallbacks.go +++ b/tableCallbacks.go @@ -110,7 +110,9 @@ func defaultSetCellValue(mh *TableData, row int, column int) { button := mh.Rows[row].HumanData[humanID].Button if (button != nil) { - mouseClick(button) + if (Data.MouseClick != nil) { + Data.MouseClick(button) + } return } if (Data.Debug) { diff --git a/vmBox.go b/vmBox.go index 55f78d3..bc51f52 100644 --- a/vmBox.go +++ b/vmBox.go @@ -71,53 +71,3 @@ func CreateVmBox(gw *GuiWindow, vm *pb.Event_VM) { AddBoxToTab(vm.Name, gw.UiTab, vbox) } - -func CreateAddVmBox(gw *GuiWindow, b *GuiButton, name string) *GuiBox{ - log.Println("CreateAddVmBox() START name =", name) - - var box *GuiBox - box = new(GuiBox) - - vbox := ui.NewVerticalBox() - vbox.SetPadded(true) - box.UiBox = vbox - box.W = gw - gw.BoxMap["ADD VM" + name] = box - - hbox := ui.NewHorizontalBox() - hbox.SetPadded(true) - vbox.Append(hbox, false) - - // abox := gw.MakeTab(gw) - - AddBoxToTab(name, gw.UiTab, vbox) - - return box - - /* - // Add hostname entry box - hostname := MakeEntryHbox(box, "Hostname:", "testhost", true, "Hostname") - memory := MakeEntryHbox(box, "Memory:", "512", true, "Memory") - disk := MakeEntryHbox(box, "Disk:", "20", true, "Disk") - - log.Println("CreateAddVmBox() hostname, memory, disk =", hostname, memory, disk) - - vbox.Append(ui.NewHorizontalSeparator(), false) - - hboxButtons := ui.NewHorizontalBox() - hboxButtons.SetPadded(true) - vbox.Append(hboxButtons, false) - - var newb GuiButton - newb.Action = "CREATE" - newb.VM = b.VM - newb.Account = b.Account - hostname.B = &newb - memory.B = &newb - disk.B = &newb - hboxButtons.Append(AddButton(&newb, "Add Virtual Machine"), false) - - a := CreateButton(box, nil, nil, "Cancel", "CLOSE", nil) - hboxButtons.Append(a.B, false) - */ -}