gui: prep work for inserting rows
This commit is contained in:
parent
2b59efc410
commit
0d3b90b879
42
main.go
42
main.go
@ -11,6 +11,7 @@ import (
|
|||||||
"github.com/pkg/browser"
|
"github.com/pkg/browser"
|
||||||
"github.com/ying32/govcl/vcl"
|
"github.com/ying32/govcl/vcl"
|
||||||
"github.com/ying32/govcl/vcl/types"
|
"github.com/ying32/govcl/vcl/types"
|
||||||
|
"github.com/ying32/govcl/vcl/types/colors"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -31,6 +32,7 @@ type TMainForm struct {
|
|||||||
Tabs *vcl.TPageControl
|
Tabs *vcl.TPageControl
|
||||||
propertiesBox *vcl.TMemo
|
propertiesBox *vcl.TMemo
|
||||||
contentBox *vcl.TStringGrid
|
contentBox *vcl.TStringGrid
|
||||||
|
insertRows []int32 // Rows in the StringGrid that are to-be-inserted
|
||||||
queryInput *vcl.TMemo
|
queryInput *vcl.TMemo
|
||||||
queryResult *vcl.TStringGrid
|
queryResult *vcl.TStringGrid
|
||||||
|
|
||||||
@ -226,6 +228,11 @@ func (f *TMainForm) OnFormCreate(sender vcl.IObject) {
|
|||||||
// dataRefreshBtn.SetImageIndex(imgLightning)
|
// dataRefreshBtn.SetImageIndex(imgLightning)
|
||||||
dataRefreshBtn.SetOnClick(func(sender vcl.IObject) { f.RefreshCurrentItem() })
|
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 = vcl.NewStringGrid(dataTab)
|
||||||
f.contentBox.SetParent(dataTab)
|
f.contentBox.SetParent(dataTab)
|
||||||
f.contentBox.BorderSpacing().SetLeft(MY_SPACING)
|
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.BorderSpacing().SetBottom(MY_SPACING)
|
||||||
f.contentBox.SetAlign(types.AlClient) // fill remaining space
|
f.contentBox.SetAlign(types.AlClient) // fill remaining space
|
||||||
f.contentBox.SetOptions(f.contentBox.Options().Include(types.GoThumbTracking, types.GoColSizing, types.GoDblClickAutoSize))
|
f.contentBox.SetOptions(f.contentBox.Options().Include(types.GoThumbTracking, types.GoColSizing, types.GoDblClickAutoSize))
|
||||||
|
f.contentBox.SetOnPrepareCanvas(f.OnDataPrepareCanvas)
|
||||||
f.contentBox.SetDefaultColWidth(MY_WIDTH)
|
f.contentBox.SetDefaultColWidth(MY_WIDTH)
|
||||||
vcl_stringgrid_clear(f.contentBox)
|
vcl_stringgrid_clear(f.contentBox)
|
||||||
|
|
||||||
@ -521,6 +529,39 @@ func (f *TMainForm) OnNavContextRefresh(item *vcl.TTreeNode, ndata *navData) {
|
|||||||
item.SetExpanded(isExpanded)
|
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) {
|
func (f *TMainForm) OnNavContextClose(sender vcl.IObject) {
|
||||||
curItem := f.Buckets.Selected()
|
curItem := f.Buckets.Selected()
|
||||||
if curItem == nil {
|
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
|
// Reset some controls that the render function is expected to populate
|
||||||
|
f.insertRows = nil
|
||||||
f.propertiesBox.Clear()
|
f.propertiesBox.Clear()
|
||||||
vcl_stringgrid_clear(f.contentBox)
|
vcl_stringgrid_clear(f.contentBox)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user