From 896a7a529a33619b938c1134c6ea03c244b4fc7b Mon Sep 17 00:00:00 2001 From: Song Lim Date: Tue, 15 Aug 2023 11:22:35 +0800 Subject: [PATCH] re-design delete bucket/key ui --- internal/cons/error.go | 4 +--- internal/gui/component.go | 19 +++++++++++++++++-- internal/gui/handler.go | 4 ---- internal/gui/state.go | 1 - internal/gui/view.go | 2 -- 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/internal/cons/error.go b/internal/cons/error.go index 2f667f7..b186596 100644 --- a/internal/cons/error.go +++ b/internal/cons/error.go @@ -1,7 +1,5 @@ package cons const ( - ErrNoDb = "No database opened" - ErrNoBucket = "No bucket selected" - ErrNoKey = "No key selected" + ErrNoDb = "No database opened" ) diff --git a/internal/gui/component.go b/internal/gui/component.go index 90c403e..bb1e13e 100644 --- a/internal/gui/component.go +++ b/internal/gui/component.go @@ -28,7 +28,13 @@ func itemList(data binding.DataList, icon *fyne.StaticResource, entity string) * return widget.NewListWithData(data, // Create item func() fyne.CanvasObject { - return container.NewHBox(widget.NewIcon(icon), widget.NewLabel(""), layout.NewSpacer(), container.NewGridWithColumns(1, widget.NewButtonWithIcon("", images.Edit, func() {}))) + return container.NewHBox( + widget.NewIcon(icon), + widget.NewLabel(""), + layout.NewSpacer(), + container.NewGridWithColumns(2, + widget.NewButtonWithIcon("", images.Edit, func() {}), + widget.NewButtonWithIcon("", images.Delete, func() {}))) }, // Update item func(di binding.DataItem, item fyne.CanvasObject) { @@ -37,7 +43,6 @@ func itemList(data binding.DataList, icon *fyne.StaticResource, entity string) * // edit button editBtn := item.(*fyne.Container).Objects[3].(*fyne.Container).Objects[0].(*widget.Button) - editBtn.OnTapped = func() { if entity == cons.BucketEntity { editBucketHandler(v) @@ -45,6 +50,16 @@ func itemList(data binding.DataList, icon *fyne.StaticResource, entity string) * editKeyHandler(v) } } + + // delete button + deleteBtn := item.(*fyne.Container).Objects[3].(*fyne.Container).Objects[1].(*widget.Button) + deleteBtn.OnTapped = func() { + if entity == cons.BucketEntity { + deleteBucketHandler(v) + } else { + deleteKeyHandler(v) + } + } }) } diff --git a/internal/gui/handler.go b/internal/gui/handler.go index 81cb921..7f504ac 100644 --- a/internal/gui/handler.go +++ b/internal/gui/handler.go @@ -182,8 +182,6 @@ func deleteBucketHandler(item string) { f, _ := filename.Get() if f == "" { dialog.NewInformation(cons.BucketDelete, cons.ErrNoDb, mw).Show() - } else if item == "" { - dialog.NewInformation(cons.BucketDelete, cons.ErrNoBucket, mw).Show() } else { dialog.NewConfirm(cons.BucketDelete, fmt.Sprintf("Delete %v?", item), func(b bool) { var err error @@ -210,8 +208,6 @@ func deleteKeyHandler(item string) { f, _ := filename.Get() if f == "" { dialog.NewInformation(cons.KeyDelete, cons.ErrNoDb, mw).Show() - } else if item == "" { - dialog.NewInformation(cons.KeyDelete, cons.ErrNoKey, mw).Show() } else { dialog.NewConfirm(cons.KeyDelete, fmt.Sprintf("Delete %v?", item), func(b bool) { var err error diff --git a/internal/gui/state.go b/internal/gui/state.go index ff06128..4ba0e35 100644 --- a/internal/gui/state.go +++ b/internal/gui/state.go @@ -14,7 +14,6 @@ var ( mw fyne.Window db *core.Database selBucket string - selKey string filename binding.String buckets binding.StringList keys binding.StringList diff --git a/internal/gui/view.go b/internal/gui/view.go index 0e1e710..637032c 100644 --- a/internal/gui/view.go +++ b/internal/gui/view.go @@ -53,8 +53,6 @@ func opsBoxTopView() []fyne.CanvasObject { openDbHandler() }), opsButton(cons.Add, images.Add, func() { addHandler() }), - opsButton(cons.BucketDelete, images.Delete, func() { deleteBucketHandler(selBucket) }), - opsButton(cons.KeyDelete, images.Delete, func() { deleteKeyHandler(selKey) }), } }