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 Text string
Extra *string Extra *string
Options DialogOptions Options DialogOptions
IconPath *string IconPath string
} }
// DialogOptions is internal. // DialogOptions is internal.

View file

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

View file

@ -39,7 +39,7 @@ type options struct {
cancelLabel *string cancelLabel *string
extraButton *string extraButton *string
icon DialogIcon icon DialogIcon
iconPath *string customIcon string
defaultCancel bool defaultCancel bool
// Message options // Message options
@ -133,7 +133,10 @@ func ExtraButton(extra string) Option {
// DialogIcon is an Option that sets the dialog icon. // DialogIcon is an Option that sets the dialog icon.
type DialogIcon int 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. // The stock dialog icons.
const ( const (
@ -148,12 +151,15 @@ const (
// Icon returns an Option to set the dialog icon. // Icon returns an Option to set the dialog icon.
// //
// Deprecated: use DialogIcon directly. // Tip: use DialogIcon directly.
func Icon(icon DialogIcon) Option { return icon } 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 { 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. // Context returns an Option to set a Context that can dismiss the dialog.