2014-03-02 17:37:25 -06:00
|
|
|
// 2 march 2014
|
2014-03-12 20:55:45 -05:00
|
|
|
|
2014-03-02 17:37:25 -06:00
|
|
|
package ui
|
|
|
|
|
|
|
|
import (
|
|
|
|
// ...
|
|
|
|
)
|
|
|
|
|
|
|
|
// #cgo LDFLAGS: -lobjc -framework Foundation -framework AppKit
|
|
|
|
// #include "objc_darwin.h"
|
|
|
|
import "C"
|
|
|
|
|
|
|
|
// NSAlert styles.
|
|
|
|
const (
|
|
|
|
_NSWarningAlertStyle = 0 // default
|
|
|
|
_NSInformationalAlertStyle = 1
|
|
|
|
_NSCriticalAlertStyle = 2
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
_NSAlert = objc_getClass("NSAlert")
|
|
|
|
|
|
|
|
_setMessageText = sel_getUid("setMessageText:")
|
|
|
|
_setInformativeText = sel_getUid("setInformativeText:")
|
|
|
|
_setAlertStyle = sel_getUid("setAlertStyle:")
|
|
|
|
_addButtonWithTitle = sel_getUid("addButtonWithTitle:")
|
|
|
|
_runModal = sel_getUid("runModal")
|
|
|
|
)
|
|
|
|
|
2014-03-12 11:14:24 -05:00
|
|
|
func _msgBox(primarytext string, secondarytext string, style uintptr, button0 string) {
|
2014-03-02 17:37:25 -06:00
|
|
|
ret := make(chan struct{})
|
|
|
|
defer close(ret)
|
|
|
|
uitask <- func() {
|
|
|
|
box := objc_new(_NSAlert)
|
2014-03-12 11:14:24 -05:00
|
|
|
C.objc_msgSend_id(box, _setMessageText, toNSString(primarytext))
|
|
|
|
C.objc_msgSend_id(box, _setInformativeText, toNSString(secondarytext))
|
2014-03-02 17:37:25 -06:00
|
|
|
objc_msgSend_uint(box, _setAlertStyle, style)
|
|
|
|
C.objc_msgSend_id(box, _addButtonWithTitle, toNSString(button0))
|
|
|
|
C.objc_msgSend_noargs(box, _runModal)
|
|
|
|
ret <- struct{}{}
|
|
|
|
}
|
|
|
|
<-ret
|
|
|
|
}
|
|
|
|
|
2014-03-12 11:14:24 -05:00
|
|
|
func msgBox(primarytext string, secondarytext string) {
|
2014-03-02 17:37:25 -06:00
|
|
|
// TODO _NSInformationalAlertStyle?
|
2014-03-12 11:14:24 -05:00
|
|
|
_msgBox(primarytext, secondarytext, _NSWarningAlertStyle, "OK")
|
2014-03-02 17:37:25 -06:00
|
|
|
}
|
|
|
|
|
2014-03-12 11:14:24 -05:00
|
|
|
func msgBoxError(primarytext string, secondarytext string) {
|
|
|
|
_msgBox(primarytext, secondarytext, _NSCriticalAlertStyle, "OK")
|
2014-03-02 17:37:25 -06:00
|
|
|
}
|