main: infra for custom context actions
This commit is contained in:
parent
a14e58297a
commit
feffa67677
@ -103,6 +103,10 @@ func (ld *badgerLoadedDatabase) NavChildren(ndata *navData) ([]string, error) {
|
||||
}
|
||||
}
|
||||
|
||||
func (ld *badgerLoadedDatabase) NavContext(ndata *navData) ([]contextAction, error) {
|
||||
return nil, nil // No special actions are supported
|
||||
}
|
||||
|
||||
func (ld *badgerLoadedDatabase) ExecQuery(query string, resultArea *vcl.TListView) {
|
||||
vcl.ShowMessage("Badger doesn't support querying")
|
||||
}
|
||||
|
@ -94,6 +94,10 @@ func (ld *boltLoadedDatabase) NavChildren(ndata *navData) ([]string, error) {
|
||||
return boltChildBucketNames(ld.db, ndata.bucketPath)
|
||||
}
|
||||
|
||||
func (ld *boltLoadedDatabase) NavContext(ndata *navData) ([]contextAction, error) {
|
||||
return nil, nil // No special actions are supported
|
||||
}
|
||||
|
||||
func (ld *boltLoadedDatabase) ExecQuery(query string, resultArea *vcl.TListView) {
|
||||
vcl.ShowMessage("Bolt doesn't support querying")
|
||||
}
|
||||
|
@ -31,6 +31,10 @@ func (n *noLoadedDatabase) NavChildren(ndata *navData) ([]string, error) {
|
||||
return []string{}, nil
|
||||
}
|
||||
|
||||
func (ld *noLoadedDatabase) NavContext(ndata *navData) ([]contextAction, error) {
|
||||
return nil, nil // No special actions are supported
|
||||
}
|
||||
|
||||
func (n *noLoadedDatabase) Keepalive(ndata *navData) {
|
||||
}
|
||||
|
||||
|
@ -91,6 +91,10 @@ func (ld *pebbleLoadedDatabase) NavChildren(ndata *navData) ([]string, error) {
|
||||
}
|
||||
}
|
||||
|
||||
func (ld *pebbleLoadedDatabase) NavContext(ndata *navData) ([]contextAction, error) {
|
||||
return nil, nil // No special actions are supported
|
||||
}
|
||||
|
||||
func (ld *pebbleLoadedDatabase) ExecQuery(query string, resultArea *vcl.TListView) {
|
||||
vcl.ShowMessage("pebble doesn't support querying")
|
||||
}
|
||||
|
@ -165,6 +165,10 @@ func (ld *redisLoadedDatabase) NavChildren(ndata *navData) ([]string, error) {
|
||||
}
|
||||
}
|
||||
|
||||
func (ld *redisLoadedDatabase) NavContext(ndata *navData) ([]contextAction, error) {
|
||||
return nil, nil // No special actions are supported
|
||||
}
|
||||
|
||||
func (ld *redisLoadedDatabase) ExecQuery(query string, resultArea *vcl.TListView) {
|
||||
ctx := context.Background()
|
||||
|
||||
|
@ -230,6 +230,10 @@ func (ld *sqliteLoadedDatabase) NavChildren(ndata *navData) ([]string, error) {
|
||||
return nil, fmt.Errorf("unknown nav path %#v", ndata.bucketPath)
|
||||
}
|
||||
|
||||
func (ld *sqliteLoadedDatabase) NavContext(ndata *navData) ([]contextAction, error) {
|
||||
return nil, nil // No special actions are supported
|
||||
}
|
||||
|
||||
func (ld *sqliteLoadedDatabase) Close() {
|
||||
_ = ld.db.Close()
|
||||
ld.arena = nil
|
||||
|
@ -4,6 +4,11 @@ import (
|
||||
"github.com/ying32/govcl/vcl"
|
||||
)
|
||||
|
||||
type contextAction struct {
|
||||
Name string
|
||||
Callback func(ndata *navData)
|
||||
}
|
||||
|
||||
// loadedDatabase is a DB-agnostic interface for each loaded database.
|
||||
type loadedDatabase interface {
|
||||
DisplayName() string
|
||||
@ -12,6 +17,7 @@ type loadedDatabase interface {
|
||||
RenderForNav(f *TMainForm, ndata *navData)
|
||||
ExecQuery(query string, resultArea *vcl.TListView)
|
||||
NavChildren(ndata *navData) ([]string, error)
|
||||
NavContext(ndata *navData) ([]contextAction, error)
|
||||
Keepalive(ndata *navData)
|
||||
Close()
|
||||
}
|
||||
|
21
main.go
21
main.go
@ -378,7 +378,26 @@ func (f *TMainForm) OnNavContextPopup(sender vcl.IObject, mousePos types.TPoint,
|
||||
mnu.Items().Add(mnuRefresh)
|
||||
|
||||
// Check what custom actions the ndata->db itself wants to add
|
||||
// ...
|
||||
ndata := (*navData)(curItem.Data())
|
||||
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
|
||||
mnuAction.SetOnClick(func(sender vcl.IObject) { cb(ndata) })
|
||||
mnu.Items().Add(mnuAction)
|
||||
}
|
||||
}
|
||||
|
||||
if curItem.Parent() == nil {
|
||||
// Top-level item (database connection). Allow closing by right-click.
|
||||
|
Loading…
Reference in New Issue
Block a user