Added new MsgBox() behavior on Mac OS X. Now we can finally remove MsgBox() from the TODOs! :D
This commit is contained in:
parent
10f55564d0
commit
b172ab2e37
|
@ -108,8 +108,9 @@ extern NSRect dummyRect;
|
||||||
return NSTerminateCancel;
|
return NSTerminateCancel;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)alertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo
|
- (void)alertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(void *)chan
|
||||||
{
|
{
|
||||||
|
dialog_send(chan, (uintptr_t) returnCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -3,19 +3,26 @@
|
||||||
package ui
|
package ui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
// ...
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
// #include "objc_darwin.h"
|
// #include "objc_darwin.h"
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
func _msgBox(parent *Window, primarytext string, secondarytext string, style uintptr) {
|
//export dialog_send
|
||||||
ret := make(chan struct{})
|
func dialog_send(pchan unsafe.Pointer, res C.intptr_t) {
|
||||||
defer close(ret)
|
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() {
|
uitask <- func() {
|
||||||
var pwin C.id = nil
|
var pwin C.id = nil
|
||||||
|
|
||||||
if parent != nil {
|
if parent != dialogWindow {
|
||||||
pwin = parent.sysData.id
|
pwin = parent.sysData.id
|
||||||
}
|
}
|
||||||
primary := toNSString(primarytext)
|
primary := toNSString(primarytext)
|
||||||
|
@ -25,19 +32,28 @@ 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)
|
C.msgBox(pwin, primary, secondary, unsafe.Pointer(&ret))
|
||||||
case 1: // error
|
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) {
|
func (w *Window) msgBox(primarytext string, secondarytext string) (done chan struct{}) {
|
||||||
_msgBox(parent, primarytext, secondarytext, 0)
|
done = make(chan struct{})
|
||||||
|
go func() {
|
||||||
|
<-_msgBox(w, primarytext, secondarytext, 0)
|
||||||
|
done <- struct{}{}
|
||||||
|
}()
|
||||||
|
return done
|
||||||
}
|
}
|
||||||
|
|
||||||
func msgBoxError(parent *Window, primarytext string, secondarytext string) {
|
func (w *Window) msgBoxError(primarytext string, secondarytext string) (done chan struct{}) {
|
||||||
_msgBox(parent, primarytext, secondarytext, 1)
|
done = make(chan struct{})
|
||||||
|
go func() {
|
||||||
|
<-_msgBox(w, primarytext, secondarytext, 1)
|
||||||
|
done <- struct{}{}
|
||||||
|
}()
|
||||||
|
return done
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
// 15 may 2014
|
// 15 may 2014
|
||||||
|
|
||||||
#include "objc_darwin.h"
|
#include "objc_darwin.h"
|
||||||
|
#include "_cgo_export.h"
|
||||||
#import <AppKit/NSAlert.h>
|
#import <AppKit/NSAlert.h>
|
||||||
|
|
||||||
// see delegateuitask_darwin.m
|
// see delegateuitask_darwin.m
|
||||||
|
@ -23,7 +24,7 @@
|
||||||
#define to(T, x) ((T *) (x))
|
#define to(T, x) ((T *) (x))
|
||||||
#define toNSWindow(x) to(NSWindow, (x))
|
#define toNSWindow(x) to(NSWindow, (x))
|
||||||
|
|
||||||
static void alert(id parent, NSString *primary, NSString *secondary, NSAlertStyle style)
|
static void alert(id parent, NSString *primary, NSString *secondary, NSAlertStyle style, void *chan)
|
||||||
{
|
{
|
||||||
NSAlert *box;
|
NSAlert *box;
|
||||||
|
|
||||||
|
@ -35,20 +36,20 @@ 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)
|
||||||
[box runModal];
|
dialog_send(chan, (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:NULL];
|
contextInfo:chan];
|
||||||
}
|
}
|
||||||
|
|
||||||
void msgBox(id parent, id primary, id secondary)
|
void msgBox(id parent, id primary, id secondary, void *chan)
|
||||||
{
|
{
|
||||||
alert(parent, (NSString *) primary, (NSString *) secondary, NSInformationalAlertStyle);
|
alert(parent, (NSString *) primary, (NSString *) secondary, NSInformationalAlertStyle, chan);
|
||||||
}
|
}
|
||||||
|
|
||||||
void msgBoxError(id parent, id primary, id secondary)
|
void msgBoxError(id parent, id primary, id secondary, void *chan)
|
||||||
{
|
{
|
||||||
alert(parent, (NSString *) primary, (NSString *) secondary, NSCriticalAlertStyle);
|
alert(parent, (NSString *) primary, (NSString *) secondary, NSCriticalAlertStyle, chan);
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,8 +63,8 @@ extern void breakMainLoop(void);
|
||||||
extern void cocoaMainLoop(void);
|
extern void cocoaMainLoop(void);
|
||||||
|
|
||||||
/* dialog_darwin.m */
|
/* dialog_darwin.m */
|
||||||
extern void msgBox(id, id, id);
|
extern void msgBox(id, id, id, void *);
|
||||||
extern void msgBoxError(id, id, id);
|
extern void msgBoxError(id, id, id, void *);
|
||||||
|
|
||||||
/* listbox_darwin.m */
|
/* listbox_darwin.m */
|
||||||
extern id toListboxItem(id, id);
|
extern id toListboxItem(id, id);
|
||||||
|
|
1
todo.md
1
todo.md
|
@ -24,4 +24,3 @@ ALL PLATFORMS:
|
||||||
- will require moving dialog behavior to the package overview
|
- will require moving dialog behavior to the package overview
|
||||||
- make sure MouseEvent's documentation has dragging described correctly (both Windows and GTK+ do)
|
- make sure MouseEvent's documentation has dragging described correctly (both Windows and GTK+ do)
|
||||||
- make all widths and heights parameters in constructors in the same place (or drop the ones in Window entirely?)
|
- make all widths and heights parameters in constructors in the same place (or drop the ones in Window entirely?)
|
||||||
- Message boxes that belong to agiven parent are still application-modal on all platforms except Mac OS X because the whole system waits... we'll need to use a channel for this, I guess :S
|
|
||||||
|
|
Loading…
Reference in New Issue