summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-06-29 10:41:02 -0400
committerPietro Gagliardi <[email protected]>2014-06-29 10:41:02 -0400
commit7e0a0db4928ffba4ff882bbddea6b2ad22a4213e (patch)
tree81fbc5f4c2c345ec309100326a43c4c05eb01388
parentf4677247f19177cb8a3521839dac3cbe7ffde417 (diff)
Did most of the conversion of dialog_darwin.go/.m to the new API.
-rw-r--r--dialog_darwin.go56
-rw-r--r--dialog_darwin.m6
2 files changed, 27 insertions, 35 deletions
diff --git a/dialog_darwin.go b/dialog_darwin.go
index 038c640..6ce28c0 100644
--- a/dialog_darwin.go
+++ b/dialog_darwin.go
@@ -3,6 +3,7 @@
package ui
import (
+ "fmt"
"unsafe"
)
@@ -17,43 +18,32 @@ func dialog_send(pchan unsafe.Pointer, res C.intptr_t) {
}()
}
-func _msgBox(parent *Window, primarytext string, secondarytext string, style uintptr) chan int {
- ret := make(chan int)
- uitask <- func() {
- var pwin C.id = nil
+func _msgBox(parent *Window, primarytext string, secondarytext string, style uintptr) Response {
+ var pwin C.id = nil
- if parent != dialogWindow {
- pwin = parent.sysData.id
- }
- primary := toNSString(primarytext)
- secondary := C.id(nil)
- if secondarytext != "" {
- secondary = toNSString(secondarytext)
- }
- switch style {
- case 0: // normal
- C.msgBox(pwin, primary, secondary, unsafe.Pointer(&ret))
- case 1: // error
- C.msgBoxError(pwin, primary, secondary, unsafe.Pointer(&ret))
- }
+ if parent != dialogWindow {
+ pwin = parent.sysData.id
}
- return ret
+ primary := toNSString(primarytext)
+ secondary := C.id(nil)
+ if secondarytext != "" {
+ secondary = toNSString(secondarytext)
+ }
+ switch style {
+ case 0: // normal
+ C.msgBox(pwin, primary, secondary, nil)
+ return OK
+ case 1: // error
+ C.msgBoxError(pwin, primary, secondary, nil)
+ return OK
+ }
+ panic(fmt.Errorf("unknown message box style %d\n", style))
}
-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 (w *Window) msgBox(primarytext string, secondarytext string) {
+ _msgBox(w, primarytext, secondarytext, 0)
}
-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
+func (w *Window) msgBoxError(primarytext string, secondarytext string) {
+ _msgBox(w, primarytext, secondarytext, 1)
}
diff --git a/dialog_darwin.m b/dialog_darwin.m
index d38e7af..7f72d02 100644
--- a/dialog_darwin.m
+++ b/dialog_darwin.m
@@ -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
[box addButtonWithTitle:@"OK"];
if (parent == nil)
- dialog_send(chan, (intptr_t) [box runModal]);
- else
+ return (intptr_t) [box runModal];
+ else {
[box beginSheetModalForWindow:toNSWindow(parent)
modalDelegate:[NSApp delegate]
didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:)
contextInfo:chan];
+ // TODO
+ }
}
void msgBox(id parent, id primary, id secondary, void *chan)