Add attachment replace workflow UI
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"image"
|
||||
"image/color"
|
||||
"os"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"gioui.org/app"
|
||||
@@ -34,6 +35,8 @@ const (
|
||||
desktopSubtitle = "KeePass-compatible password management for desktop-first workflows"
|
||||
)
|
||||
|
||||
const maxAttachmentBytes = 10 << 20
|
||||
|
||||
type bannerKind string
|
||||
|
||||
const (
|
||||
@@ -54,6 +57,11 @@ type uiSurface struct {
|
||||
Locked bool
|
||||
}
|
||||
|
||||
type attachmentItem struct {
|
||||
Name string
|
||||
Size int
|
||||
}
|
||||
|
||||
type ui struct {
|
||||
mode string
|
||||
theme *material.Theme
|
||||
@@ -103,6 +111,7 @@ type ui struct {
|
||||
deleteTemplate widget.Clickable
|
||||
instantiateTemplate widget.Clickable
|
||||
addAttachment widget.Clickable
|
||||
replaceAttachment widget.Clickable
|
||||
removeAttachment widget.Clickable
|
||||
exportAttachment widget.Clickable
|
||||
restoreHistory widget.Clickable
|
||||
@@ -119,6 +128,7 @@ type ui struct {
|
||||
masterKeyComposite widget.Clickable
|
||||
entryClicks []widget.Clickable
|
||||
historyClicks []widget.Clickable
|
||||
attachmentClicks []widget.Clickable
|
||||
breadcrumbs []widget.Clickable
|
||||
groupClicks []widget.Clickable
|
||||
state appstate.State
|
||||
@@ -234,6 +244,41 @@ func (u *ui) filter() {
|
||||
}
|
||||
}
|
||||
|
||||
func (u *ui) selectedAttachmentItems() []attachmentItem {
|
||||
item, ok := u.selectedEntry()
|
||||
if !ok || len(item.Attachments) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
items := make([]attachmentItem, 0, len(item.Attachments))
|
||||
for name, content := range item.Attachments {
|
||||
items = append(items, attachmentItem{Name: name, Size: len(content)})
|
||||
}
|
||||
slices.SortFunc(items, func(a, b attachmentItem) int {
|
||||
switch {
|
||||
case a.Name < b.Name:
|
||||
return -1
|
||||
case a.Name > b.Name:
|
||||
return 1
|
||||
default:
|
||||
return 0
|
||||
}
|
||||
})
|
||||
if len(u.attachmentClicks) < len(items) {
|
||||
u.attachmentClicks = make([]widget.Clickable, len(items))
|
||||
}
|
||||
return items
|
||||
}
|
||||
|
||||
func (u *ui) selectedAttachmentNames() []string {
|
||||
items := u.selectedAttachmentItems()
|
||||
names := make([]string, 0, len(items))
|
||||
for _, item := range items {
|
||||
names = append(names, item.Name)
|
||||
}
|
||||
return names
|
||||
}
|
||||
|
||||
func (u *ui) showEntriesSection() {
|
||||
u.state.Section = appstate.SectionEntries
|
||||
u.state.NavigateToPath(nil)
|
||||
@@ -627,6 +672,9 @@ func (u *ui) layout(gtx layout.Context) layout.Dimensions {
|
||||
for u.addAttachment.Clicked(gtx) {
|
||||
u.runAction("add attachment", u.addAttachmentAction)
|
||||
}
|
||||
for u.replaceAttachment.Clicked(gtx) {
|
||||
u.runAction("replace attachment", u.replaceAttachmentAction)
|
||||
}
|
||||
for u.removeAttachment.Clicked(gtx) {
|
||||
u.runAction("remove attachment", u.removeAttachmentAction)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user