gui: basic syntax highlighting implementation (disabled)
This commit is contained in:
parent
60add3be86
commit
35a83eb483
46
main.go
46
main.go
@ -41,7 +41,7 @@ type TMainForm struct {
|
|||||||
insertRows map[int32]struct{} // Rows in the StringGrid that are to-be-inserted
|
insertRows map[int32]struct{} // Rows in the StringGrid that are to-be-inserted
|
||||||
deleteRows map[int32]struct{}
|
deleteRows map[int32]struct{}
|
||||||
updateRows map[int32][]int32 // Row->cells that are to-be-updated
|
updateRows map[int32][]int32 // Row->cells that are to-be-updated
|
||||||
queryInput *vcl.TMemo
|
queryInput *vcl.TRichEdit
|
||||||
queryResult *vcl.TStringGrid
|
queryResult *vcl.TStringGrid
|
||||||
|
|
||||||
none *noLoadedDatabase
|
none *noLoadedDatabase
|
||||||
@ -293,7 +293,7 @@ func (f *TMainForm) OnFormCreate(sender vcl.IObject) {
|
|||||||
queryExecBtn.SetImageIndex(imgResultsetNext)
|
queryExecBtn.SetImageIndex(imgResultsetNext)
|
||||||
queryExecBtn.SetOnClick(f.OnQueryExecute)
|
queryExecBtn.SetOnClick(f.OnQueryExecute)
|
||||||
|
|
||||||
f.queryInput = vcl.NewMemo(queryTab)
|
f.queryInput = vcl.NewRichEdit(queryTab)
|
||||||
f.queryInput.SetParent(queryTab)
|
f.queryInput.SetParent(queryTab)
|
||||||
f.queryInput.SetHeight(MY_HEIGHT)
|
f.queryInput.SetHeight(MY_HEIGHT)
|
||||||
f.queryInput.SetAlign(types.AlTop)
|
f.queryInput.SetAlign(types.AlTop)
|
||||||
@ -303,10 +303,12 @@ func (f *TMainForm) OnFormCreate(sender vcl.IObject) {
|
|||||||
} else {
|
} else {
|
||||||
f.queryInput.Font().SetName("monospace")
|
f.queryInput.Font().SetName("monospace")
|
||||||
}
|
}
|
||||||
|
f.queryInput.SetCursor(types.CrIBeam) // Use text cursor instead of default pointer cursor
|
||||||
f.queryInput.BorderSpacing().SetLeft(MY_SPACING)
|
f.queryInput.BorderSpacing().SetLeft(MY_SPACING)
|
||||||
//f.queryInput.BorderSpacing().SetTop(1)
|
//f.queryInput.BorderSpacing().SetTop(1)
|
||||||
f.queryInput.BorderSpacing().SetRight(MY_SPACING)
|
f.queryInput.BorderSpacing().SetRight(MY_SPACING)
|
||||||
f.queryInput.SetBorderStyle(types.BsFrame)
|
f.queryInput.SetBorderStyle(types.BsFrame)
|
||||||
|
// f.queryInput.SetOnKeyUp(f.OnQueryTextChanged) // Performs extremely slowly
|
||||||
|
|
||||||
vsplit := vcl.NewSplitter(queryTab)
|
vsplit := vcl.NewSplitter(queryTab)
|
||||||
vsplit.SetParent(queryTab)
|
vsplit.SetParent(queryTab)
|
||||||
@ -692,6 +694,46 @@ func (f *TMainForm) OnNavContextClose(sender vcl.IObject) {
|
|||||||
// n.b. This triggers OnNavChange, which will then re-render from noLoadedDatabase{}
|
// n.b. This triggers OnNavChange, which will then re-render from noLoadedDatabase{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// func (f *TMainForm) OnQueryTextChanged(sender vcl.IObject) {
|
||||||
|
func (f *TMainForm) OnQueryTextChanged(sender vcl.IObject, key *types.Char, shift types.TShiftState) {
|
||||||
|
|
||||||
|
// FIXME changing the text colour calls the onchange handler recursively
|
||||||
|
// FIXME changing the text colour pushes into the undo stack
|
||||||
|
|
||||||
|
// Preserve
|
||||||
|
f.queryInput.Lines().BeginUpdate()
|
||||||
|
origPos := f.queryInput.SelStart()
|
||||||
|
origLen := f.queryInput.SelLength()
|
||||||
|
defer func() {
|
||||||
|
f.queryInput.SetSelStart(origPos)
|
||||||
|
f.queryInput.SetSelLength(origLen)
|
||||||
|
f.queryInput.Lines().EndUpdate()
|
||||||
|
}()
|
||||||
|
|
||||||
|
tx := strings.ToLower(f.queryInput.Text())
|
||||||
|
|
||||||
|
// Reset all existing colors
|
||||||
|
f.queryInput.SetSelStart(0)
|
||||||
|
f.queryInput.SetSelLength(int32(len(tx)))
|
||||||
|
f.queryInput.SelAttributes().SetColor(colors.ClBlack)
|
||||||
|
|
||||||
|
searchPos := 0
|
||||||
|
for {
|
||||||
|
matchPos := strings.Index(tx[searchPos:], "select")
|
||||||
|
if matchPos == -1 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
matchPos += searchPos // compensate for slicing
|
||||||
|
|
||||||
|
f.queryInput.SetSelStart(int32(matchPos))
|
||||||
|
f.queryInput.SetSelLength(6)
|
||||||
|
f.queryInput.SelAttributes().SetColor(colors.ClRed)
|
||||||
|
|
||||||
|
searchPos = matchPos + 6 // strlen(SELECT)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (f *TMainForm) OnQueryExecute(sender vcl.IObject) {
|
func (f *TMainForm) OnQueryExecute(sender vcl.IObject) {
|
||||||
// If query tab is not selected, switch to it, but do not exec
|
// If query tab is not selected, switch to it, but do not exec
|
||||||
if f.Tabs.ActivePageIndex() != 2 {
|
if f.Tabs.ActivePageIndex() != 2 {
|
||||||
|
Loading…
Reference in New Issue
Block a user