Add filter to password list view.

This commit is contained in:
Greg 2020-09-08 13:14:09 -04:00
parent ec0b64f5f5
commit db1c958073

View File

@ -242,24 +242,62 @@ func eventLoop() {
overlay := copied overlay := copied
var overlayStart time.Time var overlayStart time.Time
FilterEd := &widget.Editor{SingleLine: true}
updateBtns := func() { updateBtns := func() {
passBtns = passBtns[:0] passBtns = passBtns[:0]
pathnames = pathnames[:0] pathnames = pathnames[:0]
mux.Lock() dirs := make(map[string]bool) // visited pathnames
for _, x := range l {
_, n := path.Split(x.Pathname) var addd, addf func(x passgo.Pass)
s := strings.Repeat(" /", x.Level) addd = func(x passgo.Pass) {
z := "" if x.Level < 1 {
if x.Dir { return
z = "/"
} }
d, n := path.Split(x.Pathname)
x = passgo.Pass{
Pathname: d,
Level: x.Level - 1,
Dir: true,
}
fmt.Printf("addd(): d/n = '%s'/'%s'\n", d,n)
if dirs[d] != true {
addd(x)
}
dirs[x.Pathname] = true
s := strings.Repeat(" /", x.Level)
lbl := strings.Join([]string{s, d}, "")
passBtns = append(passBtns, &Button{ passBtns = append(passBtns, &Button{
Size: unit.Sp(fontSize), Size: unit.Sp(fontSize),
Label: strings.Join([]string{s, n, z}, ""), Label: lbl,
Background: gray, Background: gray,
}) })
pathnames = append(pathnames, x.Pathname) pathnames = append(pathnames, x.Pathname)
} }
flt := strings.ToUpper(FilterEd.Text())
addf = func(x passgo.Pass) {
if !strings.Contains(strings.ToUpper(x.Pathname), flt) {
return
}
d, n := path.Split(x.Pathname)
s := strings.Repeat(" /", x.Level)
lbl := strings.Join([]string{s, n}, "")
if dirs[d] != true {
addd(x)
}
passBtns = append(passBtns, &Button{
Size: unit.Sp(fontSize),
Label: lbl,
Background: gray,
})
pathnames = append(pathnames, x.Pathname)
}
mux.Lock()
for _, x := range l {
if !x.Dir {
addf(x)
}
}
mux.Unlock() mux.Unlock()
} }
@ -378,7 +416,10 @@ func eventLoop() {
start2 := float64(Config.ClearDelay) start2 := float64(Config.ClearDelay)
fade2a, end := start2+1.5, start2+2.0 fade2a, end := start2+1.5, start2+2.0
c2 := layout.Flexed(1.0, func(gtx C) D { c2 := layout.Rigid(func(gtx C) D {
return material.Editor(th, FilterEd, "filter").Layout(gtx)
})
c3 := layout.Flexed(1.0, func(gtx C) D {
var ret D var ret D
mux.Lock() mux.Lock()
if lst.Dragging() { if lst.Dragging() {
@ -435,7 +476,7 @@ func eventLoop() {
mux.Unlock() mux.Unlock()
return ret return ret
}) })
ret := flex.Layout(gtx, c1, c2) ret := flex.Layout(gtx, c1, c2, c3)
x := time.Since(overlayStart).Seconds() x := time.Since(overlayStart).Seconds()
if x >= fade1b && x < start2 && animating { if x >= fade1b && x < start2 && animating {
animOff() animOff()
@ -484,6 +525,9 @@ func eventLoop() {
if animating && x > end { if animating && x > end {
animOff() animOff()
} }
if len(FilterEd.Events()) > 0 {
updateBtns()
}
return ret return ret
} }
@ -836,7 +880,7 @@ func eventLoop() {
} }
switch e := e.(type) { switch e := e.(type) {
case system.DestroyEvent: case system.DestroyEvent:
return os.Exit(0)
case system.StageEvent: case system.StageEvent:
if e.Stage == system.StageRunning { if e.Stage == system.StageRunning {
go func() { go func() {