Add an option for using custom dialog icons on MacOS
This commit is contained in:
parent
8d981fce7e
commit
17827d3b70
5 changed files with 27 additions and 9 deletions
|
@ -55,9 +55,13 @@ fmt.stringFromDate(date.dateValue)
|
||||||
var app=Application.currentApplication()
|
var app=Application.currentApplication()
|
||||||
app.includeStandardAdditions=true
|
app.includeStandardAdditions=true
|
||||||
app.activate()
|
app.activate()
|
||||||
ObjC.import('stdio')
|
ObjC.import("stdlib")
|
||||||
ObjC.import('stdlib')
|
ObjC.import("stdio")
|
||||||
var res=app.{{.Operation}}({{json .Text}},{{json .Options}})
|
var opt={{json .Options}}
|
||||||
|
{{- if .IconPath}}
|
||||||
|
opt["withIcon"]=Path("{{.IconPath}}")
|
||||||
|
{{- end}}
|
||||||
|
var res=app.{{.Operation}}({{json .Text}},opt)
|
||||||
if(res.gaveUp){$.exit(5)}
|
if(res.gaveUp){$.exit(5)}
|
||||||
if(res.buttonReturned==={{json .Extra}}){$.puts(res.buttonReturned)
|
if(res.buttonReturned==={{json .Extra}}){$.puts(res.buttonReturned)
|
||||||
$.exit(1)}
|
$.exit(1)}
|
||||||
|
|
|
@ -2,10 +2,13 @@ var app = Application.currentApplication()
|
||||||
app.includeStandardAdditions = true
|
app.includeStandardAdditions = true
|
||||||
app.activate()
|
app.activate()
|
||||||
|
|
||||||
ObjC.import('stdio')
|
ObjC.import("stdlib")
|
||||||
ObjC.import('stdlib')
|
ObjC.import("stdio")
|
||||||
|
var opt = {{json .Options}}
|
||||||
var res = app.{{.Operation}}({{json .Text}}, {{json .Options}})
|
{{- if .IconPath}}
|
||||||
|
opt["withIcon"] = Path("{{.IconPath}}")
|
||||||
|
{{- end}}
|
||||||
|
var res = app.{{.Operation}}({{json .Text}}, opt)
|
||||||
if (res.gaveUp) {
|
if (res.gaveUp) {
|
||||||
$.exit(5)
|
$.exit(5)
|
||||||
}
|
}
|
||||||
|
|
|
@ -130,6 +130,7 @@ type Dialog struct {
|
||||||
Text string
|
Text string
|
||||||
Extra *string
|
Extra *string
|
||||||
Options DialogOptions
|
Options DialogOptions
|
||||||
|
IconPath *string
|
||||||
}
|
}
|
||||||
|
|
||||||
// DialogOptions is internal.
|
// DialogOptions is internal.
|
||||||
|
|
|
@ -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 { // use if we want to show a specific icon
|
if opts.icon != 0 || opts.iconPath != nil { // 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,7 +20,11 @@ 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
|
||||||
data.Options.Icon = opts.icon.String()
|
if opts.iconPath != nil {
|
||||||
|
data.IconPath = opts.iconPath
|
||||||
|
} else {
|
||||||
|
data.Options.Icon = opts.icon.String()
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
data.Operation = "displayAlert"
|
data.Operation = "displayAlert"
|
||||||
data.Options.As = kind.String()
|
data.Options.As = kind.String()
|
||||||
|
|
|
@ -39,6 +39,7 @@ type options struct {
|
||||||
cancelLabel *string
|
cancelLabel *string
|
||||||
extraButton *string
|
extraButton *string
|
||||||
icon DialogIcon
|
icon DialogIcon
|
||||||
|
iconPath *string
|
||||||
defaultCancel bool
|
defaultCancel bool
|
||||||
|
|
||||||
// Message options
|
// Message options
|
||||||
|
@ -150,6 +151,11 @@ const (
|
||||||
// Deprecated: use DialogIcon directly.
|
// Deprecated: 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.
|
||||||
|
func CustomIcon(path string) Option {
|
||||||
|
return funcOption(func(o *options) { o.iconPath = &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.
|
||||||
//
|
//
|
||||||
// Dialogs dismissed by ctx return ctx.Err().
|
// Dialogs dismissed by ctx return ctx.Err().
|
||||||
|
|
Loading…
Reference in a new issue