2021-04-06 07:35:22 -04:00
|
|
|
package zenity
|
|
|
|
|
|
|
|
import "github.com/ncruces/zenity/internal/zenutil"
|
|
|
|
|
2021-04-25 19:36:15 -04:00
|
|
|
func getButtons(dialog, okcancel bool, opts options) (btns zenutil.DialogButtons) {
|
2021-04-06 07:35:22 -04:00
|
|
|
if !okcancel {
|
|
|
|
opts.cancelLabel = nil
|
|
|
|
opts.defaultCancel = false
|
|
|
|
}
|
|
|
|
|
2021-04-25 19:36:15 -04:00
|
|
|
if opts.okLabel != nil || opts.cancelLabel != nil || opts.extraButton != nil || dialog != okcancel {
|
2021-04-06 07:35:22 -04:00
|
|
|
if opts.okLabel == nil {
|
|
|
|
opts.okLabel = stringPtr("OK")
|
|
|
|
}
|
|
|
|
if okcancel {
|
|
|
|
if opts.cancelLabel == nil {
|
|
|
|
opts.cancelLabel = stringPtr("Cancel")
|
|
|
|
}
|
|
|
|
if opts.extraButton == nil {
|
|
|
|
btns.Buttons = []string{*opts.cancelLabel, *opts.okLabel}
|
|
|
|
btns.Default = 2
|
|
|
|
btns.Cancel = 1
|
|
|
|
} else {
|
|
|
|
btns.Buttons = []string{*opts.extraButton, *opts.cancelLabel, *opts.okLabel}
|
|
|
|
btns.Default = 3
|
|
|
|
btns.Cancel = 2
|
|
|
|
btns.Extra = 1
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if opts.extraButton == nil {
|
|
|
|
btns.Buttons = []string{*opts.okLabel}
|
|
|
|
btns.Default = 1
|
|
|
|
} else {
|
|
|
|
btns.Buttons = []string{*opts.extraButton, *opts.okLabel}
|
|
|
|
btns.Default = 2
|
|
|
|
btns.Extra = 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if opts.defaultCancel {
|
|
|
|
if btns.Cancel != 0 {
|
|
|
|
btns.Default = btns.Cancel
|
|
|
|
} else {
|
|
|
|
btns.Default = 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-03-28 15:22:39 -04:00
|
|
|
func getAlertButtons(opts options) (ok, cancel string, extra *string) {
|
|
|
|
if opts.okLabel == nil {
|
|
|
|
opts.okLabel = stringPtr("OK")
|
|
|
|
}
|
|
|
|
if opts.cancelLabel == nil {
|
|
|
|
opts.cancelLabel = stringPtr("Cancel")
|
|
|
|
}
|
|
|
|
return *opts.okLabel, *opts.cancelLabel, opts.extraButton
|
|
|
|
}
|
|
|
|
|
2021-04-06 07:35:22 -04:00
|
|
|
func (i DialogIcon) String() string {
|
|
|
|
switch i {
|
|
|
|
case ErrorIcon:
|
|
|
|
return "stop"
|
|
|
|
case WarningIcon:
|
|
|
|
return "caution"
|
|
|
|
case InfoIcon, QuestionIcon:
|
|
|
|
return "note"
|
|
|
|
default:
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (k messageKind) String() string {
|
|
|
|
switch k {
|
|
|
|
case infoKind:
|
|
|
|
return "informational"
|
|
|
|
case warningKind:
|
|
|
|
return "warning"
|
|
|
|
case errorKind:
|
|
|
|
return "critical"
|
|
|
|
default:
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
}
|