2024-06-03 04:49:04 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2024-06-28 00:29:44 +00:00
|
|
|
"errors"
|
2024-06-03 04:49:04 +00:00
|
|
|
"fmt"
|
2024-06-30 01:16:27 +00:00
|
|
|
"runtime"
|
2024-06-27 23:21:14 +00:00
|
|
|
"runtime/debug"
|
2024-06-03 04:49:04 +00:00
|
|
|
"strings"
|
|
|
|
"unsafe"
|
|
|
|
|
2024-06-23 03:58:12 +00:00
|
|
|
"github.com/pkg/browser"
|
2024-06-03 04:49:04 +00:00
|
|
|
"github.com/ying32/govcl/vcl"
|
|
|
|
"github.com/ying32/govcl/vcl/types"
|
|
|
|
)
|
|
|
|
|
2024-06-27 23:53:01 +00:00
|
|
|
const (
|
|
|
|
APPNAME = "yvbolt"
|
|
|
|
HOMEPAGE_URL = "https://code.ivysaur.me/yvbolt"
|
|
|
|
)
|
|
|
|
|
2024-06-03 04:49:04 +00:00
|
|
|
type TMainForm struct {
|
|
|
|
*vcl.TForm
|
2024-06-08 02:24:35 +00:00
|
|
|
|
2024-06-29 00:13:34 +00:00
|
|
|
ImageList *vcl.TImageList
|
|
|
|
Menu *vcl.TMainMenu
|
|
|
|
|
|
|
|
SQLiteUseCliDriver *vcl.TMenuItem
|
|
|
|
|
2024-06-14 23:43:24 +00:00
|
|
|
StatusBar *vcl.TStatusBar
|
2024-06-03 04:49:04 +00:00
|
|
|
Buckets *vcl.TTreeView
|
|
|
|
Tabs *vcl.TPageControl
|
|
|
|
propertiesBox *vcl.TMemo
|
|
|
|
contentBox *vcl.TListView
|
2024-06-15 00:14:11 +00:00
|
|
|
queryInput *vcl.TMemo
|
|
|
|
queryResult *vcl.TListView
|
2024-06-03 04:49:04 +00:00
|
|
|
|
2024-06-23 02:55:21 +00:00
|
|
|
none *noLoadedDatabase
|
|
|
|
dbs []loadedDatabase
|
2024-06-03 04:49:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
mainForm *TMainForm
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
vcl.RunApp(&mainForm)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *TMainForm) OnFormCreate(sender vcl.IObject) {
|
2024-06-08 02:24:35 +00:00
|
|
|
f.ImageList = loadImages(f)
|
|
|
|
|
2024-06-27 23:53:01 +00:00
|
|
|
f.SetCaption(APPNAME)
|
2024-06-22 05:36:25 +00:00
|
|
|
f.ScreenCenter()
|
2024-06-14 23:42:23 +00:00
|
|
|
f.ImageList.GetIcon(imgDatabaseLightning, f.Icon())
|
2024-06-03 04:49:04 +00:00
|
|
|
|
|
|
|
mnuFile := vcl.NewMenuItem(f)
|
|
|
|
mnuFile.SetCaption("File")
|
|
|
|
|
2024-06-27 23:01:34 +00:00
|
|
|
//
|
|
|
|
|
2024-06-23 04:20:06 +00:00
|
|
|
mnuFileBadger := vcl.NewMenuItem(mnuFile)
|
|
|
|
mnuFileBadger.SetCaption("Badger")
|
2024-06-23 04:29:00 +00:00
|
|
|
mnuFileBadger.SetImageIndex(imgVendorDgraph)
|
2024-06-23 04:20:06 +00:00
|
|
|
mnuFile.Add(mnuFileBadger)
|
2024-06-08 02:23:38 +00:00
|
|
|
|
2024-06-27 23:11:34 +00:00
|
|
|
vcl_menuitem(mnuFileBadger, "Open database...", imgDatabaseAdd, f.OnMnuFileBadgerOpenClick)
|
|
|
|
vcl_menuitem(mnuFileBadger, "New in-memory database", imgDatabaseAdd, f.OnMnuFileBadgerMemoryClick)
|
2024-06-23 04:29:11 +00:00
|
|
|
|
2024-06-23 04:20:06 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
mnuFileBolt := vcl.NewMenuItem(mnuFile)
|
|
|
|
mnuFileBolt.SetCaption("Bolt")
|
|
|
|
mnuFileBolt.SetImageIndex(imgVendorGithub)
|
|
|
|
mnuFile.Add(mnuFileBolt)
|
2024-06-08 01:44:18 +00:00
|
|
|
|
2024-06-27 23:40:03 +00:00
|
|
|
vcl_menuitem(mnuFileBolt, "New database...", imgDatabaseAdd, f.OnMnuFileBoltNewClick)
|
2024-06-27 23:11:34 +00:00
|
|
|
vcl_menuitem(mnuFileBolt, "Open database...", imgDatabaseAdd, f.OnMnuFileBoltOpenClick)
|
2024-06-27 23:33:43 +00:00
|
|
|
vcl_menuitem(mnuFileBolt, "Open database (read-only)...", imgDatabaseAdd, f.OnMnuFileBoltOpenReadonlyClick)
|
2024-06-23 04:20:06 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
|
2024-06-27 23:01:34 +00:00
|
|
|
mnuFilePebble := vcl.NewMenuItem(mnuFile)
|
|
|
|
mnuFilePebble.SetCaption("Pebble")
|
|
|
|
mnuFilePebble.SetImageIndex(imgVendorCockroach)
|
|
|
|
mnuFile.Add(mnuFilePebble)
|
|
|
|
|
2024-06-27 23:11:34 +00:00
|
|
|
vcl_menuitem(mnuFilePebble, "Open database...", imgDatabaseAdd, f.OnMnuFilePebbleOpenClick)
|
|
|
|
vcl_menuitem(mnuFilePebble, "New in-memory database", imgDatabaseAdd, f.OnMnuFilePebbleMemoryClick)
|
2024-06-27 23:01:34 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
|
2024-06-23 04:20:06 +00:00
|
|
|
mnuFileRedis := vcl.NewMenuItem(mnuFile)
|
|
|
|
mnuFileRedis.SetCaption("Redis")
|
|
|
|
mnuFileRedis.SetImageIndex(imgVendorRedis)
|
|
|
|
mnuFile.Add(mnuFileRedis)
|
|
|
|
|
2024-06-27 23:11:34 +00:00
|
|
|
vcl_menuitem(mnuFileRedis, "Connect...", imgDatabaseAdd, f.OnMnuFileRedisConnectClick)
|
2024-06-23 04:20:06 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
mnuFileSqlite := vcl.NewMenuItem(mnuFile)
|
|
|
|
mnuFileSqlite.SetCaption("SQLite")
|
|
|
|
mnuFileSqlite.SetImageIndex(imgVendorSqlite)
|
|
|
|
mnuFile.Add(mnuFileSqlite)
|
|
|
|
|
2024-06-27 23:11:34 +00:00
|
|
|
vcl_menuitem(mnuFileSqlite, "Open database...", imgDatabaseAdd, f.OnMnuFileSqliteOpenClick)
|
|
|
|
vcl_menuitem(mnuFileSqlite, "New in-memory database", imgDatabaseAdd, f.OnMnuFileSqliteMemoryClick)
|
2024-06-23 04:20:06 +00:00
|
|
|
|
2024-06-29 00:13:34 +00:00
|
|
|
vcl_menuseparator(mnuFileSqlite)
|
|
|
|
f.SQLiteUseCliDriver = vcl_menuitem(mnuFileSqlite, "Connect using CLI driver (experimental)", -1, nil)
|
|
|
|
f.SQLiteUseCliDriver.SetAutoCheck(true)
|
|
|
|
|
2024-06-23 04:20:06 +00:00
|
|
|
//
|
2024-06-22 05:36:25 +00:00
|
|
|
|
2024-06-29 00:13:18 +00:00
|
|
|
vcl_menuseparator(mnuFile)
|
2024-06-08 01:34:49 +00:00
|
|
|
|
|
|
|
mnuFileExit := vcl.NewMenuItem(mnuFile)
|
|
|
|
mnuFileExit.SetCaption("Exit")
|
|
|
|
mnuFileExit.SetOnClick(f.OnMnuFileExitClick)
|
|
|
|
mnuFile.Add(mnuFileExit)
|
|
|
|
|
2024-06-15 00:14:32 +00:00
|
|
|
mnuQuery := vcl.NewMenuItem(f)
|
|
|
|
mnuQuery.SetCaption("Query")
|
|
|
|
|
|
|
|
mnuQueryExecute := vcl.NewMenuItem(mnuQuery)
|
|
|
|
mnuQueryExecute.SetCaption("Execute")
|
|
|
|
mnuQueryExecute.SetShortCutFromString("F5")
|
|
|
|
mnuQueryExecute.SetOnClick(f.OnQueryExecute)
|
2024-06-15 00:57:35 +00:00
|
|
|
mnuQueryExecute.SetImageIndex(imgLightning)
|
2024-06-15 00:14:32 +00:00
|
|
|
mnuQuery.Add(mnuQueryExecute)
|
|
|
|
|
2024-06-23 03:58:12 +00:00
|
|
|
mnuHelp := vcl.NewMenuItem(f)
|
|
|
|
mnuHelp.SetCaption("Help")
|
|
|
|
|
2024-06-27 23:21:14 +00:00
|
|
|
mnuHelpVersion := vcl.NewMenuItem(mnuHelp)
|
|
|
|
mnuHelpVersion.SetCaption("Driver versions...")
|
|
|
|
mnuHelpVersion.SetOnClick(f.OnMenuHelpVersion)
|
|
|
|
mnuHelp.Add(mnuHelpVersion)
|
|
|
|
|
2024-06-23 03:58:12 +00:00
|
|
|
mnuHelpHomepage := vcl.NewMenuItem(mnuHelp)
|
2024-06-27 23:53:01 +00:00
|
|
|
mnuHelpHomepage.SetCaption("About " + APPNAME)
|
2024-06-23 03:58:12 +00:00
|
|
|
mnuHelpHomepage.SetShortCutFromString("F1")
|
|
|
|
mnuHelpHomepage.SetOnClick(f.OnMnuHelpHomepage)
|
|
|
|
mnuHelp.Add(mnuHelpHomepage)
|
|
|
|
|
2024-06-03 04:49:04 +00:00
|
|
|
f.Menu = vcl.NewMainMenu(f)
|
2024-06-08 02:24:44 +00:00
|
|
|
f.Menu.SetImages(f.ImageList)
|
2024-06-03 04:49:04 +00:00
|
|
|
f.Menu.Items().Add(mnuFile)
|
2024-06-15 00:14:32 +00:00
|
|
|
f.Menu.Items().Add(mnuQuery)
|
2024-06-23 03:58:12 +00:00
|
|
|
f.Menu.Items().Add(mnuHelp)
|
2024-06-03 04:49:04 +00:00
|
|
|
|
2024-06-14 23:43:24 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
f.StatusBar = vcl.NewStatusBar(f)
|
|
|
|
f.StatusBar.SetParent(f)
|
|
|
|
f.StatusBar.SetSimpleText("")
|
|
|
|
|
|
|
|
//
|
|
|
|
|
2024-06-03 04:49:04 +00:00
|
|
|
f.Buckets = vcl.NewTreeView(f)
|
|
|
|
f.Buckets.SetParent(f)
|
2024-06-08 02:24:44 +00:00
|
|
|
f.Buckets.SetImages(f.ImageList)
|
2024-06-03 04:49:04 +00:00
|
|
|
f.Buckets.SetAlign(types.AlLeft)
|
|
|
|
f.Buckets.SetWidth(MY_WIDTH)
|
|
|
|
f.Buckets.SetReadOnly(true) // prevent click to rename on nodes
|
|
|
|
f.Buckets.SetOnExpanding(f.OnNavExpanding)
|
|
|
|
f.Buckets.SetOnChange(f.OnNavChange)
|
2024-06-23 03:28:15 +00:00
|
|
|
f.Buckets.SetOnContextPopup(f.OnNavContextPopup)
|
2024-06-03 04:49:04 +00:00
|
|
|
|
|
|
|
hsplit := vcl.NewSplitter(f)
|
|
|
|
hsplit.SetParent(f)
|
|
|
|
hsplit.SetAlign(types.AlLeft)
|
|
|
|
hsplit.SetLeft(1) // Just needs to be further "over" than f.Buckets for auto-alignment
|
|
|
|
|
|
|
|
f.Tabs = vcl.NewPageControl(f)
|
|
|
|
f.Tabs.SetParent(f)
|
2024-06-14 23:43:58 +00:00
|
|
|
f.Tabs.SetAlign(types.AlClient) // fill remaining space
|
|
|
|
f.Tabs.SetImages(f.ImageList)
|
2024-06-03 04:49:04 +00:00
|
|
|
|
|
|
|
propertiesTab := vcl.NewTabSheet(f.Tabs)
|
|
|
|
propertiesTab.SetParent(f.Tabs)
|
|
|
|
propertiesTab.SetCaption("Properties")
|
2024-06-14 23:43:58 +00:00
|
|
|
propertiesTab.SetImageIndex(imgChartBar)
|
2024-06-03 04:49:04 +00:00
|
|
|
|
|
|
|
f.propertiesBox = vcl.NewMemo(propertiesTab)
|
|
|
|
f.propertiesBox.SetParent(propertiesTab)
|
|
|
|
f.propertiesBox.BorderSpacing().SetAround(MY_SPACING)
|
|
|
|
f.propertiesBox.SetAlign(types.AlClient) // fill remaining space
|
|
|
|
f.propertiesBox.SetReadOnly(true)
|
2024-06-29 23:05:16 +00:00
|
|
|
f.propertiesBox.SetEnabled(true) // Need to leave it enabled so scrolling works
|
|
|
|
f.propertiesBox.SetColor(vcl_default_tab_background())
|
2024-06-23 02:56:00 +00:00
|
|
|
|
2024-06-03 04:49:04 +00:00
|
|
|
f.propertiesBox.SetBorderStyle(types.BsNone)
|
2024-06-23 02:56:00 +00:00
|
|
|
f.propertiesBox.SetScrollBars(types.SsAutoVertical)
|
2024-06-03 04:49:04 +00:00
|
|
|
|
|
|
|
dataTab := vcl.NewTabSheet(f.Tabs)
|
|
|
|
dataTab.SetParent(f.Tabs)
|
|
|
|
dataTab.SetCaption("Data")
|
2024-06-14 23:43:58 +00:00
|
|
|
dataTab.SetImageIndex(imgTable)
|
2024-06-03 04:49:04 +00:00
|
|
|
|
|
|
|
f.contentBox = vcl.NewListView(dataTab)
|
|
|
|
f.contentBox.SetParent(dataTab)
|
|
|
|
f.contentBox.BorderSpacing().SetAround(MY_SPACING)
|
|
|
|
f.contentBox.SetAlign(types.AlClient) // fill remaining space
|
|
|
|
f.contentBox.SetViewStyle(types.VsReport) // "Report style" i.e. has columns
|
|
|
|
f.contentBox.SetAutoWidthLastColumn(true)
|
|
|
|
f.contentBox.SetReadOnly(true)
|
2024-06-08 02:49:57 +00:00
|
|
|
f.contentBox.Columns().Clear()
|
2024-06-15 00:14:11 +00:00
|
|
|
|
|
|
|
queryTab := vcl.NewTabSheet(f.Tabs)
|
|
|
|
queryTab.SetParent(f.Tabs)
|
|
|
|
queryTab.SetCaption("Query")
|
|
|
|
queryTab.SetImageIndex(imgLightning)
|
|
|
|
|
2024-06-15 00:57:35 +00:00
|
|
|
queryButtonBar := vcl.NewToolBar(queryTab)
|
|
|
|
queryButtonBar.SetParent(queryTab)
|
|
|
|
queryButtonBar.SetAlign(types.AlTop)
|
|
|
|
queryButtonBar.BorderSpacing().SetLeft(MY_SPACING)
|
|
|
|
queryButtonBar.BorderSpacing().SetTop(MY_SPACING)
|
2024-06-29 23:10:19 +00:00
|
|
|
//queryButtonBar.BorderSpacing().SetBottom(1)
|
2024-06-15 00:57:35 +00:00
|
|
|
queryButtonBar.BorderSpacing().SetRight(MY_SPACING)
|
2024-06-29 23:10:19 +00:00
|
|
|
queryButtonBar.SetEdgeBorders(0)
|
2024-06-15 00:57:35 +00:00
|
|
|
queryButtonBar.SetImages(f.ImageList)
|
|
|
|
queryButtonBar.SetShowCaptions(true)
|
|
|
|
|
|
|
|
queryExecBtn := vcl.NewToolButton(queryButtonBar)
|
|
|
|
queryExecBtn.SetParent(queryButtonBar)
|
2024-06-15 00:14:11 +00:00
|
|
|
queryExecBtn.SetCaption("Execute")
|
2024-06-15 00:57:35 +00:00
|
|
|
// queryExecBtn.SetImageIndex(imgLightning)
|
2024-06-15 00:14:11 +00:00
|
|
|
queryExecBtn.SetOnClick(f.OnQueryExecute)
|
|
|
|
|
|
|
|
f.queryInput = vcl.NewMemo(queryTab)
|
|
|
|
f.queryInput.SetParent(queryTab)
|
|
|
|
f.queryInput.SetHeight(MY_HEIGHT)
|
|
|
|
f.queryInput.SetAlign(types.AlTop)
|
|
|
|
f.queryInput.SetTop(1)
|
2024-06-30 01:16:27 +00:00
|
|
|
if runtime.GOOS == "windows" {
|
|
|
|
f.queryInput.Font().SetName("Consolas")
|
|
|
|
} else {
|
|
|
|
f.queryInput.Font().SetName("monospace")
|
|
|
|
}
|
2024-06-15 00:14:11 +00:00
|
|
|
f.queryInput.BorderSpacing().SetLeft(MY_SPACING)
|
2024-06-29 23:10:19 +00:00
|
|
|
//f.queryInput.BorderSpacing().SetTop(1)
|
2024-06-15 00:14:11 +00:00
|
|
|
f.queryInput.BorderSpacing().SetRight(MY_SPACING)
|
2024-06-29 23:10:19 +00:00
|
|
|
f.queryInput.SetBorderStyle(types.BsFrame)
|
2024-06-15 00:14:11 +00:00
|
|
|
|
|
|
|
vsplit := vcl.NewSplitter(queryTab)
|
|
|
|
vsplit.SetParent(queryTab)
|
|
|
|
vsplit.SetAlign(types.AlTop)
|
|
|
|
vsplit.SetTop(2)
|
|
|
|
|
|
|
|
f.queryResult = vcl.NewListView(queryTab)
|
|
|
|
f.queryResult.SetParent(queryTab)
|
|
|
|
f.queryResult.SetAlign(types.AlClient) // fill remaining space
|
|
|
|
f.queryResult.SetViewStyle(types.VsReport) // "Report style" i.e. has columns
|
|
|
|
f.queryResult.SetAutoWidthLastColumn(true)
|
|
|
|
f.queryResult.SetReadOnly(true)
|
|
|
|
f.queryResult.Columns().Clear()
|
|
|
|
f.queryResult.BorderSpacing().SetLeft(MY_SPACING)
|
|
|
|
f.queryResult.BorderSpacing().SetRight(MY_SPACING)
|
|
|
|
f.queryResult.BorderSpacing().SetBottom(MY_SPACING)
|
2024-06-23 02:55:21 +00:00
|
|
|
|
|
|
|
f.none = &noLoadedDatabase{}
|
|
|
|
f.OnNavChange(f, nil) // calls f.none.RenderForNav and sets up status bar content
|
2024-06-03 04:49:04 +00:00
|
|
|
}
|
|
|
|
|
2024-06-27 23:40:03 +00:00
|
|
|
func (f *TMainForm) OnMnuFileBoltNewClick(sender vcl.IObject) {
|
|
|
|
dlg := vcl.NewSaveDialog(f)
|
|
|
|
dlg.SetTitle("Save database as...")
|
|
|
|
dlg.SetFilter("Bolt database|*.db|All files|*.*")
|
|
|
|
ret := dlg.Execute() // Fake blocking
|
|
|
|
if ret {
|
|
|
|
f.boltAddDatabaseFromFile(dlg.FileName(), false)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-27 23:11:34 +00:00
|
|
|
func (f *TMainForm) OnMnuFileBoltOpenClick(sender vcl.IObject) {
|
2024-06-03 04:49:04 +00:00
|
|
|
dlg := vcl.NewOpenDialog(f)
|
|
|
|
dlg.SetTitle("Select a database file...")
|
2024-06-08 02:23:38 +00:00
|
|
|
dlg.SetFilter("Bolt database|*.db|All files|*.*")
|
2024-06-03 04:49:04 +00:00
|
|
|
ret := dlg.Execute() // Fake blocking
|
|
|
|
if ret {
|
2024-06-27 23:33:43 +00:00
|
|
|
f.boltAddDatabaseFromFile(dlg.FileName(), false)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *TMainForm) OnMnuFileBoltOpenReadonlyClick(sender vcl.IObject) {
|
|
|
|
dlg := vcl.NewOpenDialog(f)
|
|
|
|
dlg.SetTitle("Select a database file...")
|
|
|
|
dlg.SetFilter("Bolt database|*.db|All files|*.*")
|
|
|
|
ret := dlg.Execute() // Fake blocking
|
|
|
|
if ret {
|
|
|
|
f.boltAddDatabaseFromFile(dlg.FileName(), true)
|
2024-06-03 04:49:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-08 02:23:38 +00:00
|
|
|
func (f *TMainForm) OnMnuFileSqliteOpenClick(sender vcl.IObject) {
|
2024-06-29 00:13:34 +00:00
|
|
|
cliDriver := f.SQLiteUseCliDriver.Checked()
|
|
|
|
|
2024-06-08 02:23:38 +00:00
|
|
|
dlg := vcl.NewOpenDialog(f)
|
|
|
|
dlg.SetTitle("Select a database file...")
|
|
|
|
dlg.SetFilter("SQLite database|*.db;*.db3;*.sqlite;*.sqlite3|All files|*.*")
|
|
|
|
ret := dlg.Execute() // Fake blocking
|
|
|
|
if ret {
|
2024-06-29 00:13:34 +00:00
|
|
|
f.sqliteAddDatabaseFromFile(dlg.FileName(), cliDriver)
|
2024-06-08 02:23:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-15 00:37:44 +00:00
|
|
|
func (f *TMainForm) OnMnuFileBadgerOpenClick(sender vcl.IObject) {
|
|
|
|
dlg := vcl.NewSelectDirectoryDialog(f)
|
|
|
|
dlg.SetTitle("Select a database directory...")
|
|
|
|
ret := dlg.Execute() // Fake blocking
|
|
|
|
if ret {
|
|
|
|
f.badgerAddDatabaseFromDirectory(dlg.FileName())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-23 04:29:11 +00:00
|
|
|
func (f *TMainForm) OnMnuFileBadgerMemoryClick(sender vcl.IObject) {
|
|
|
|
f.badgerAddDatabaseFromMemory()
|
|
|
|
}
|
|
|
|
|
2024-06-27 23:01:34 +00:00
|
|
|
func (f *TMainForm) OnMnuFilePebbleOpenClick(sender vcl.IObject) {
|
|
|
|
dlg := vcl.NewSelectDirectoryDialog(f)
|
|
|
|
dlg.SetTitle("Select a database directory...")
|
|
|
|
ret := dlg.Execute() // Fake blocking
|
|
|
|
if ret {
|
|
|
|
f.pebbleAddDatabaseFrom(dlg.FileName(), nil)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *TMainForm) OnMnuFilePebbleMemoryClick(sender vcl.IObject) {
|
|
|
|
f.pebbleAddDatabaseFromMemory()
|
|
|
|
}
|
|
|
|
|
2024-06-08 02:23:38 +00:00
|
|
|
func (f *TMainForm) OnMnuFileSqliteMemoryClick(sender vcl.IObject) {
|
2024-06-29 00:13:34 +00:00
|
|
|
cliDriver := f.SQLiteUseCliDriver.Checked()
|
|
|
|
|
|
|
|
f.sqliteAddDatabaseFromFile(`:memory:`, cliDriver)
|
2024-06-08 01:34:49 +00:00
|
|
|
}
|
|
|
|
|
2024-06-22 05:36:25 +00:00
|
|
|
func (f *TMainForm) OnMnuFileRedisConnectClick(sender vcl.IObject) {
|
2024-06-23 01:07:33 +00:00
|
|
|
|
2024-06-22 05:36:25 +00:00
|
|
|
var child *TRedisConnectionDialog
|
|
|
|
vcl.Application.CreateForm(&child)
|
2024-06-23 01:07:33 +00:00
|
|
|
defer child.Free()
|
|
|
|
|
|
|
|
var ret TRedisConnectionDialogResult
|
|
|
|
child.CustomReturn = &ret
|
|
|
|
|
|
|
|
mr := child.ShowModal() // Fake blocking
|
|
|
|
if mr != types.MrOk || ret == nil {
|
|
|
|
return // Cancelled
|
|
|
|
}
|
|
|
|
|
|
|
|
// Connect
|
|
|
|
f.redisConnect(ret)
|
2024-06-22 05:36:25 +00:00
|
|
|
}
|
|
|
|
|
2024-06-08 02:23:38 +00:00
|
|
|
func (f *TMainForm) OnMnuFileExitClick(sender vcl.IObject) {
|
2024-06-14 23:44:19 +00:00
|
|
|
f.Close()
|
2024-06-08 01:44:18 +00:00
|
|
|
}
|
|
|
|
|
2024-06-23 03:58:12 +00:00
|
|
|
func (f *TMainForm) OnMnuHelpHomepage(sender vcl.IObject) {
|
2024-06-27 23:53:01 +00:00
|
|
|
err := browser.OpenURL(HOMEPAGE_URL)
|
2024-06-23 03:58:12 +00:00
|
|
|
if err != nil {
|
|
|
|
vcl.ShowMessage("Opening browser: " + err.Error())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-27 23:21:14 +00:00
|
|
|
func (f *TMainForm) OnMenuHelpVersion(sender vcl.IObject) {
|
|
|
|
|
|
|
|
bi, ok := debug.ReadBuildInfo()
|
|
|
|
if !ok {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-06-27 23:53:01 +00:00
|
|
|
info := "This version of " + APPNAME + " was compiled with:\n"
|
2024-06-27 23:21:14 +00:00
|
|
|
for _, dep := range bi.Deps {
|
|
|
|
|
|
|
|
// Filter to only interesting things
|
|
|
|
switch dep.Path {
|
|
|
|
case `github.com/cockroachdb/pebble`,
|
|
|
|
`github.com/dgraph-io/badger/v4`,
|
|
|
|
`github.com/mattn/go-sqlite3`,
|
|
|
|
`github.com/redis/go-redis/v9`,
|
|
|
|
`go.etcd.io/bbolt`,
|
|
|
|
`modernc.org/sqlite`:
|
|
|
|
info += fmt.Sprintf("- %s %s\n", dep.Path, dep.Version)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
vcl.ShowMessage(info)
|
|
|
|
}
|
|
|
|
|
2024-06-23 03:28:15 +00:00
|
|
|
func (f *TMainForm) OnNavContextPopup(sender vcl.IObject, mousePos types.TPoint, handled *bool) {
|
|
|
|
*handled = true
|
|
|
|
|
|
|
|
curItem := f.Buckets.Selected()
|
|
|
|
if curItem == nil {
|
|
|
|
// Nothing is selected at all
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-06-28 00:04:39 +00:00
|
|
|
ndata := (*navData)(curItem.Data())
|
|
|
|
|
2024-06-23 03:28:15 +00:00
|
|
|
mnu := vcl.NewPopupMenu(f.Buckets)
|
2024-06-28 00:00:18 +00:00
|
|
|
mnu.SetImages(f.ImageList)
|
2024-06-23 03:28:15 +00:00
|
|
|
|
|
|
|
mnuRefresh := vcl.NewMenuItem(mnu)
|
|
|
|
mnuRefresh.SetCaption("Refresh")
|
2024-06-28 00:00:18 +00:00
|
|
|
mnuRefresh.SetImageIndex(imgArrowRefresh)
|
2024-06-28 00:04:39 +00:00
|
|
|
mnuRefresh.SetOnClick(func(sender vcl.IObject) { f.OnNavContextRefresh(curItem, ndata) })
|
2024-06-23 03:28:15 +00:00
|
|
|
mnu.Items().Add(mnuRefresh)
|
|
|
|
|
|
|
|
// Check what custom actions the ndata->db itself wants to add
|
2024-06-27 23:34:00 +00:00
|
|
|
actions, err := ndata.ld.NavContext(ndata)
|
|
|
|
if err != nil {
|
|
|
|
vcl.ShowMessage(err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(actions) > 0 {
|
|
|
|
mnuSep := vcl.NewMenuItem(mnu)
|
|
|
|
mnuSep.SetCaption("-")
|
|
|
|
mnu.Items().Add(mnuSep)
|
|
|
|
|
|
|
|
for _, action := range actions {
|
|
|
|
mnuAction := vcl.NewMenuItem(mnu)
|
|
|
|
mnuAction.SetCaption(action.Name)
|
|
|
|
cb := action.Callback // Copy to avoid reuse of loop variable
|
2024-06-28 00:29:44 +00:00
|
|
|
mnuAction.SetOnClick(func(sender vcl.IObject) {
|
|
|
|
cb(ndata)
|
|
|
|
f.OnNavContextRefresh(curItem, ndata)
|
|
|
|
})
|
2024-06-27 23:34:00 +00:00
|
|
|
mnu.Items().Add(mnuAction)
|
|
|
|
}
|
|
|
|
}
|
2024-06-23 03:28:15 +00:00
|
|
|
|
|
|
|
if curItem.Parent() == nil {
|
|
|
|
// Top-level item (database connection). Allow closing by right-click.
|
|
|
|
mnuSep := vcl.NewMenuItem(mnu)
|
|
|
|
mnuSep.SetCaption("-")
|
|
|
|
mnu.Items().Add(mnuSep)
|
|
|
|
|
|
|
|
mnuClose := vcl.NewMenuItem(mnu)
|
|
|
|
mnuClose.SetCaption("Close")
|
|
|
|
mnuClose.SetOnClick(f.OnNavContextClose)
|
2024-06-28 00:00:18 +00:00
|
|
|
mnuClose.SetImageIndex(imgDatabaseDelete)
|
2024-06-23 03:28:15 +00:00
|
|
|
mnu.Items().Add(mnuClose)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Show popup
|
|
|
|
mnu.Popup2()
|
|
|
|
}
|
|
|
|
|
2024-06-28 00:04:39 +00:00
|
|
|
func (f *TMainForm) OnNavContextRefresh(item *vcl.TTreeNode, ndata *navData) {
|
|
|
|
isExpanded := item.Expanded()
|
|
|
|
|
|
|
|
// Reset nav node to 'unloaded' state
|
|
|
|
item.Collapse(true)
|
|
|
|
item.DeleteChildren()
|
|
|
|
item.SetHasChildren(true)
|
|
|
|
ndata.childrenLoaded = false
|
|
|
|
|
|
|
|
// Trigger a virtual reload
|
|
|
|
item.Expand(false) // Calls OnNavExpanding to dynamically detect children
|
|
|
|
|
|
|
|
// Restore previous gui state
|
|
|
|
item.SetExpanded(isExpanded)
|
2024-06-23 03:28:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (f *TMainForm) OnNavContextClose(sender vcl.IObject) {
|
|
|
|
curItem := f.Buckets.Selected()
|
|
|
|
if curItem == nil {
|
|
|
|
return // Nothing selected (shouldn't happen)
|
|
|
|
}
|
|
|
|
if curItem.Parent() != nil {
|
|
|
|
return // Selection is not top-level DB connection (shouldn't happen)
|
|
|
|
}
|
|
|
|
|
|
|
|
ndata := (*navData)(curItem.Data())
|
|
|
|
|
|
|
|
ndata.ld.Close()
|
|
|
|
curItem.Delete()
|
|
|
|
|
|
|
|
// n.b. This triggers OnNavChange, which will then re-render from noLoadedDatabase{}
|
|
|
|
}
|
|
|
|
|
2024-06-15 00:14:11 +00:00
|
|
|
func (f *TMainForm) OnQueryExecute(sender vcl.IObject) {
|
2024-06-15 00:14:32 +00:00
|
|
|
// If query tab is not selected, switch to it, but do not exec
|
|
|
|
if f.Tabs.ActivePageIndex() != 2 {
|
|
|
|
f.Tabs.SetActivePageIndex(2)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-06-23 01:07:52 +00:00
|
|
|
queryString := f.queryInput.Text()
|
|
|
|
if f.queryInput.SelLength() > 0 {
|
|
|
|
queryString = f.queryInput.SelText() // Just the selected text
|
|
|
|
}
|
|
|
|
|
2024-06-15 00:14:11 +00:00
|
|
|
// Execute
|
|
|
|
node := f.Buckets.Selected()
|
|
|
|
if node == nil {
|
|
|
|
vcl.ShowMessage("No database selected")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
ndata := (*navData)(node.Data())
|
2024-06-23 01:07:52 +00:00
|
|
|
ndata.ld.ExecQuery(queryString, f.queryResult)
|
2024-06-15 00:14:11 +00:00
|
|
|
}
|
|
|
|
|
2024-06-03 04:49:04 +00:00
|
|
|
func (f *TMainForm) OnNavChange(sender vcl.IObject, node *vcl.TTreeNode) {
|
|
|
|
|
2024-06-23 02:55:21 +00:00
|
|
|
var ld loadedDatabase = f.none
|
|
|
|
var ndata *navData = nil
|
2024-06-03 04:49:04 +00:00
|
|
|
|
2024-06-23 02:55:21 +00:00
|
|
|
if node != nil && node.Data() != nil {
|
|
|
|
ndata = (*navData)(node.Data())
|
|
|
|
ld = ndata.ld
|
|
|
|
}
|
2024-06-14 23:43:24 +00:00
|
|
|
|
2024-06-23 02:55:21 +00:00
|
|
|
ld.RenderForNav(f, ndata) // Handover to the database type's own renderer function
|
2024-06-14 23:43:24 +00:00
|
|
|
|
|
|
|
// We're in charge of common status bar text updates
|
2024-06-23 02:55:21 +00:00
|
|
|
f.StatusBar.SetSimpleText(ld.DisplayName() + " | " + ld.DriverName())
|
2024-06-03 04:49:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (f *TMainForm) OnNavExpanding(sender vcl.IObject, node *vcl.TTreeNode, allowExpansion *bool) {
|
|
|
|
|
|
|
|
if node.Data() == nil {
|
|
|
|
vcl.ShowMessage("unexpected nil data")
|
|
|
|
*allowExpansion = false
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
ndata := (*navData)(node.Data())
|
|
|
|
|
2024-06-23 03:12:26 +00:00
|
|
|
err := f.NavLoadChildren(node, ndata)
|
|
|
|
if err != nil {
|
2024-06-28 00:29:44 +00:00
|
|
|
|
|
|
|
if errors.Is(err, ErrNavNotExist) {
|
|
|
|
// The nav entry has been deleted.
|
|
|
|
// This is a normal thing to happen when e.g. deleting a table
|
|
|
|
// f.StatusBar.SetSimpleText(err.Error()) // Just gets overridden when the selection changes
|
|
|
|
node.Delete()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-06-23 03:12:26 +00:00
|
|
|
vcl.ShowMessage(err.Error())
|
|
|
|
*allowExpansion = false // Permanently block
|
2024-06-03 04:49:04 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-06-23 03:12:26 +00:00
|
|
|
*allowExpansion = node.HasChildren()
|
2024-06-23 03:21:41 +00:00
|
|
|
|
|
|
|
// While we're here - preload one single level deep (not any deeper)
|
|
|
|
|
|
|
|
if node.HasChildren() {
|
|
|
|
|
|
|
|
// This node has children that we haven't processed. Process them now
|
|
|
|
cc := node.GetFirstChild()
|
|
|
|
|
|
|
|
for {
|
|
|
|
ndataChild := (*navData)(cc.Data())
|
|
|
|
if ndataChild.childrenLoaded {
|
|
|
|
break // We always do them together, so if one's done, no need to keep looking
|
|
|
|
}
|
|
|
|
|
|
|
|
f.NavLoadChildren(cc, ndataChild)
|
|
|
|
|
|
|
|
cc = cc.GetNextSibling()
|
|
|
|
if cc == nil {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2024-06-23 03:12:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (f *TMainForm) NavLoadChildren(node *vcl.TTreeNode, ndata *navData) error {
|
|
|
|
|
|
|
|
if ndata.childrenLoaded {
|
|
|
|
return nil // Nothing to do
|
|
|
|
}
|
|
|
|
|
2024-06-03 04:49:04 +00:00
|
|
|
// Find the child buckets from this point under the element
|
2024-06-08 01:34:33 +00:00
|
|
|
nextBucketNames, err := ndata.ld.NavChildren(ndata)
|
2024-06-03 04:49:04 +00:00
|
|
|
if err != nil {
|
2024-06-23 03:12:26 +00:00
|
|
|
return fmt.Errorf("Failed to find child buckets under %q: %w", strings.Join(ndata.bucketPath, `/`), err)
|
2024-06-03 04:49:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ndata.childrenLoaded = true // don't repeat this work
|
|
|
|
|
|
|
|
if len(nextBucketNames) == 0 {
|
|
|
|
node.SetHasChildren(false)
|
|
|
|
|
|
|
|
} else {
|
2024-06-23 03:12:26 +00:00
|
|
|
node.SetHasChildren(true)
|
2024-06-03 04:49:04 +00:00
|
|
|
|
|
|
|
// Populate LCL child nodes
|
|
|
|
for _, bucketName := range nextBucketNames {
|
|
|
|
|
|
|
|
node := f.Buckets.Items().AddChild(node, formatUtf8([]byte(bucketName)))
|
2024-06-23 03:21:41 +00:00
|
|
|
node.SetHasChildren(true) // dynamically populate in OnNavExpanding
|
2024-06-14 23:43:58 +00:00
|
|
|
node.SetImageIndex(imgTable)
|
|
|
|
node.SetSelectedIndex(imgTable)
|
2024-06-03 04:49:04 +00:00
|
|
|
navData := &navData{
|
|
|
|
ld: ndata.ld,
|
|
|
|
childrenLoaded: false, // will be loaded dynamically
|
|
|
|
bucketPath: []string{}, // empty = root
|
|
|
|
}
|
|
|
|
navData.bucketPath = append(navData.bucketPath, ndata.bucketPath...)
|
|
|
|
navData.bucketPath = append(navData.bucketPath, bucketName)
|
|
|
|
node.SetData(unsafe.Pointer(navData))
|
2024-06-08 01:34:33 +00:00
|
|
|
|
|
|
|
ndata.ld.Keepalive(navData)
|
2024-06-23 03:12:26 +00:00
|
|
|
}
|
2024-06-03 04:49:04 +00:00
|
|
|
}
|
2024-06-23 03:12:26 +00:00
|
|
|
|
|
|
|
return nil
|
2024-06-03 04:49:04 +00:00
|
|
|
}
|