Skip to content

Commit

Permalink
Merge branch 'Seanstoppable-todoistmulti'
Browse files Browse the repository at this point in the history
  • Loading branch information
senorprogrammer committed May 13, 2019
2 parents 6bdb0ce + f7b69fa commit f62f9a0
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 28 deletions.
2 changes: 1 addition & 1 deletion modules/todoist/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
8 changes: 4 additions & 4 deletions modules/todoist/keyboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
28 changes: 6 additions & 22 deletions modules/todoist/widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,18 @@ import (
type Widget struct {
wtf.KeyboardWidget
wtf.TextWidget
wtf.MultiSourceWidget

idx int
projects []*Project
settings *Settings
}

// 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,
}
Expand All @@ -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)

Expand All @@ -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 {
Expand All @@ -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
Expand Down
8 changes: 7 additions & 1 deletion wtf/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os/exec"
"regexp"
"runtime"
"strconv"
"strings"

"github.com/wtfutil/wtf/utils"
Expand Down Expand Up @@ -149,7 +150,12 @@ func ToStrs(slice []interface{}) []string {
results := []string{}

for _, val := range slice {
results = append(results, val.(string))
switch val.(type) {
case int:
results = append(results, strconv.Itoa(val.(int)))
case string:
results = append(results, val.(string))
}
}

return results
Expand Down

0 comments on commit f62f9a0

Please sign in to comment.