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:
parent
cbb147f41e
commit
6a41935e61
@ -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()
|
||||
|
||||
|
@ -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")
|
||||
}
|
||||
|
@ -11,8 +11,8 @@ import (
|
||||
type Widget struct {
|
||||
wtf.KeyboardWidget
|
||||
wtf.TextWidget
|
||||
wtf.MultiSourceWidget
|
||||
|
||||
idx int
|
||||
projects []*Project
|
||||
settings *Settings
|
||||
}
|
||||
@ -20,8 +20,9 @@ type Widget struct {
|
||||
// NewWidget creates a new instance of a widget
|
||||
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
|
||||
widget := Widget{
|
||||
KeyboardWidget: wtf.NewKeyboardWidget(app, pages, settings.common),
|
||||
TextWidget: wtf.NewTextWidget(app, settings.common, true),
|
||||
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
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user