Did most of the conversion of dialog_darwin.go/.m to the new API.

This commit is contained in:
Pietro Gagliardi 2014-06-29 10:41:02 -04:00
parent f4677247f1
commit 7e0a0db492
2 changed files with 27 additions and 35 deletions

View File

@ -3,6 +3,7 @@
package ui package ui
import ( import (
"fmt"
"unsafe" "unsafe"
) )
@ -17,9 +18,7 @@ func dialog_send(pchan unsafe.Pointer, res C.intptr_t) {
}() }()
} }
func _msgBox(parent *Window, primarytext string, secondarytext string, style uintptr) chan int { func _msgBox(parent *Window, primarytext string, secondarytext string, style uintptr) Response {
ret := make(chan int)
uitask <- func() {
var pwin C.id = nil var pwin C.id = nil
if parent != dialogWindow { if parent != dialogWindow {
@ -32,28 +31,19 @@ func _msgBox(parent *Window, primarytext string, secondarytext string, style uin
} }
switch style { switch style {
case 0: // normal case 0: // normal
C.msgBox(pwin, primary, secondary, unsafe.Pointer(&ret)) C.msgBox(pwin, primary, secondary, nil)
return OK
case 1: // error case 1: // error
C.msgBoxError(pwin, primary, secondary, unsafe.Pointer(&ret)) C.msgBoxError(pwin, primary, secondary, nil)
return OK
} }
} panic(fmt.Errorf("unknown message box style %d\n", style))
return ret
} }
func (w *Window) msgBox(primarytext string, secondarytext string) (done chan struct{}) { func (w *Window) msgBox(primarytext string, secondarytext string) {
done = make(chan struct{}) _msgBox(w, primarytext, secondarytext, 0)
go func() {
<-_msgBox(w, primarytext, secondarytext, 0)
done <- struct{}{}
}()
return done
} }
func (w *Window) msgBoxError(primarytext string, secondarytext string) (done chan struct{}) { func (w *Window) msgBoxError(primarytext string, secondarytext string) {
done = make(chan struct{}) _msgBox(w, primarytext, secondarytext, 1)
go func() {
<-_msgBox(w, primarytext, secondarytext, 1)
done <- struct{}{}
}()
return done
} }

View File

@ -21,12 +21,14 @@ static void alert(id parent, NSString *primary, NSString *secondary, NSAlertStyl
// TODO is there a named constant? will also need to be changed when we add different dialog types // TODO is there a named constant? will also need to be changed when we add different dialog types
[box addButtonWithTitle:@"OK"]; [box addButtonWithTitle:@"OK"];
if (parent == nil) if (parent == nil)
dialog_send(chan, (intptr_t) [box runModal]); return (intptr_t) [box runModal];
else else {
[box beginSheetModalForWindow:toNSWindow(parent) [box beginSheetModalForWindow:toNSWindow(parent)
modalDelegate:[NSApp delegate] modalDelegate:[NSApp delegate]
didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:) didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:)
contextInfo:chan]; contextInfo:chan];
// TODO
}
} }
void msgBox(id parent, id primary, id secondary, void *chan) void msgBox(id parent, id primary, id secondary, void *chan)