From fc084d71900c51c38ed8eb408ed257266a986a46 Mon Sep 17 00:00:00 2001 From: mappu Date: Fri, 28 Jun 2024 12:29:44 +1200 Subject: [PATCH] gui: seamless refresh after bucket action, support nav removal --- db_bolt.go | 4 ++-- loadedDatabase.go | 4 ++++ main.go | 15 ++++++++++++++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/db_bolt.go b/db_bolt.go index 9ef56e6..dac984a 100644 --- a/db_bolt.go +++ b/db_bolt.go @@ -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) } } diff --git a/loadedDatabase.go b/loadedDatabase.go index 1e2dfa0..6828309 100644 --- a/loadedDatabase.go +++ b/loadedDatabase.go @@ -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) diff --git a/main.go b/main.go index 6c20d20..0316c3e 100644 --- a/main.go +++ b/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