1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

Flip todoist over to multiview widget

This can also probably be made scrollable in the future as well
This commit is contained in:
Sean Smith 2019-05-12 23:15:48 -04:00
parent cbb147f41e
commit 6a41935e61
4 changed files with 12 additions and 28 deletions

View File

@ -19,7 +19,7 @@ func (widget *Widget) display() {
title := fmt.Sprintf("[green]%s[white]", proj.Project.Name)
_, _, width, _ := widget.View.GetRect()
str := widget.settings.common.SigilStr(len(widget.projects), widget.idx, width) + "\n"
str := widget.settings.common.SigilStr(len(widget.projects), widget.Idx, width) + "\n"
maxLen := proj.LongestLine()

View File

@ -6,14 +6,14 @@ func (widget *Widget) initializeKeyboardControls() {
widget.SetKeyboardChar("/", widget.ShowHelp, "Show/hide this help prompt")
widget.SetKeyboardChar("c", widget.Close, "Close item")
widget.SetKeyboardChar("d", widget.Delete, "Delete item")
widget.SetKeyboardChar("h", widget.PreviousProject, "Select previous project")
widget.SetKeyboardChar("h", widget.Prev, "Select previous project")
widget.SetKeyboardChar("j", widget.Up, "Select previous item")
widget.SetKeyboardChar("k", widget.Down, "Select next item")
widget.SetKeyboardChar("l", widget.NextProject, "Select next project")
widget.SetKeyboardChar("l", widget.Next, "Select next project")
widget.SetKeyboardChar("r", widget.Refresh, "Refresh widget")
widget.SetKeyboardKey(tcell.KeyDown, widget.Down, "Select next item")
widget.SetKeyboardKey(tcell.KeyLeft, widget.PreviousProject, "Select previous project")
widget.SetKeyboardKey(tcell.KeyRight, widget.NextProject, "Select next project")
widget.SetKeyboardKey(tcell.KeyLeft, widget.Prev, "Select previous project")
widget.SetKeyboardKey(tcell.KeyRight, widget.Next, "Select next project")
widget.SetKeyboardKey(tcell.KeyUp, widget.Up, "Select previous item")
}

View File

@ -11,8 +11,8 @@ import (
type Widget struct {
wtf.KeyboardWidget
wtf.TextWidget
wtf.MultiSourceWidget
idx int
projects []*Project
settings *Settings
}
@ -22,6 +22,7 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
widget := Widget{
KeyboardWidget: wtf.NewKeyboardWidget(app, pages, settings.common),
TextWidget: wtf.NewTextWidget(app, settings.common, true),
MultiSourceWidget: wtf.NewMultiSourceWidget(settings.common, "project", "projects"),
settings: settings,
}
@ -31,6 +32,7 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
widget.initializeKeyboardControls()
widget.View.SetInputCapture(widget.InputCapture)
widget.SetDisplayFunction(widget.display)
widget.KeyboardWidget.SetView(widget.View)
@ -40,7 +42,7 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
/* -------------------- Exported Functions -------------------- */
func (widget *Widget) CurrentProject() *Project {
return widget.ProjectAt(widget.idx)
return widget.ProjectAt(widget.Idx)
}
func (widget *Widget) ProjectAt(idx int) *Project {
@ -51,24 +53,6 @@ func (widget *Widget) ProjectAt(idx int) *Project {
return widget.projects[idx]
}
func (w *Widget) NextProject() {
w.idx = w.idx + 1
if w.idx == len(w.projects) {
w.idx = 0
}
w.display()
}
func (w *Widget) PreviousProject() {
w.idx = w.idx - 1
if w.idx < 0 {
w.idx = len(w.projects) - 1
}
w.display()
}
func (w *Widget) Refresh() {
if w.Disabled() || w.CurrentProject() == nil {
return

View File

@ -149,7 +149,7 @@ func ToStrs(slice []interface{}) []string {
results := []string{}
for _, val := range slice {
results = append(results, val.(string))
results = append(results, fmt.Sprintf("%v", val))
}
return results