Updated TimerList struct

This commit is contained in:
2023-01-12 06:04:17 -06:00
parent c98a4dea0c
commit c412f54294
10 changed files with 260 additions and 27 deletions

View File

@@ -21,13 +21,19 @@ type listTimersScreen struct {
cursor int
fullList *timertxt.TimerList
timerList *timertxt.TimerList
doneList *timertxt.TimerList
timerFilterList *timertxt.TimerList
doneFilterList *timertxt.TimerList
filter string
selected map[int]bool
inputDialog *widdles.InputDialog
filter string
partManager *PartManager
msg string
err error
@@ -38,9 +44,12 @@ type ListTimersMsg ScreenMsg
func NewListTimersScreen(u *Ui) *listTimersScreen {
w, h := termbox.Size()
s := listTimersScreen{
ui: u,
menu: widdles.NewTopMenu(0, 0, 0),
scrollbar: widdles.NewScrollbar(w-2, 2, 1, h-2),
ui: u,
menu: widdles.NewTopMenu(0, 0, 0),
scrollbar: widdles.NewScrollbar(w-2, 2, 1, h-2),
selected: make(map[int]bool),
inputDialog: widdles.NewInputDialog("", ""),
partManager: NewPartManager("", 0, 0, 0, 0),
}
return &s
}
@@ -62,9 +71,17 @@ func (s *listTimersScreen) Init() wandle.Cmd {
s.menu.Measure()
// Timer Lists
s.timerList, s.doneList = s.ui.program.TimerList, s.ui.program.DoneList
s.fullList = timertxt.NewTimerList()
s.fullList.AddTimers(s.timerList.GetTimerSlice())
s.fullList.AddTimers(s.doneList.GetTimerSlice())
s.timerFilterList, s.doneFilterList = s.timerList, s.doneList
s.timerFilterList.Sort(timertxt.SORT_START_DATE_DESC)
s.doneFilterList.Sort(timertxt.SORT_START_DATE_DESC)
w, h := termbox.Size()
s.partManager.SetX(w / 4)
s.partManager.SetY(h / 4)
s.partManager.SetWidth(w / 2)
s.partManager.SetHeight(h / 2)
return nil
}
@@ -80,9 +97,6 @@ func (s *listTimersScreen) Update(msg wandle.Msg) wandle.Cmd {
func (s *listTimersScreen) View(style wandle.Style) {
_, h := termbox.Size()
if s.menu.IsActive() {
s.menu.View(style)
}
y := 2
wandle.Print(1, y, style.Bold(true), "Active Timers")
y++
@@ -94,7 +108,11 @@ func (s *listTimersScreen) View(style wandle.Style) {
if s.cursor == idx {
st = st.Invert()
}
wandle.Print(1, y, st, "[ ]")
if s.selected[idx] {
wandle.Print(1, y, st, "[✔] ")
} else {
wandle.Print(1, y, st, "[ ] ")
}
s.ViewTimer(5, y, st, tmr)
y++
}
@@ -102,19 +120,31 @@ func (s *listTimersScreen) View(style wandle.Style) {
wandle.Print(1, y, style.Bold(true), "Done Timers")
y++
for idx, tmr := range s.doneFilterList.GetTimerSlice() {
if y > h-2 {
if y > h-3 {
break
}
st := style
if s.cursor == s.timerFilterList.Size()+idx {
st = st.Invert()
}
wandle.Print(1, y, st, "[ ]")
if s.selected[s.timerFilterList.Size()+idx] {
wandle.Print(1, y, st, "[✔] ")
} else {
wandle.Print(1, y, st, "[ ] ")
}
s.ViewTimer(5, y, st, tmr)
y++
}
wandle.Print(1, h-1, style, "[p]roject(+), [c]ontext(@), [t]ags(:)")
if len(s.selected) > 0 {
wandle.Print(39, h-1, style, fmt.Sprintf("(%d selected)", len(s.selected)))
}
s.scrollbar.View(style)
if s.menu.IsActive() {
s.menu.View(style)
}
s.partManager.View(style)
}
func (s *listTimersScreen) ViewTimer(x, y int, style wandle.Style, tmr *timertxt.Timer) {
@@ -127,18 +157,38 @@ func (s *listTimersScreen) ViewTimer(x, y int, style wandle.Style, tmr *timertxt
}
func (s *listTimersScreen) handleTermboxEvent(msg termbox.Event) wandle.Cmd {
if pmRes := s.partManager.Update(msg); pmRes != nil {
return pmRes
}
if (msg.Type == termbox.EventKey && msg.Key == termbox.KeyEsc) || s.menu.IsActive() {
return s.menu.Update(msg)
}
switch msg.Type {
case termbox.EventKey:
top := s.timerFilterList.Size() + s.doneFilterList.Size() - 2
selected := len(s.selected)
var selTimer *timertxt.Timer
if selected == 0 {
if s.cursor < s.timerFilterList.Size() {
selTimer, s.err = s.timerFilterList.GetTimer(s.cursor)
} else {
selTimer, s.err = s.doneFilterList.GetTimer(s.cursor)
}
}
if msg.Key == termbox.KeyEnter {
// Edit the entry
/*
if s.cursor >= 0 && s.cursor < s.timerFilterList.Size()+s.doneFilterList.Size() {
} else {
}
*/
} else if msg.Key == termbox.KeySpace {
// (un)Select the entry
if v := s.selected[s.cursor]; v {
delete(s.selected, s.cursor)
} else {
s.selected[s.cursor] = true
}
} else if msg.Key == termbox.KeyArrowUp || msg.Ch == 'k' {
if s.cursor > 0 {
s.cursor--
@@ -155,6 +205,44 @@ func (s *listTimersScreen) handleTermboxEvent(msg termbox.Event) wandle.Cmd {
return nil
} else if msg.Ch == 'G' {
s.cursor = top
} else if msg.Ch == 't' {
// Edit tag(s)
tags := s.fullList.GetTagKeys()
s.partManager.SetOptions(tags)
if selected > 0 {
// TODO
//s.partManager.SetLabel(fmt.Sprintf("Manage Tags on %d Timers", selected))
} else {
s.partManager.SetLabel("Manage Tags for Timer")
s.partManager.SetType("Tag")
}
s.partManager.Show()
} else if msg.Ch == 'p' {
// Edit project(s)
projs := s.fullList.GetProjects()
s.partManager.SetOptions(projs)
if selected > 0 {
// TODO
//s.partManager.SetLabel(fmt.Sprintf("Manage Projects on %d Timers", selected))
} else {
s.partManager.SetLabel("Manage Projects for Timer")
s.partManager.SetType("Project")
s.partManager.SetValue(strings.Join(selTimer.Projects, " "))
}
s.partManager.Show()
} else if msg.Ch == 'c' {
// Edit context(s)
ctxts := s.fullList.GetContexts()
s.partManager.SetOptions(ctxts)
if selected > 0 {
// TODO
//s.partManager.SetLabel(fmt.Sprintf("Manage Contexts on %d Timers", selected))
} else {
s.partManager.SetLabel("Manage Contexts for Timer")
s.partManager.SetType("Context")
s.partManager.SetValue(strings.Join(selTimer.Contexts, " "))
}
s.partManager.Show()
}
}
return nil