forked from ncruces/zenity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util_darwin.go
85 lines (78 loc) · 1.74 KB
/
util_darwin.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package zenity
import "github.com/ncruces/zenity/internal/zenutil"
func getButtons(dialog, okcancel bool, opts options) (btns zenutil.DialogButtons) {
if !okcancel {
opts.cancelLabel = nil
opts.defaultCancel = false
}
if opts.okLabel != nil || opts.cancelLabel != nil || opts.extraButton != nil || dialog != okcancel {
if opts.okLabel == nil {
opts.okLabel = ptr("OK")
}
if okcancel {
if opts.cancelLabel == nil {
opts.cancelLabel = ptr("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
}
func getAlertButtons(opts options) (ok, cancel string, extra *string) {
if opts.okLabel == nil {
opts.okLabel = ptr("OK")
}
if opts.cancelLabel == nil {
opts.cancelLabel = ptr("Cancel")
}
return *opts.okLabel, *opts.cancelLabel, opts.extraButton
}
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 ""
}
}