From 0d3b90b87929d43e91f5ce328e49940d85596568 Mon Sep 17 00:00:00 2001 From: mappu Date: Fri, 5 Jul 2024 20:07:19 +1200 Subject: [PATCH] gui: prep work for inserting rows --- main.go | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/main.go b/main.go index eb1d6a3..c459f3a 100644 --- a/main.go +++ b/main.go @@ -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)