Skip to content

Commit

Permalink
Make all dialog button callbacks use Hide() or hideWithResp()
Browse files Browse the repository at this point in the history
This avoids directly manipulating the channel from several places,
which helps with encapsulation.
  • Loading branch information
fiam committed Mar 18, 2020
1 parent 7e65ddd commit a971c77
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 16 deletions.
12 changes: 3 additions & 9 deletions dialog/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,7 @@ func ShowCustom(title, dismiss string, content fyne.CanvasObject, parent fyne.Wi
d := &dialog{content: content, title: title, icon: nil, parent: parent}

d.dismiss = &widget.Button{Text: dismiss,
OnTapped: func() {
d.response <- false
},
OnTapped: d.Hide,
}
d.setButtons(widget.NewHBox(layout.NewSpacer(), d.dismiss, layout.NewSpacer()))

Expand All @@ -208,14 +206,10 @@ func ShowCustomConfirm(title, confirm, dismiss string, content fyne.CanvasObject
d.callback = callback

d.dismiss = &widget.Button{Text: dismiss, Icon: theme.CancelIcon(),
OnTapped: func() {
d.response <- false
},
OnTapped: d.Hide,
}
ok := &widget.Button{Text: confirm, Icon: theme.ConfirmIcon(), Style: widget.PrimaryButton,
OnTapped: func() {
d.response <- true
},
OnTapped: d.Hide,
}
d.setButtons(widget.NewHBox(layout.NewSpacer(), d.dismiss, ok, layout.NewSpacer()))

Expand Down
6 changes: 2 additions & 4 deletions dialog/confirm.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,11 @@ func NewConfirm(title, message string, callback func(bool), parent fyne.Window)
d := newDialog(title, message, theme.QuestionIcon(), callback, parent)

d.dismiss = &widget.Button{Text: "No", Icon: theme.CancelIcon(),
OnTapped: func() {
d.response <- false
},
OnTapped: d.Hide,
}
confirm := &widget.Button{Text: "Yes", Icon: theme.ConfirmIcon(), Style: widget.PrimaryButton,
OnTapped: func() {
d.response <- true
d.hideWithResp(true)
},
}
d.setButtons(newButtonList(d.dismiss, confirm))
Expand Down
4 changes: 1 addition & 3 deletions dialog/information.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ func createTextDialog(title, message string, icon fyne.Resource, parent fyne.Win
d := newDialog(title, message, icon, nil, parent)

d.dismiss = &widget.Button{Text: "OK",
OnTapped: func() {
d.response <- false
},
OnTapped: d.Hide,
}
d.setButtons(newButtonList(d.dismiss))

Expand Down

0 comments on commit a971c77

Please sign in to comment.