Last provided icon wins.

This commit is contained in:
Nuno Cruces 2022-05-05 13:04:27 +01:00
parent e34f649c02
commit 4019a42f15
3 changed files with 15 additions and 9 deletions

View file

@ -130,7 +130,7 @@ type Dialog struct {
Text string
Extra *string
Options DialogOptions
IconPath *string
IconPath string
}
// DialogOptions is internal.

View file

@ -11,7 +11,7 @@ func message(kind messageKind, text string, opts options) error {
// dialog is more flexible, alert prettier
var dialog bool
if opts.icon != 0 || opts.iconPath != nil { // use if we want to show a specific icon
if opts.icon != 0 || opts.customIcon != "" { // use if we want to show a specific icon
dialog = true
} else if kind == questionKind && opts.cancelLabel == nil { // use for questions with default buttons
dialog = true
@ -20,8 +20,8 @@ func message(kind messageKind, text string, opts options) error {
if dialog {
data.Operation = "displayDialog"
data.Options.Title = opts.title
if opts.iconPath != nil {
data.IconPath = opts.iconPath
if opts.customIcon != "" {
data.IconPath = opts.customIcon
} else {
data.Options.Icon = opts.icon.String()
}

View file

@ -39,7 +39,7 @@ type options struct {
cancelLabel *string
extraButton *string
icon DialogIcon
iconPath *string
customIcon string
defaultCancel bool
// Message options
@ -133,7 +133,10 @@ func ExtraButton(extra string) Option {
// DialogIcon is an Option that sets the dialog icon.
type DialogIcon int
func (i DialogIcon) apply(o *options) { o.icon = i }
func (i DialogIcon) apply(o *options) {
o.customIcon = ""
o.icon = i
}
// The stock dialog icons.
const (
@ -148,12 +151,15 @@ const (
// Icon returns an Option to set the dialog icon.
//
// Deprecated: use DialogIcon directly.
// Tip: use DialogIcon directly.
func Icon(icon DialogIcon) Option { return icon }
// Icon returns an Option to set an icon loaded from a file.
// Icon returns an Option to set a custom dialog icon, loaded from a file.
func CustomIcon(path string) Option {
return funcOption(func(o *options) { o.iconPath = &path })
return funcOption(func(o *options) {
o.icon = unspecifiedIcon
o.customIcon = path
})
}
// Context returns an Option to set a Context that can dismiss the dialog.