From aeb76e9c57805a34942929d527109bd32822e485 Mon Sep 17 00:00:00 2001 From: Sean Smith Date: Thu, 23 May 2019 20:41:14 -0400 Subject: [PATCH 1/6] Flip weather over to a multi-source widget --- modules/weatherservices/weather/keyboard.go | 9 +++--- modules/weatherservices/weather/widget.go | 35 +++++---------------- 2 files changed, 13 insertions(+), 31 deletions(-) diff --git a/modules/weatherservices/weather/keyboard.go b/modules/weatherservices/weather/keyboard.go index 76f2a555..197e36be 100644 --- a/modules/weatherservices/weather/keyboard.go +++ b/modules/weatherservices/weather/keyboard.go @@ -4,9 +4,10 @@ import "github.com/gdamore/tcell" func (widget *Widget) initializeKeyboardControls() { widget.SetKeyboardChar("/", widget.ShowHelp, "Show/hide this help prompt") - widget.SetKeyboardChar("h", widget.Prev, "Select previous item") - widget.SetKeyboardChar("l", widget.Next, "Select next item") + widget.SetKeyboardChar("r", widget.Refresh, "Refresh Widget") + widget.SetKeyboardChar("h", widget.PrevSource, "Select previous city") + widget.SetKeyboardChar("l", widget.NextSource, "Select next city") - widget.SetKeyboardKey(tcell.KeyLeft, widget.Prev, "Select previous item") - widget.SetKeyboardKey(tcell.KeyRight, widget.Next, "Select next item") + widget.SetKeyboardKey(tcell.KeyLeft, widget.PrevSource, "Select previous city") + widget.SetKeyboardKey(tcell.KeyRight, widget.NextSource, "Select next city") } diff --git a/modules/weatherservices/weather/widget.go b/modules/weatherservices/weather/widget.go index a19ad738..4f4ba669 100644 --- a/modules/weatherservices/weather/widget.go +++ b/modules/weatherservices/weather/widget.go @@ -9,29 +9,32 @@ import ( // Widget is the container for weather data. type Widget struct { wtf.KeyboardWidget + wtf.MultiSourceWidget wtf.TextWidget // APIKey string Data []*owm.CurrentWeatherData - Idx int + pages *tview.Pages settings *Settings } // NewWidget creates and returns a new instance of the weather 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), - - Idx: 0, + KeyboardWidget: wtf.NewKeyboardWidget(app, pages, settings.common), + MultiSourceWidget: wtf.NewMultiSourceWidget(settings.common, "cityid", "cityids"), + TextWidget: wtf.NewTextWidget(app, settings.common, true), + pages: pages, settings: settings, } widget.initializeKeyboardControls() widget.View.SetInputCapture(widget.InputCapture) + widget.SetDisplayFunction(widget.display) + widget.KeyboardWidget.SetView(widget.View) return &widget @@ -65,28 +68,6 @@ func (widget *Widget) Refresh() { widget.display() } -// Next displays data for the next city data in the list. If the current city is the last -// city, it wraps to the first city. -func (widget *Widget) Next() { - widget.Idx++ - if widget.Idx == len(widget.Data) { - widget.Idx = 0 - } - - widget.display() -} - -// Prev displays data for the previous city in the list. If the previous city is the first -// city, it wraps to the last city. -func (widget *Widget) Prev() { - widget.Idx-- - if widget.Idx < 0 { - widget.Idx = len(widget.Data) - 1 - } - - widget.display() -} - func (widget *Widget) HelpText() string { return widget.KeyboardWidget.HelpText() } From a283dd8ed847c14c24bfce5247bfe2a83e8911d1 Mon Sep 17 00:00:00 2001 From: Sean Smith Date: Thu, 23 May 2019 20:45:01 -0400 Subject: [PATCH 2/6] Migrate gitlab to multisource widget --- modules/gitlab/keyboard.go | 8 ++++---- modules/gitlab/widget.go | 28 +++++----------------------- 2 files changed, 9 insertions(+), 27 deletions(-) diff --git a/modules/gitlab/keyboard.go b/modules/gitlab/keyboard.go index 3891d565..5d3791d7 100644 --- a/modules/gitlab/keyboard.go +++ b/modules/gitlab/keyboard.go @@ -5,9 +5,9 @@ import "github.com/gdamore/tcell" func (widget *Widget) initializeKeyboardControls() { widget.SetKeyboardChar("/", widget.ShowHelp, "Show/hide this help prompt") widget.SetKeyboardChar("r", widget.Refresh, "Refresh widget") - widget.SetKeyboardChar("h", widget.Prev, "Select previous item") - widget.SetKeyboardChar("l", widget.Next, "Select next item") + widget.SetKeyboardChar("h", widget.PrevSource, "Select previous project") + widget.SetKeyboardChar("l", widget.NextSource, "Select next project") - widget.SetKeyboardKey(tcell.KeyLeft, widget.Prev, "Select previous item") - widget.SetKeyboardKey(tcell.KeyRight, widget.Next, "Select next item") + widget.SetKeyboardKey(tcell.KeyLeft, widget.PrevSource, "Select previous project") + widget.SetKeyboardKey(tcell.KeyRight, widget.NextSource, "Select next project") } diff --git a/modules/gitlab/widget.go b/modules/gitlab/widget.go index adc72557..bad0b118 100644 --- a/modules/gitlab/widget.go +++ b/modules/gitlab/widget.go @@ -8,10 +8,10 @@ import ( type Widget struct { wtf.KeyboardWidget + wtf.MultiSourceWidget wtf.TextWidget GitlabProjects []*GitlabProject - Idx int gitlab *glb.Client settings *Settings @@ -26,10 +26,9 @@ 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), - - Idx: 0, + KeyboardWidget: wtf.NewKeyboardWidget(app, pages, settings.common), + MultiSourceWidget: wtf.NewMultiSourceWidget(settings.common, "repository", "repositories"), + TextWidget: wtf.NewTextWidget(app, settings.common, true), gitlab: gitlab, settings: settings, @@ -39,6 +38,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) @@ -55,24 +55,6 @@ func (widget *Widget) Refresh() { widget.display() } -func (widget *Widget) Next() { - widget.Idx++ - if widget.Idx == len(widget.GitlabProjects) { - widget.Idx = 0 - } - - widget.display() -} - -func (widget *Widget) Prev() { - widget.Idx-- - if widget.Idx < 0 { - widget.Idx = len(widget.GitlabProjects) - 1 - } - - widget.display() -} - func (widget *Widget) HelpText() string { return widget.KeyboardWidget.HelpText() } From 09ea4cd874a6004b607bb9f267f1f4226b5a7772 Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Fri, 24 May 2019 14:26:03 -0700 Subject: [PATCH 3/6] Todoist now properly updates list items when Refresh() is called --- modules/todoist/widget.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/modules/todoist/widget.go b/modules/todoist/widget.go index 2a4ca8a1..1b1039c1 100644 --- a/modules/todoist/widget.go +++ b/modules/todoist/widget.go @@ -53,14 +53,16 @@ func (widget *Widget) ProjectAt(idx int) *Project { return widget.projects[idx] } -func (w *Widget) Refresh() { - if w.Disabled() || w.CurrentProject() == nil { - w.SetItemCount(0) +func (widget *Widget) Refresh() { + widget.loadProjects() + + if widget.Disabled() || widget.CurrentProject() == nil { + widget.SetItemCount(0) return } - w.SetItemCount(len(w.CurrentProject().tasks)) - w.display() + widget.SetItemCount(len(widget.CurrentProject().tasks)) + widget.display() } func (widget *Widget) HelpText() string { From dd4d85e3372871ab0a00fc518478141a4e7dce83 Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Fri, 24 May 2019 14:26:38 -0700 Subject: [PATCH 4/6] Update CHANGELOG.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 65b698c6..a7fa884f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +### 🐞 Fixed + +* Todoist now properly updates list items when Refresh is called + ## v0.10.3 * Invalid glog dependency removed, by [@bosr](https://github.com/bosr) From b9fc08e0983ca33f4f3fc7ab76c354272e312269 Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Fri, 24 May 2019 14:27:29 -0700 Subject: [PATCH 5/6] Todoist only refreshes if it is not disabled and there is a current project --- modules/todoist/widget.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/todoist/widget.go b/modules/todoist/widget.go index 1b1039c1..9778eac7 100644 --- a/modules/todoist/widget.go +++ b/modules/todoist/widget.go @@ -54,13 +54,13 @@ func (widget *Widget) ProjectAt(idx int) *Project { } func (widget *Widget) Refresh() { - widget.loadProjects() - if widget.Disabled() || widget.CurrentProject() == nil { widget.SetItemCount(0) return } + widget.loadProjects() + widget.SetItemCount(len(widget.CurrentProject().tasks)) widget.display() } From f183a854c8cdc43ed4beed61b49ed7d1f36048f4 Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Fri, 24 May 2019 16:56:44 -0700 Subject: [PATCH 6/6] Improve keyboard handling in main.go --- main.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 7145d73b..f45f5706 100644 --- a/main.go +++ b/main.go @@ -40,22 +40,29 @@ func disableAllWidgets(widgets []wtf.Wtfable) { } func keyboardIntercept(event *tcell.EventKey) *tcell.EventKey { + // These keys are global keys used by the app. Widgets should not implement these keys switch event.Key() { case tcell.KeyCtrlR: refreshAllWidgets(runningWidgets) + return nil case tcell.KeyTab: focusTracker.Next() + return nil case tcell.KeyBacktab: focusTracker.Prev() + return nil case tcell.KeyEsc: focusTracker.None() + return nil } + // This function checks to see if any widget has been assigned the pressed key as its + // focus key if focusTracker.FocusOn(string(event.Rune())) { return nil } - // If no specific widget has focus, then allow key presses to fall through to the app + // If no specific widget has focus, then allow the key presses to fall through to the app if !focusTracker.IsFocused { switch string(event.Rune()) { case "/":