Skip to content

Commit

Permalink
Merge pull request #9 from xxxserxxx/issue8
Browse files Browse the repository at this point in the history
Fixes #8, help dialog can be shown exactly once
  • Loading branch information
spezifisch authored Jul 30, 2024
2 parents 39cc1d6 + 1027e68 commit 3f52475
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
11 changes: 10 additions & 1 deletion gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,13 @@ func InitGui(indexes *[]subsonic.SubsonicIndex,
// help box modal
ui.helpModal = makeModal(ui.helpWidget.Root, 80, 30)
ui.helpWidget.Root.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
ui.CloseHelp()
// Belts and suspenders. After the dialog is shown, this function will
// _always_ be called. Therefore, check to ensure it's actually visible
// before triggering on events. Also, don't close on every key, but only
// ESC, like the help text says.
if ui.helpWidget.visible && (event.Key() == tcell.KeyEscape) {
ui.CloseHelp()
}
return event
})

Expand Down Expand Up @@ -188,10 +194,13 @@ func (ui *Ui) ShowHelp() {
ui.helpWidget.RenderHelp(activePage)

ui.pages.ShowPage(PageHelpBox)
ui.pages.SendToFront(PageHelpBox)
ui.app.SetFocus(ui.helpModal)
ui.helpWidget.visible = true
}

func (ui *Ui) CloseHelp() {
ui.helpWidget.visible = false
ui.pages.HidePage(PageHelpBox)
}

Expand Down
12 changes: 4 additions & 8 deletions widget_help.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ type HelpWidget struct {
helpBook *tview.Flex
leftColumn, rightColumn *tview.TextView

// visible reflects whether the modal is shown
visible bool

// external references
ui *Ui
}
Expand All @@ -32,16 +35,9 @@ func (ui *Ui) createHelpWidget() (m *HelpWidget) {
m.helpBook = tview.NewFlex().
SetDirection(tview.FlexColumn)

// button at the bottom
closeButton := tview.NewButton("Close")
closeButton.SetSelectedFunc(func() {
ui.CloseHelp()
})

m.Root = tview.NewFlex().
SetDirection(tview.FlexRow).
AddItem(m.helpBook, 0, 1, false).
AddItem(closeButton, 1, 0, true)
AddItem(m.helpBook, 0, 1, false)

m.Root.Box.SetBorder(true).SetTitle(" Help ")

Expand Down

0 comments on commit 3f52475

Please sign in to comment.