Skip to content

Commit

Permalink
Common help code into HelpfulWidget
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Cummer committed Aug 1, 2018
1 parent 00abe70 commit 9154441
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 173 deletions.
27 changes: 6 additions & 21 deletions gerrit/widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,9 @@ const HelpText = `
`

type Widget struct {
wtf.HelpfulWidget
wtf.TextWidget

app *tview.Application
pages *tview.Pages

gerrit *glb.Client

GerritProjects []*GerritProject
Expand Down Expand Up @@ -74,16 +72,16 @@ func NewWidget(app *tview.Application, pages *tview.Pages) *Widget {
}

widget := Widget{
TextWidget: wtf.NewTextWidget("Gerrit", "gerrit", true),

app: app,
pages: pages,
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
TextWidget: wtf.NewTextWidget("Gerrit", "gerrit", true),

gerrit: gerrit,

Idx: 0,
}

widget.HelpfulWidget.SetView(widget.View)

widget.GerritProjects = widget.buildProjectCollection(wtf.Config.UList("wtf.mods.gerrit.projects"))

widget.View.SetInputCapture(widget.keyboardIntercept)
Expand Down Expand Up @@ -148,7 +146,7 @@ func (widget *Widget) currentGerritProject() *GerritProject {
func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
switch string(event.Rune()) {
case "/":
widget.showHelp()
widget.ShowHelp()
return nil
case "h":
widget.Prev()
Expand All @@ -172,16 +170,3 @@ func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
return event
}
}

func (widget *Widget) showHelp() {
closeFunc := func() {
widget.pages.RemovePage("help")
widget.app.SetFocus(widget.View)
}

modal := wtf.NewBillboardModal(HelpText, closeFunc)

widget.pages.AddPage("help", modal, false, true)
widget.app.SetFocus(modal)
widget.app.Draw()
}
20 changes: 5 additions & 15 deletions git/widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const modalWidth = 80
const modalHeight = 7

type Widget struct {
wtf.HelpfulWidget
wtf.TextWidget

app *tview.Application
Expand All @@ -34,13 +35,15 @@ type Widget struct {

func NewWidget(app *tview.Application, pages *tview.Pages) *Widget {
widget := Widget{
TextWidget: wtf.NewTextWidget("Git", "git", true),
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
TextWidget: wtf.NewTextWidget("Git", "git", true),

app: app,
Idx: 0,
pages: pages,
}

widget.HelpfulWidget.SetView(widget.View)
widget.View.SetInputCapture(widget.keyboardIntercept)

return &widget
Expand Down Expand Up @@ -173,7 +176,7 @@ func (widget *Widget) gitRepos(repoPaths []string) []*GitRepo {
func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
switch string(event.Rune()) {
case "/":
widget.showHelp()
widget.ShowHelp()
return nil
case "h":
widget.Prev()
Expand All @@ -200,16 +203,3 @@ func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
return event
}
}

func (widget *Widget) showHelp() {
closeFunc := func() {
widget.pages.RemovePage("help")
widget.app.SetFocus(widget.View)
}

modal := wtf.NewBillboardModal(HelpText, closeFunc)

widget.pages.AddPage("help", modal, false, true)
widget.app.SetFocus(modal)
widget.app.Draw()
}
27 changes: 6 additions & 21 deletions github/widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,24 @@ const HelpText = `
`

type Widget struct {
wtf.HelpfulWidget
wtf.TextWidget

app *tview.Application
pages *tview.Pages

GithubRepos []*GithubRepo
Idx int
}

func NewWidget(app *tview.Application, pages *tview.Pages) *Widget {
widget := Widget{
TextWidget: wtf.NewTextWidget("GitHub", "github", true),
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
TextWidget: wtf.NewTextWidget("GitHub", "github", true),

app: app,
Idx: 0,
pages: pages,
Idx: 0,
}

widget.GithubRepos = widget.buildRepoCollection(wtf.Config.UMap("wtf.mods.github.repositories"))

widget.HelpfulWidget.SetView(widget.View)
widget.View.SetInputCapture(widget.keyboardIntercept)

return &widget
Expand Down Expand Up @@ -101,7 +99,7 @@ func (widget *Widget) currentGithubRepo() *GithubRepo {
func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
switch string(event.Rune()) {
case "/":
widget.showHelp()
widget.ShowHelp()
return nil
case "h":
widget.Prev()
Expand All @@ -125,16 +123,3 @@ func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
return event
}
}

func (widget *Widget) showHelp() {
closeFunc := func() {
widget.pages.RemovePage("help")
widget.app.SetFocus(widget.View)
}

modal := wtf.NewBillboardModal(HelpText, closeFunc)

widget.pages.AddPage("help", modal, false, true)
widget.app.SetFocus(modal)
widget.app.Draw()
}
26 changes: 5 additions & 21 deletions gitlab/widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@ const HelpText = `
`

type Widget struct {
wtf.HelpfulWidget
wtf.TextWidget

app *tview.Application
pages *tview.Pages

gitlab *glb.Client

GitlabProjects []*GitlabProject
Expand All @@ -47,10 +45,8 @@ func NewWidget(app *tview.Application, pages *tview.Pages) *Widget {
}

widget := Widget{
TextWidget: wtf.NewTextWidget("Gitlab", "gitlab", true),

app: app,
pages: pages,
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
TextWidget: wtf.NewTextWidget("Gitlab", "gitlab", true),

gitlab: gitlab,

Expand All @@ -59,6 +55,7 @@ func NewWidget(app *tview.Application, pages *tview.Pages) *Widget {

widget.GitlabProjects = widget.buildProjectCollection(wtf.Config.UMap("wtf.mods.gitlab.projects"))

widget.HelpfulWidget.SetView(widget.View)
widget.View.SetInputCapture(widget.keyboardIntercept)

return &widget
Expand Down Expand Up @@ -121,7 +118,7 @@ func (widget *Widget) currentGitlabProject() *GitlabProject {
func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
switch string(event.Rune()) {
case "/":
widget.showHelp()
widget.ShowHelp()
return nil
case "h":
widget.Prev()
Expand All @@ -145,16 +142,3 @@ func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
return event
}
}

func (widget *Widget) showHelp() {
closeFunc := func() {
widget.pages.RemovePage("help")
widget.app.SetFocus(widget.View)
}

modal := wtf.NewBillboardModal(HelpText, closeFunc)

widget.pages.AddPage("help", modal, false, true)
widget.app.SetFocus(modal)
widget.app.Draw()
}
26 changes: 6 additions & 20 deletions jira/widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,20 @@ const HelpText = `
`

type Widget struct {
wtf.HelpfulWidget
wtf.TextWidget

app *tview.Application
pages *tview.Pages
result *SearchResult
selected int
}

func NewWidget(app *tview.Application, pages *tview.Pages) *Widget {
widget := Widget{
TextWidget: wtf.NewTextWidget("Jira", "jira", true),

app: app,
pages: pages,
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
TextWidget: wtf.NewTextWidget("Jira", "jira", true),
}

widget.HelpfulWidget.SetView(widget.View)
widget.unselect()

widget.View.SetInputCapture(widget.keyboardIntercept)
Expand Down Expand Up @@ -173,7 +172,7 @@ func getProjects() []string {
func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
switch string(event.Rune()) {
case "/":
widget.showHelp()
widget.ShowHelp()
case "j":
// Select the next item down
widget.next()
Expand Down Expand Up @@ -210,16 +209,3 @@ func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
return event
}
}

func (widget *Widget) showHelp() {
closeFunc := func() {
widget.pages.RemovePage("help")
widget.app.SetFocus(widget.View)
}

modal := wtf.NewBillboardModal(HelpText, closeFunc)

widget.pages.AddPage("help", modal, false, true)
widget.app.SetFocus(modal)
widget.app.Draw()
}
26 changes: 6 additions & 20 deletions textfile/widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,24 @@ const HelpText = `
`

type Widget struct {
wtf.HelpfulWidget
wtf.TextWidget

app *tview.Application
filePath string
pages *tview.Pages
}

func NewWidget(app *tview.Application, pages *tview.Pages) *Widget {
widget := Widget{
TextWidget: wtf.NewTextWidget("TextFile", "textfile", true),
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
TextWidget: wtf.NewTextWidget("TextFile", "textfile", true),

app: app,
filePath: wtf.Config.UString("wtf.mods.textfile.filePath"),
pages: pages,
}

widget.HelpfulWidget.SetView(widget.View)

widget.View.SetWrap(true)
widget.View.SetWordWrap(true)

widget.View.SetInputCapture(widget.keyboardIntercept)

return &widget
Expand Down Expand Up @@ -155,7 +154,7 @@ func (widget *Widget) fileName() string {
func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
switch string(event.Rune()) {
case "/":
widget.showHelp()
widget.ShowHelp()
return nil
case "o":
wtf.OpenFile(widget.filePath)
Expand All @@ -164,16 +163,3 @@ func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {

return event
}

func (widget *Widget) showHelp() {
closeFunc := func() {
widget.pages.RemovePage("help")
widget.app.SetFocus(widget.View)
}

modal := wtf.NewBillboardModal(HelpText, closeFunc)

widget.pages.AddPage("help", modal, false, true)
widget.app.SetFocus(modal)
widget.app.Draw()
}
21 changes: 6 additions & 15 deletions todo/widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const modalWidth = 80
const modalHeight = 7

type Widget struct {
wtf.HelpfulWidget
wtf.TextWidget

app *tview.Application
Expand All @@ -46,7 +47,8 @@ type Widget struct {

func NewWidget(app *tview.Application, pages *tview.Pages) *Widget {
widget := Widget{
TextWidget: wtf.NewTextWidget("Todo", "todo", true),
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
TextWidget: wtf.NewTextWidget("Todo", "todo", true),

app: app,
filePath: wtf.Config.UString("wtf.mods.todo.filename"),
Expand All @@ -55,6 +57,8 @@ func NewWidget(app *tview.Application, pages *tview.Pages) *Widget {
}

widget.init()
widget.HelpfulWidget.SetView(widget.View)

widget.View.SetScrollable(true)
widget.View.SetRegions(true)
widget.View.SetInputCapture(widget.keyboardIntercept)
Expand Down Expand Up @@ -116,7 +120,7 @@ func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
widget.display()
return nil
case "/":
widget.showHelp()
widget.ShowHelp()
return nil
case "j":
// Select the next item down
Expand Down Expand Up @@ -222,19 +226,6 @@ func (widget *Widget) persist() {
}
}

func (widget *Widget) showHelp() {
closeFunc := func() {
widget.pages.RemovePage("help")
widget.app.SetFocus(widget.View)
}

modal := wtf.NewBillboardModal(HelpText, closeFunc)

widget.pages.AddPage("help", modal, false, true)
widget.app.SetFocus(modal)
widget.app.Draw()
}

/* -------------------- Modal Form -------------------- */

func (widget *Widget) addButtons(form *tview.Form, saveFctn func()) {
Expand Down
Loading

0 comments on commit 9154441

Please sign in to comment.