gui: seamless refresh after bucket action, support nav removal

This commit is contained in:
mappu 2024-06-28 12:29:44 +12:00
parent e2111017eb
commit fc084d7190
3 changed files with 20 additions and 3 deletions

View File

@ -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)
}
}

View File

@ -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
View File

@ -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