Skip to content

Commit

Permalink
re-design delete bucket/key ui
Browse files Browse the repository at this point in the history
  • Loading branch information
songlim327 committed Aug 15, 2023
1 parent b0d902f commit 896a7a5
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 12 deletions.
4 changes: 1 addition & 3 deletions internal/cons/error.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package cons

const (
ErrNoDb = "No database opened"
ErrNoBucket = "No bucket selected"
ErrNoKey = "No key selected"
ErrNoDb = "No database opened"
)
19 changes: 17 additions & 2 deletions internal/gui/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -37,14 +43,23 @@ 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)
} else {
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)
}
}
})
}

Expand Down
4 changes: 0 additions & 4 deletions internal/gui/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion internal/gui/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ var (
mw fyne.Window
db *core.Database
selBucket string
selKey string
filename binding.String
buckets binding.StringList
keys binding.StringList
Expand Down
2 changes: 0 additions & 2 deletions internal/gui/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) }),
}
}

Expand Down

0 comments on commit 896a7a5

Please sign in to comment.