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
var overlayStart time.Time
FilterEd := &widget.Editor{SingleLine: true}
updateBtns := func() {
passBtns = passBtns[:0]
pathnames = pathnames[:0]
mux.Lock()
for _, x := range l {
_, n := path.Split(x.Pathname)
s := strings.Repeat(" /", x.Level)
z := ""
if x.Dir {
z = "/"
dirs := make(map[string]bool) // visited pathnames
var addd, addf func(x passgo.Pass)
addd = func(x passgo.Pass) {
if x.Level < 1 {
return
}
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{
Size: unit.Sp(fontSize),
Label: strings.Join([]string{s, n, z}, ""),
Size: unit.Sp(fontSize),
Label: lbl,
Background: gray,
})
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()
}
@ -378,7 +416,10 @@ func eventLoop() {
start2 := float64(Config.ClearDelay)
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
mux.Lock()
if lst.Dragging() {
@ -435,7 +476,7 @@ func eventLoop() {
mux.Unlock()
return ret
})
ret := flex.Layout(gtx, c1, c2)
ret := flex.Layout(gtx, c1, c2, c3)
x := time.Since(overlayStart).Seconds()
if x >= fade1b && x < start2 && animating {
animOff()
@ -484,6 +525,9 @@ func eventLoop() {
if animating && x > end {
animOff()
}
if len(FilterEd.Events()) > 0 {
updateBtns()
}
return ret
}
@ -836,7 +880,7 @@ func eventLoop() {
}
switch e := e.(type) {
case system.DestroyEvent:
return
os.Exit(0)
case system.StageEvent:
if e.Stage == system.StageRunning {
go func() {