Advanced Priority Sorting (If none, but above 'Z')
This commit is contained in:
39
model.go
39
model.go
@@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -189,3 +190,41 @@ func (a *AppState) WriteDoneList() error {
|
||||
}
|
||||
return a.DoneList.WriteToFilename(a.getDoneFile())
|
||||
}
|
||||
|
||||
func (a *AppState) AdvancedPrioritySort(t1, t2 *todotxt.Task) bool {
|
||||
if t1.HasPriority() && t2.HasPriority() {
|
||||
return t1.Priority < t2.Priority
|
||||
} else if t1.HasPriority() && !t2.HasPriority() {
|
||||
return t1.Priority <= "Y"
|
||||
} else if !t1.HasPriority() && t2.HasPriority() {
|
||||
return "Y" <= t2.Priority
|
||||
}
|
||||
return t1.HasPriority()
|
||||
}
|
||||
|
||||
type customSort struct {
|
||||
list todotxt.TaskList
|
||||
by func(t1, t2 *todotxt.Task) bool
|
||||
}
|
||||
|
||||
func (c *customSort) Len() int {
|
||||
return len(c.list)
|
||||
}
|
||||
|
||||
func (c *customSort) Swap(l, r int) {
|
||||
c.list[l], c.list[r] = c.list[r], c.list[l]
|
||||
}
|
||||
|
||||
func (c *customSort) Less(l, r int) bool {
|
||||
return c.by(&c.list[l], &c.list[r])
|
||||
}
|
||||
|
||||
type By func(t1, t2 *todotxt.Task) bool
|
||||
|
||||
func (by By) Sort(list []todotxt.Task) {
|
||||
ts := &customSort{
|
||||
list: list,
|
||||
by: by,
|
||||
}
|
||||
sort.Sort(ts)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user