From 44c64228ce49d6d14782de902301f58205ba253c Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Tue, 7 May 2019 18:33:23 -0700 Subject: [PATCH] All demo table code is now seperate Signed-off-by: Jeff Carr --- table.go | 61 +++++++++++------------------------------------ tableCallbacks.go | 15 ++++++++++++ tableDemo.go | 35 +++++++++++++++++++++++++-- 3 files changed, 62 insertions(+), 49 deletions(-) diff --git a/table.go b/table.go index 56b3156..686785d 100644 --- a/table.go +++ b/table.go @@ -27,22 +27,7 @@ type modelHandler struct { columnTypes string funcColumnTypes func() []ui.TableValue scanCellValue func(*modelHandler, int, int) ui.TableValue - setCellValue func(*modelHandler, int, int) ui.TableValue -} - -func newDemoModelHandler() *modelHandler { - mh := new(modelHandler) - mh.rows = 20 - mh.funcColumnTypes = demoColumnTypes - mh.scanCellValue = demoCellValue - mh.checkStates = make([]int, mh.rows) - mh.vms = make([]vmRowData, mh.rows) - mh.vms[8].hostname = "fire" - mh.vms[9].hostname = "librem15.this.is.a.really.long.string.test" - mh.yellowRow = -1 - log.Println("Called newDemoModelhandler() with mh=", mh) - spew.Dump(mh) - return mh + setCellValue func(*modelHandler, *ui.TableModel, int, int, ui.TableValue) } func standardColumnTypes() []ui.TableValue { @@ -67,45 +52,27 @@ func defaultCellValue(mh *modelHandler, row, column int) ui.TableValue { return ui.TableString(fmt.Sprintf("jcarrbad %d", row)) } -func (mh *modelHandler) SetCellValue(m *ui.TableModel, row, column int, value ui.TableValue) { - log.Println("SetCallValue() START") - spew.Dump(m) - spew.Dump(mh) - if (mh.columnTypes == "standard") { - if column == 3 { // button row (?) - log.Println("Button was pressed START", row, column) - } - return +func defaultSetCellValue(mh *modelHandler, m *ui.TableModel, row, column int, value ui.TableValue) { + if column == 3 { // button row (?) + log.Println("Button was pressed START", row, column) } - if column == 2 { - mh.vms[row].hostname = string(value.(ui.TableString)) - } - if column == 6 { // row background color - prevYellowRow := mh.yellowRow - mh.yellowRow = row - if prevYellowRow != -1 { - m.RowChanged(prevYellowRow) - } - m.RowChanged(mh.yellowRow) - } - if column == 7 { // checkboxes - mh.checkStates[row] = int(value.(ui.TableInt)) - } - log.Println("SetCallValue() END") - spew.Dump(m) + return } func newModelHandler(rows int) *modelHandler { mh := new(modelHandler) - mh.rows = rows - mh.columnTypes = "standard" + + mh.rows = rows + mh.columnTypes = "standard" mh.funcColumnTypes = standardColumnTypes mh.scanCellValue = defaultCellValue - mh.bgcolorColumn = 0 - mh.checkStates = make([]int, mh.rows) - mh.vms = make([]vmRowData, mh.rows) + mh.setCellValue = defaultSetCellValue + mh.bgcolorColumn = 0 + mh.checkStates = make([]int, mh.rows) + mh.vms = make([]vmRowData, mh.rows) mh.vms[1].hostname = "jcarr" - mh.yellowRow = -1 + mh.yellowRow = -1 + log.Println("Called newModelhandler() with mh=", mh) spew.Dump(mh) return mh diff --git a/tableCallbacks.go b/tableCallbacks.go index 511701d..194b9d9 100644 --- a/tableCallbacks.go +++ b/tableCallbacks.go @@ -6,6 +6,8 @@ import "log" import "github.com/andlabs/ui" import _ "github.com/andlabs/ui/winmanifest" +import "github.com/davecgh/go-spew/spew" + func (mh *modelHandler) NumRows(m *ui.TableModel) int { // log.Println("NumRows() with m=", m) return mh.rows @@ -28,3 +30,16 @@ func (mh *modelHandler) CellValue(m *ui.TableModel, row, column int) ui.TableVal } return mh.scanCellValue(mh, row, column) } + +func (mh *modelHandler) SetCellValue(m *ui.TableModel, row, column int, value ui.TableValue) { + log.Println("SetCallValue() START") + spew.Dump(m) + spew.Dump(mh) + if (mh.columnTypes == "standard") { + defaultSetCellValue(mh, m, row, column, value) + return + } + demoSetCellValue(mh, m, row, column, value) + log.Println("SetCallValue() END") + spew.Dump(m) +} diff --git a/tableDemo.go b/tableDemo.go index f5bb210..48bbd09 100644 --- a/tableDemo.go +++ b/tableDemo.go @@ -3,14 +3,28 @@ package main import "fmt" -/* import "log" import "github.com/davecgh/go-spew/spew" -*/ import "github.com/andlabs/ui" import _ "github.com/andlabs/ui/winmanifest" +func newDemoModelHandler() *modelHandler { + mh := new(modelHandler) + mh.rows = 20 + mh.funcColumnTypes = demoColumnTypes + mh.scanCellValue = demoCellValue + mh.setCellValue = demoSetCellValue + mh.checkStates = make([]int, mh.rows) + mh.vms = make([]vmRowData, mh.rows) + mh.vms[8].hostname = "fire" + mh.vms[9].hostname = "librem15.this.is.a.really.long.string.test" + mh.yellowRow = -1 + log.Println("Called newDemoModelhandler() with mh=", mh) + spew.Dump(mh) + return mh +} + func demoColumnTypes() []ui.TableValue { return []ui.TableValue{ ui.TableString(""), // column 0 text @@ -105,3 +119,20 @@ func makeDemotable(name string) *ui.Table { return table } + +func demoSetCellValue(mh *modelHandler, m *ui.TableModel, row, column int, value ui.TableValue) { + if column == 2 { + mh.vms[row].hostname = string(value.(ui.TableString)) + } + if column == 6 { // row background color + prevYellowRow := mh.yellowRow + mh.yellowRow = row + if prevYellowRow != -1 { + m.RowChanged(prevYellowRow) + } + m.RowChanged(mh.yellowRow) + } + if column == 7 { // checkboxes + mh.checkStates[row] = int(value.(ui.TableInt)) + } +}