Skip to content

Commit

Permalink
feat: generate tags dialog
Browse files Browse the repository at this point in the history
Signed-off-by: Rachel Powers <[email protected]>
  • Loading branch information
Ryex committed Sep 30, 2024
1 parent a683150 commit aa162a2
Show file tree
Hide file tree
Showing 9 changed files with 652 additions and 30 deletions.
40 changes: 26 additions & 14 deletions internal/gui/bindings/bindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"

"fyne.io/fyne/v2/data/binding"
log "github.com/sirupsen/logrus"
)

type proxyBinding[B binding.DataItem] struct {
Expand Down Expand Up @@ -76,6 +77,7 @@ func Listen[T any](data Bound[T], f func(T)) binding.DataListener {
listener := binding.NewDataListener(func() {
val, err := data.Get()
if err != nil {
log.Errorf("listen bind get error %s", err.Error())
return
}
f(val)
Expand All @@ -84,6 +86,14 @@ func Listen[T any](data Bound[T], f func(T)) binding.DataListener {
return listener
}

func AddListenerToAll(f func(), items ...binding.DataItem) {

listener := binding.NewDataListener(f)
for _, item := range items {
item.AddListener(listener)
}
}

func ListenErr[T any](data Bound[T], f func(T), e func(error)) binding.DataListener {
listener := binding.NewDataListener(func() {
val, err := data.Get()
Expand All @@ -99,8 +109,8 @@ func ListenErr[T any](data Bound[T], f func(T), e func(error)) binding.DataListe

type boundMapping[F any, T any] struct {
proxyBinding[Bound[F]]
f func(F) (T, error)
r func(T) (F, error)
get func(F) (T, error)
set func(T) (F, error)
}

func NewMapping[F any, T any](
Expand All @@ -109,35 +119,37 @@ func NewMapping[F any, T any](
) Bound[T] {
return &boundMapping[F, T]{
proxyBinding: proxyBinding[Bound[F]]{from: from},
f: f,
get: f,
}
}

func NewReversableMapping[F any, T any](
from Bound[F],
f func(F) (T, error),
r func(T) (F, error),
get func(F) (T, error),
set func(T) (F, error),
) Bound[T] {
return &boundMapping[F, T]{
proxyBinding: proxyBinding[Bound[F]]{from: from},
f: f,
r: r,
get: get,
set: set,
}
}

func (bm *boundMapping[F, T]) Get() (T, error) {
v, err := bm.from.Get()
if err != nil {
var t T
log.Errorf("mapped bind get err %s", err.Error())
return t, err
}
return bm.f(v)
return bm.get(v)
}

func (bm *boundMapping[F, T]) Set(t T) error {
if bm.r != nil {
rev, err := bm.r(t)
if bm.set != nil {
rev, err := bm.set(t)
if err != nil {
log.Errorf("mapped bind set err %s", err.Error())
return err
}
return bm.from.Set(rev)
Expand All @@ -154,13 +166,13 @@ var errWrongType = errors.New("wrong type provided")

type mappedBinding[T any] struct {
Bound[T]
v T
v T

counter int
self binding.ExternalInt
self binding.ExternalInt

set func(T) error
get func() (T, error)
set func(T) error
get func() (T, error)
}

func MappedBind[T any](get func() (T, error), set func(T) error) ExternalBound[T] {
Expand Down
15 changes: 15 additions & 0 deletions internal/gui/gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"image/color"
"net/url"
"os"
"path/filepath"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -186,6 +187,7 @@ func (a *App) buildMainUI() {
dlg := dialog.NewFileOpen(func(uc fyne.URIReadCloser, err error) {
if err == nil && uc != nil {
log.Infof("open path %s", uc.URI().Path())
a.app.Preferences().SetString("lastPack.path", uc.URI().Path())
a.operatingPath.Set(uc.URI().Path())
}
}, a.window)
Expand All @@ -196,13 +198,20 @@ func (a *App) buildMainUI() {
fyne.Min(a.window.Canvas().Size().Height, 580),
),
)
lastOpen := a.app.Preferences().String("lastPack.path")
lastOpenURI := storage.NewFileURI(filepath.Dir(lastOpen))
lisableLastOpen, err := storage.ListerForURI(lastOpenURI)
if err == nil {
dlg.SetLocation(lisableLastOpen)
}
dlg.Show()
})

folderBtn := widget.NewButtonWithIcon(lang.X("folderBtn.text", "Open folder"), theme.FolderOpenIcon(), func() {
dlg := dialog.NewFolderOpen(func(lu fyne.ListableURI, err error) {
if err == nil && lu != nil {
log.Infof("open path %s", lu.Path())
a.app.Preferences().SetString("lastFolder.path", lu.Path())
a.operatingPath.Set(lu.Path())
}
}, a.window)
Expand All @@ -212,6 +221,12 @@ func (a *App) buildMainUI() {
fyne.Min(a.window.Canvas().Size().Height, 580),
),
)
lastOpen := a.app.Preferences().String("lastFolder.path")
lastOpenURI := storage.NewFileURI(lastOpen)
lisableLastOpen, err := storage.ListerForURI(lastOpenURI)
if err == nil {
dlg.SetLocation(lisableLastOpen)
}
dlg.Show()
})

Expand Down
7 changes: 7 additions & 0 deletions internal/gui/pack.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"fyne.io/fyne/v2/dialog"
"fyne.io/fyne/v2/lang"
"fyne.io/fyne/v2/layout"
"fyne.io/fyne/v2/storage"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"

Expand Down Expand Up @@ -260,6 +261,12 @@ func (a *App) setUnpackedContent(pkg *ddpackage.Package) {
fyne.Min(a.window.Canvas().Size().Height, 580),
),
)
outPath := a.app.Preferences().String("pack.outPath")
outPathURI := storage.NewFileURI(outPath)
lisableOutPath, err := storage.ListerForURI(outPathURI)
if err == nil {
dlg.SetLocation(lisableOutPath)
}
dlg.Show()
})

Expand Down
38 changes: 23 additions & 15 deletions internal/gui/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,25 +55,33 @@ func (a *App) buildPackageTreeAndInfoPane(editable bool) fyne.CanvasObject {
},
)

leftSplit := container.NewPadded(
layouts.NewTopExpandVBox(
layouts.NewBottomExpandVBox(
container.New(
layouts.NewRightExpandHBoxLayout(),
widget.NewLabel(lang.X("tree.label", "Resources")),
filterEntry,
),
container.NewStack(
&canvas.Rectangle{
FillColor: theme.Color(theme.ColorNameInputBackground),
},
container.NewPadded(tree),
),
leftSplit := layouts.NewTopExpandVBox(
layouts.NewBottomExpandVBox(
container.New(
layouts.NewRightExpandHBoxLayout(),
widget.NewLabel(lang.X("tree.label", "Resources")),
filterEntry,
),
container.NewStack(
&canvas.Rectangle{
FillColor: theme.Color(theme.ColorNameInputBackground),
},
container.NewPadded(tree),
),
tagSetsBtn,
),
tagSetsBtn,
)

if editable {
generateTageBtn := widget.NewButton(
lang.X("generateTageBtn.label", "Generate Tags"),
func() {
dlg := a.createTagGenDialog()
dlg.Show()
})
leftSplit.Add(generateTageBtn)
}

defaultPreview := container.NewCenter(
widget.NewLabel(lang.X("preview.defaultText", "Select a resource")),
)
Expand Down
Loading

0 comments on commit aa162a2

Please sign in to comment.