From b172ab2e37896d36292660f6cc15987fb88ddf57 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sun, 8 Jun 2014 12:36:55 -0400 Subject: Added new MsgBox() behavior on Mac OS X. Now we can finally remove MsgBox() from the TODOs! :D --- dialog_darwin.go | 42 +++++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 13 deletions(-) (limited to 'dialog_darwin.go') diff --git a/dialog_darwin.go b/dialog_darwin.go index ef1cd6c..3047ed0 100644 --- a/dialog_darwin.go +++ b/dialog_darwin.go @@ -3,19 +3,26 @@ package ui import ( - // ... + "unsafe" ) // #include "objc_darwin.h" import "C" -func _msgBox(parent *Window, primarytext string, secondarytext string, style uintptr) { - ret := make(chan struct{}) - defer close(ret) +//export dialog_send +func dialog_send(pchan unsafe.Pointer, res C.intptr_t) { + rchan := (*chan int)(pchan) + go func() { // send it in a new goroutine like we do with everything else + *rchan <- int(res) + }() +} + +func _msgBox(parent *Window, primarytext string, secondarytext string, style uintptr) chan int { + ret := make(chan int) uitask <- func() { var pwin C.id = nil - if parent != nil { + if parent != dialogWindow { pwin = parent.sysData.id } primary := toNSString(primarytext) @@ -25,19 +32,28 @@ func _msgBox(parent *Window, primarytext string, secondarytext string, style uin } switch style { case 0: // normal - C.msgBox(pwin, primary, secondary) + C.msgBox(pwin, primary, secondary, unsafe.Pointer(&ret)) case 1: // error - C.msgBoxError(pwin, primary, secondary) + C.msgBoxError(pwin, primary, secondary, unsafe.Pointer(&ret)) } - ret <- struct{}{} } - <-ret + return ret } -func msgBox(parent *Window, primarytext string, secondarytext string) { - _msgBox(parent, primarytext, secondarytext, 0) +func (w *Window) msgBox(primarytext string, secondarytext string) (done chan struct{}) { + done = make(chan struct{}) + go func() { + <-_msgBox(w, primarytext, secondarytext, 0) + done <- struct{}{} + }() + return done } -func msgBoxError(parent *Window, primarytext string, secondarytext string) { - _msgBox(parent, primarytext, secondarytext, 1) +func (w *Window) msgBoxError(primarytext string, secondarytext string) (done chan struct{}) { + done = make(chan struct{}) + go func() { + <-_msgBox(w, primarytext, secondarytext, 1) + done <- struct{}{} + }() + return done } -- cgit v1.2.3