gui: prep work for inserting rows

This commit is contained in:
mappu 2024-07-05 20:07:19 +12:00
parent 2b59efc410
commit 0d3b90b879

42
main.go
View File

@ -11,6 +11,7 @@ import (
"github.com/pkg/browser"
"github.com/ying32/govcl/vcl"
"github.com/ying32/govcl/vcl/types"
"github.com/ying32/govcl/vcl/types/colors"
)
const (
@ -31,6 +32,7 @@ type TMainForm struct {
Tabs *vcl.TPageControl
propertiesBox *vcl.TMemo
contentBox *vcl.TStringGrid
insertRows []int32 // Rows in the StringGrid that are to-be-inserted
queryInput *vcl.TMemo
queryResult *vcl.TStringGrid
@ -226,6 +228,11 @@ func (f *TMainForm) OnFormCreate(sender vcl.IObject) {
// dataRefreshBtn.SetImageIndex(imgLightning)
dataRefreshBtn.SetOnClick(func(sender vcl.IObject) { f.RefreshCurrentItem() })
dataInsertBtn := vcl.NewToolButton(dataButtonBar)
dataInsertBtn.SetParent(dataButtonBar)
dataInsertBtn.SetCaption("Insert")
dataInsertBtn.SetOnClick(f.OnDataInsertClick)
f.contentBox = vcl.NewStringGrid(dataTab)
f.contentBox.SetParent(dataTab)
f.contentBox.BorderSpacing().SetLeft(MY_SPACING)
@ -233,6 +240,7 @@ func (f *TMainForm) OnFormCreate(sender vcl.IObject) {
f.contentBox.BorderSpacing().SetBottom(MY_SPACING)
f.contentBox.SetAlign(types.AlClient) // fill remaining space
f.contentBox.SetOptions(f.contentBox.Options().Include(types.GoThumbTracking, types.GoColSizing, types.GoDblClickAutoSize))
f.contentBox.SetOnPrepareCanvas(f.OnDataPrepareCanvas)
f.contentBox.SetDefaultColWidth(MY_WIDTH)
vcl_stringgrid_clear(f.contentBox)
@ -521,6 +529,39 @@ func (f *TMainForm) OnNavContextRefresh(item *vcl.TTreeNode, ndata *navData) {
item.SetExpanded(isExpanded)
}
func (f *TMainForm) OnDataPrepareCanvas(sender vcl.IObject, aCol, aRow int32, aState types.TGridDrawState) {
if len(f.insertRows) == 0 {
return // fast-path
}
isInsertRow := false
for _, rr := range f.insertRows {
if rr == aRow {
isInsertRow = true
break
}
}
if isInsertRow {
/*sender.(*vcl.TStringGrid)*/
f.contentBox.Canvas().Brush().SetColor(colors.ClYellow)
}
}
func (f *TMainForm) OnDataInsertClick(sender vcl.IObject) {
if !f.contentBox.Enabled() {
return // Not an active data view
}
rpos := f.contentBox.RowCount()
f.contentBox.SetRowCount(rpos + 1)
f.insertRows = append(f.insertRows, rpos)
// Scroll to bottom
f.contentBox.SetTopRow(rpos)
}
func (f *TMainForm) OnNavContextClose(sender vcl.IObject) {
curItem := f.Buckets.Selected()
if curItem == nil {
@ -572,6 +613,7 @@ func (f *TMainForm) OnNavChange(sender vcl.IObject, node *vcl.TTreeNode) {
}
// Reset some controls that the render function is expected to populate
f.insertRows = nil
f.propertiesBox.Clear()
vcl_stringgrid_clear(f.contentBox)