2019-05-08 15:09:17 -05:00
|
|
|
package gui
|
2019-05-08 15:04:18 -05:00
|
|
|
|
|
|
|
import "log"
|
|
|
|
|
|
|
|
import "github.com/andlabs/ui"
|
|
|
|
import _ "github.com/andlabs/ui/winmanifest"
|
|
|
|
|
2019-05-24 21:29:08 -05:00
|
|
|
import pb "git.wit.com/wit/witProtobuf"
|
|
|
|
|
2019-05-21 16:39:46 -05:00
|
|
|
import "github.com/davecgh/go-spew/spew"
|
|
|
|
|
|
|
|
func InitColumns(mh *TableData, parts []TableColumnData) {
|
2019-05-12 14:54:11 -05:00
|
|
|
tmpBTindex := 0
|
2019-05-13 02:30:38 -05:00
|
|
|
humanID := 0
|
2019-05-12 14:54:11 -05:00
|
|
|
for key, foo := range parts {
|
2019-05-13 02:30:38 -05:00
|
|
|
log.Println("key, foo =", key, foo)
|
2019-05-13 02:08:59 -05:00
|
|
|
|
|
|
|
parts[key].Index = humanID
|
|
|
|
humanID += 1
|
|
|
|
|
|
|
|
if (foo.CellType == "BG") {
|
2019-05-13 02:46:11 -05:00
|
|
|
mh.generatedColumnTypes = append(mh.generatedColumnTypes, ui.TableColor{})
|
2019-05-13 02:08:59 -05:00
|
|
|
initRowBTcolor (mh, tmpBTindex, parts[key])
|
|
|
|
tmpBTindex += 1
|
|
|
|
} else if (foo.CellType == "BUTTON") {
|
2019-05-13 02:46:11 -05:00
|
|
|
mh.generatedColumnTypes = append(mh.generatedColumnTypes, ui.TableString(""))
|
2019-05-13 02:08:59 -05:00
|
|
|
initRowButtonColumn (mh, tmpBTindex, parts[key].Heading, parts[key])
|
|
|
|
tmpBTindex += 1
|
|
|
|
} else if (foo.CellType == "TEXTCOLOR") {
|
2019-05-13 02:46:11 -05:00
|
|
|
mh.generatedColumnTypes = append(mh.generatedColumnTypes, ui.TableString(""))
|
|
|
|
mh.generatedColumnTypes = append(mh.generatedColumnTypes, ui.TableColor{})
|
2019-05-13 02:08:59 -05:00
|
|
|
initRowTextColorColumn(mh, tmpBTindex, tmpBTindex + 1, parts[key].Heading, ui.TableColor{0.0, 0, 0.9, 1}, parts[key])
|
|
|
|
tmpBTindex += 2
|
|
|
|
} else if (foo.CellType == "TEXT") {
|
2019-05-13 02:46:11 -05:00
|
|
|
mh.generatedColumnTypes = append(mh.generatedColumnTypes, ui.TableString(""))
|
2019-05-13 02:08:59 -05:00
|
|
|
initRowTextColumn (mh, tmpBTindex, parts[key].Heading, parts[key])
|
|
|
|
tmpBTindex += 1
|
|
|
|
} else {
|
|
|
|
panic("I don't know what this is in initColumnNames")
|
|
|
|
}
|
2019-05-12 14:54:11 -05:00
|
|
|
}
|
2019-05-13 02:46:11 -05:00
|
|
|
}
|
|
|
|
|
2019-05-24 22:54:09 -05:00
|
|
|
func AddTableTab(mytab *ui.Tab, mytabcount int, name string, rowcount int, parts []TableColumnData, account *pb.Config_Account) *TableData {
|
2019-05-13 02:46:11 -05:00
|
|
|
mh := new(TableData)
|
|
|
|
|
|
|
|
mh.RowCount = rowcount
|
|
|
|
mh.Rows = make([]RowData, mh.RowCount)
|
|
|
|
|
|
|
|
InitColumns(mh, parts)
|
2019-05-12 14:54:11 -05:00
|
|
|
|
|
|
|
model := ui.NewTableModel(mh)
|
|
|
|
table := ui.NewTable(
|
|
|
|
&ui.TableParams{
|
|
|
|
Model: model,
|
2019-05-13 02:46:11 -05:00
|
|
|
RowBackgroundColorModelColumn: 0, // Row Background color is always index zero
|
2019-05-12 14:54:11 -05:00
|
|
|
})
|
|
|
|
|
2019-05-13 02:46:11 -05:00
|
|
|
tmpBTindex := 0
|
2019-05-12 14:54:11 -05:00
|
|
|
for key, foo := range parts {
|
|
|
|
log.Println(key, foo)
|
|
|
|
if (foo.CellType == "BG") {
|
|
|
|
} else if (foo.CellType == "BUTTON") {
|
|
|
|
tmpBTindex += 1
|
|
|
|
table.AppendButtonColumn(foo.Heading, tmpBTindex, ui.TableModelColumnAlwaysEditable)
|
|
|
|
} else if (foo.CellType == "TEXTCOLOR") {
|
|
|
|
tmpBTindex += 1
|
2019-05-13 01:37:27 -05:00
|
|
|
table.AppendTextColumn(foo.Heading, tmpBTindex, ui.TableModelColumnAlwaysEditable,
|
|
|
|
&ui.TableTextColumnOptionalParams{
|
|
|
|
ColorModelColumn: tmpBTindex + 1,
|
|
|
|
});
|
2019-05-12 14:54:11 -05:00
|
|
|
tmpBTindex += 1
|
|
|
|
} else if (foo.CellType == "TEXT") {
|
|
|
|
tmpBTindex += 1
|
2019-05-13 01:37:27 -05:00
|
|
|
table.AppendTextColumn(foo.Heading, tmpBTindex, ui.TableModelColumnAlwaysEditable, nil)
|
2019-05-12 14:54:11 -05:00
|
|
|
} else {
|
|
|
|
panic("I don't know what this is in initColumnNames")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-21 16:39:46 -05:00
|
|
|
vbox := ui.NewVerticalBox()
|
|
|
|
vbox.SetPadded(true)
|
|
|
|
|
|
|
|
vbox.Append(table, true)
|
|
|
|
mytab.Append(name, vbox)
|
2019-05-12 14:54:11 -05:00
|
|
|
mytab.SetMargined(mytabcount, true)
|
2019-05-12 17:11:32 -05:00
|
|
|
|
2019-05-21 16:39:46 -05:00
|
|
|
vbox.Append(ui.NewVerticalSeparator(), false)
|
|
|
|
|
|
|
|
hbox := ui.NewHorizontalBox()
|
|
|
|
hbox.SetPadded(true)
|
|
|
|
|
2019-05-24 22:54:09 -05:00
|
|
|
hbox.Append(CreateButton(account, nil, "Add Virtual Machine", "createAddVmBox", mouseClick), false)
|
|
|
|
hbox.Append(CreateButton(account, nil, "Close", "CLOSE", mouseClick), false)
|
2019-05-21 16:39:46 -05:00
|
|
|
|
|
|
|
vbox.Append(hbox, false)
|
|
|
|
|
2019-05-12 17:11:32 -05:00
|
|
|
return mh
|
2019-05-12 14:54:11 -05:00
|
|
|
}
|
|
|
|
|
2019-05-24 18:19:22 -05:00
|
|
|
func SocketError() {
|
|
|
|
ui.MsgBoxError(Data.cloudWindow,
|
|
|
|
"There was a socket error",
|
|
|
|
"More detailed information can be shown here.")
|
|
|
|
}
|
|
|
|
|
|
|
|
func MessageWindow(msg1 string, msg2 string) {
|
|
|
|
ui.MsgBox(Data.cloudWindow, msg1, msg2)
|
|
|
|
}
|
|
|
|
|
|
|
|
func ErrorWindow(msg1 string, msg2 string) {
|
|
|
|
ui.MsgBoxError(Data.cloudWindow, msg1, msg2)
|
|
|
|
}
|
|
|
|
|
2019-05-24 11:02:35 -05:00
|
|
|
// This is the default mouse click handler
|
|
|
|
// Every mouse click that hasn't been assigned to
|
|
|
|
// 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
|
|
|
|
|
2019-05-24 15:23:50 -05:00
|
|
|
// 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
|
|
|
|
func mouseClick(b *ButtonMap) {
|
|
|
|
log.Println("gui.mouseClick() START b =", b)
|
|
|
|
|
2019-05-24 18:19:22 -05:00
|
|
|
if (b != nil) {
|
2019-05-24 21:45:03 -05:00
|
|
|
if (b.Action == "createAddVmBox") {
|
|
|
|
log.Println("gui.mouseClick() createAddVmBox for b =", b)
|
2019-05-24 18:19:22 -05:00
|
|
|
createAddVmBox(Data.cloudTab, "Create New Virtual Machine", mouseClick)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-24 15:23:50 -05:00
|
|
|
if (Data.MouseClick == nil) {
|
|
|
|
log.Println("Data.MouseClick() IS nil. NOT DOING ANYTHING")
|
|
|
|
} else {
|
2019-05-24 11:02:35 -05:00
|
|
|
log.Println("\tData.MouseClick() START")
|
|
|
|
Data.MouseClick(b)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-24 15:23:50 -05:00
|
|
|
/*
|
|
|
|
func buttonMapClick(b *ButtonMap) {
|
2019-05-24 14:51:04 -05:00
|
|
|
log.Println("gui.buttonVmClick() START")
|
2019-05-24 15:23:50 -05:00
|
|
|
if (Data.MouseClick == nil) {
|
|
|
|
log.Println("Data.MouseClick() IS nil. NOT DOING ANYTHING")
|
|
|
|
} else {
|
|
|
|
log.Println("Data.MouseClick() START")
|
|
|
|
Data.MouseClick(b)
|
2019-05-24 14:51:04 -05:00
|
|
|
}
|
|
|
|
}
|
2019-05-24 15:23:50 -05:00
|
|
|
*/
|
2019-05-24 14:51:04 -05:00
|
|
|
|
|
|
|
// This is the raw routine passed to every button in andlabs libui / ui
|
2019-05-22 12:39:56 -05:00
|
|
|
func defaultButtonClick(button *ui.Button) {
|
|
|
|
log.Println("defaultButtonClick() button =", button)
|
2019-05-24 11:02:35 -05:00
|
|
|
for key, foo := range Data.AllButtons {
|
|
|
|
log.Println("Data.AllButtons =", key, foo)
|
|
|
|
if Data.AllButtons[key].B == button {
|
2019-05-22 12:39:56 -05:00
|
|
|
log.Println("\tBUTTON MATCHED")
|
2019-05-24 21:45:03 -05:00
|
|
|
// log.Println("\tData.AllButtons[key].Name =", Data.AllButtons[key].Name)
|
|
|
|
log.Println("\tData.AllButtons[key].Action =", Data.AllButtons[key].Action)
|
2019-05-24 11:02:35 -05:00
|
|
|
if Data.AllButtons[key].custom != nil {
|
|
|
|
log.Println("\tDOING CUSTOM FUNCTION")
|
2019-05-24 15:23:50 -05:00
|
|
|
var tmp ButtonMap
|
|
|
|
tmp = Data.AllButtons[key]
|
|
|
|
spew.Dump(tmp)
|
|
|
|
Data.AllButtons[key].custom(&tmp)
|
2019-05-24 11:02:35 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
if (Data.MouseClick != nil) {
|
2019-05-24 14:51:04 -05:00
|
|
|
Data.MouseClick(&Data.AllButtons[key])
|
2019-05-22 12:39:56 -05:00
|
|
|
}
|
2019-05-23 19:44:00 -05:00
|
|
|
return
|
2019-05-22 12:39:56 -05:00
|
|
|
}
|
|
|
|
}
|
2019-05-23 19:44:00 -05:00
|
|
|
log.Println("\tBUTTON NOT FOUND")
|
2019-05-24 11:02:35 -05:00
|
|
|
// still run the mouse click handler
|
|
|
|
if (Data.MouseClick != nil) {
|
|
|
|
Data.MouseClick(nil)
|
|
|
|
}
|
2019-05-22 12:39:56 -05:00
|
|
|
}
|
|
|
|
|
2019-05-24 14:51:04 -05:00
|
|
|
// 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
|
2019-05-22 12:39:56 -05:00
|
|
|
func defaultFontButtonClick(button *ui.FontButton) {
|
2019-05-24 18:19:22 -05:00
|
|
|
log.Println("defaultFontButtonClick() button =", button)
|
2019-05-24 11:02:35 -05:00
|
|
|
for key, foo := range Data.AllButtons {
|
|
|
|
log.Println("Data.AllButtons =", key, foo)
|
2019-05-22 12:39:56 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-24 22:54:09 -05:00
|
|
|
func CreateButton(a *pb.Config_Account, vm *pb.Event_VM,
|
|
|
|
name string, note string, custom func(*ButtonMap)) *ui.Button {
|
2019-05-22 13:27:58 -05:00
|
|
|
newB := ui.NewButton(name)
|
2019-05-22 12:39:56 -05:00
|
|
|
newB.OnClicked(defaultButtonClick)
|
|
|
|
|
|
|
|
var newmap ButtonMap
|
|
|
|
newmap.B = newB
|
2019-05-24 22:54:09 -05:00
|
|
|
newmap.Account = a
|
2019-05-24 21:45:03 -05:00
|
|
|
newmap.Action = note
|
2019-05-24 02:04:14 -05:00
|
|
|
newmap.custom = custom
|
2019-05-24 11:02:35 -05:00
|
|
|
Data.AllButtons = append(Data.AllButtons, newmap)
|
2019-05-24 02:04:14 -05:00
|
|
|
|
|
|
|
return newB
|
|
|
|
}
|
|
|
|
|
2019-05-24 15:23:50 -05:00
|
|
|
func CreateFontButton(name string, note string, custom func(*ButtonMap)) *ui.FontButton {
|
2019-05-22 12:39:56 -05:00
|
|
|
newB := ui.NewFontButton()
|
|
|
|
|
|
|
|
newB.OnChanged(defaultFontButtonClick)
|
|
|
|
|
|
|
|
var newmap ButtonMap
|
|
|
|
newmap.FB = newB
|
2019-05-24 21:45:03 -05:00
|
|
|
newmap.Action = note
|
2019-05-22 12:39:56 -05:00
|
|
|
newmap.custom = custom
|
2019-05-24 11:02:35 -05:00
|
|
|
Data.AllButtons = append(Data.AllButtons, newmap)
|
2019-05-22 12:39:56 -05:00
|
|
|
|
|
|
|
return newB
|
|
|
|
}
|