-
Notifications
You must be signed in to change notification settings - Fork 2
/
fuzzy_Searcher.go
61 lines (52 loc) · 1.5 KB
/
fuzzy_Searcher.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package dialogs
import (
"strings"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/dialog"
"fyne.io/fyne/v2/layout"
"fyne.io/fyne/v2/widget"
"github.com/elias-gill/walldo-in-go/fuzzyEngine/matching"
"github.com/elias-gill/walldo-in-go/globals"
"github.com/elias-gill/walldo-in-go/utils"
"github.com/elias-gill/walldo-in-go/wallpaper"
)
// Create a new Fuzzy finder dialog and display it.
func NewFuzzyDialog() {
data := []string{}
// list of results
resultsWidget := widget.NewList(
func() int {
return len(data)
},
func() fyne.CanvasObject {
return widget.NewLabel("template")
},
func(id widget.ListItemID, canvas fyne.CanvasObject) {
canvas.(*widget.Label).SetText(data[id])
})
resultsWidget.OnSelected = func(id int) {
wallpaper.SetFromFile(strings.Clone(data[id]))
}
// search input
searchInput := widget.NewEntry()
searchInput.SetPlaceHolder("Search Image")
searchInput.OnChanged =
func(entry string) {
imagesList := utils.GetImagesList()
data = []string{}
if len(entry) >= 1 {
// search for the matching results
matches := matching.FindAll(entry, imagesList)
// display the results
for i := 0; i < len(matches); i++ {
data = append(data, imagesList[matches[i].Idx])
}
}
resultsWidget.Refresh()
}
cont := container.New(layout.NewBorderLayout(searchInput, nil, nil, nil), searchInput, resultsWidget)
dial := dialog.NewCustom("Fuzzy search", "Cancel", cont, globals.Window)
dial.Resize(fyne.NewSize(500, 300))
dial.Show()
}