gui: seamless refresh after bucket action, support nav removal
This commit is contained in:
parent
e2111017eb
commit
fc084d7190
@ -226,13 +226,13 @@ func boltChildBucketNames(db *bbolt.DB, path []string) ([]string, error) {
|
||||
if len(path) > 0 {
|
||||
b := tx.Bucket([]byte(path[0]))
|
||||
if b == nil {
|
||||
return fmt.Errorf("Unexpected missing root bucket %q", path[0])
|
||||
return fmt.Errorf("Root bucket %q: %w", path[0], ErrNavNotExist)
|
||||
}
|
||||
|
||||
for i := 1; i < len(path); i += 1 {
|
||||
b = b.Bucket([]byte(path[i]))
|
||||
if b == nil {
|
||||
return fmt.Errorf("Unexpected missing bucket %q", strings.Join(path[0:i], `/`))
|
||||
return fmt.Errorf("Bucket %q: %w", strings.Join(path[0:i], `/`), ErrNavNotExist)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,9 +1,13 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/ying32/govcl/vcl"
|
||||
)
|
||||
|
||||
var ErrNavNotExist error = errors.New("The selected item no longer exists")
|
||||
|
||||
type contextAction struct {
|
||||
Name string
|
||||
Callback func(ndata *navData)
|
||||
|
15
main.go
15
main.go
@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"runtime/debug"
|
||||
"strings"
|
||||
@ -412,7 +413,10 @@ func (f *TMainForm) OnNavContextPopup(sender vcl.IObject, mousePos types.TPoint,
|
||||
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) })
|
||||
mnuAction.SetOnClick(func(sender vcl.IObject) {
|
||||
cb(ndata)
|
||||
f.OnNavContextRefresh(curItem, ndata)
|
||||
})
|
||||
mnu.Items().Add(mnuAction)
|
||||
}
|
||||
}
|
||||
@ -518,6 +522,15 @@ func (f *TMainForm) OnNavExpanding(sender vcl.IObject, node *vcl.TTreeNode, allo
|
||||
|
||||
err := f.NavLoadChildren(node, ndata)
|
||||
if err != nil {
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
vcl.ShowMessage(err.Error())
|
||||
*allowExpansion = false // Permanently block
|
||||
return
|
||||
|
Loading…
Reference in New Issue
Block a user