Advanced Priority Sorting (If none, but above 'Z')

This commit is contained in:
Brian Buller 2019-04-24 07:20:41 -05:00
parent 05e41675b1
commit a925eec330
2 changed files with 40 additions and 2 deletions

View File

@ -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)
}

View File

@ -116,8 +116,7 @@ func (screen *MainScreen) reloadList(bundle termboxScreen.Bundle) error {
(*screen.displayList) = append(*screen.displayList, av)
}
}
screen.displayList.Sort(todotxt.SORT_CREATED_DATE_DESC)
screen.displayList.Sort(todotxt.SORT_PRIORITY_ASC)
By(app.AdvancedPrioritySort).Sort(*screen.displayList)
case MainBundleListDone:
if err := app.LoadDoneList(); err != nil {
return err