diff options
author | RandomChars <random@chars.jp> | 2021-10-09 16:06:40 +0900 |
---|---|---|
committer | RandomChars <random@chars.jp> | 2021-10-09 16:06:40 +0900 |
commit | 07903e234b39f8dac522fed15d54956086538795 (patch) | |
tree | 66df9007fc1a37ce0dbc1595c3c3770b755efac7 | |
parent | 6e2def8f8fc1c5d7f77c2bbb1d06a49b6891304b (diff) |
better return func that sets page when in page view, fix hardcoded set of store.PageSize pages returning from tag search dialog (do not write code when drunk!!!), implement substring search in tag search dialog
-rw-r--r-- | image.go | 8 | ||||
-rw-r--r-- | tag.go | 53 |
2 files changed, 51 insertions, 10 deletions
@@ -793,3 +793,11 @@ func addImage(path string, reader io.ReadCloser) { go setImage(img) } } + +func makeReturnFunc() func() { + if inPageView { + return func() { setPage(currentPage) } + } + o := window.Content() + return func() { window.SetContent(o) } +} @@ -24,18 +24,19 @@ func init() { entry = widget.NewEntry() ) entry.PlaceHolder = "Enter tags here" + doSearch := func(s string) { + if entry.Text == "" { + return + } + tagSearch(strings.Split(s, " "), makeReturnFunc()) + } submit = widget.NewButton("Search", func() { submit.Disable() defer submit.Enable() - if entry.Text == "" { - return - } - o := window.Content() - tagSearch(strings.Split(entry.Text, " "), func() { - window.SetContent(o) - }) + doSearch(entry.Text) }) + entry.OnSubmitted = doSearch return container.NewBorder(nil, nil, nil, submit, entry, submit) }() } @@ -50,7 +51,7 @@ var tagMenu = &fyne.MenuItem{ go func() { t := tagSelectDialog(nil, true) if t != nil { - tagSearch(t, func() { setPage(store.PageSize) }) + tagSearch(t, makeReturnFunc()) } }() }, @@ -251,10 +252,42 @@ func tagSelectDialog(selected []string, diag bool) []string { return b } - c := container.NewHSplit( + sr := widget.NewEntry() + sr.OnChanged = func(s string) { + if s == "" { + r.UnselectAll() + l.UnselectAll() + return + } + + sel := false + for i, tag := range deselected { + if strings.Contains(tag, s) { + r.Select(i) + sel = true + break + } + } + if !sel { + r.UnselectAll() + } + + sel = false + for i, tag := range selected { + if strings.Contains(tag, s) { + l.Select(i) + break + } + } + if !sel { + l.UnselectAll() + } + } + + c := container.NewBorder(sr, nil, nil, nil, container.NewHSplit( container.NewBorder(widget.NewLabel("Selected"), nil, nil, nil, l), container.NewBorder(widget.NewLabel("Available"), nil, nil, nil, r), - ) + )) s := make(chan bool) cb := func(submit bool) { s <- submit |