2014-05-15 18:08:24 -05:00
|
|
|
// 15 may 2014
|
|
|
|
|
|
|
|
#include "objc_darwin.h"
|
2014-06-08 11:36:55 -05:00
|
|
|
#include "_cgo_export.h"
|
2014-05-20 07:08:55 -05:00
|
|
|
#import <AppKit/NSAlert.h>
|
2014-06-04 23:53:26 -05:00
|
|
|
#import <AppKit/NSWindow.h>
|
2014-06-11 13:58:39 -05:00
|
|
|
#import <AppKit/NSApplication.h>
|
2014-06-04 23:53:26 -05:00
|
|
|
|
|
|
|
#define to(T, x) ((T *) (x))
|
|
|
|
#define toNSWindow(x) to(NSWindow, (x))
|
|
|
|
|
2014-06-08 11:36:55 -05:00
|
|
|
static void alert(id parent, NSString *primary, NSString *secondary, NSAlertStyle style, void *chan)
|
2014-05-15 18:08:24 -05:00
|
|
|
{
|
|
|
|
NSAlert *box;
|
|
|
|
|
|
|
|
box = [NSAlert new];
|
|
|
|
[box setMessageText:primary];
|
|
|
|
if (secondary != nil)
|
|
|
|
[box setInformativeText:secondary];
|
|
|
|
[box setAlertStyle:style];
|
|
|
|
// TODO is there a named constant? will also need to be changed when we add different dialog types
|
|
|
|
[box addButtonWithTitle:@"OK"];
|
2014-06-04 23:53:26 -05:00
|
|
|
if (parent == nil)
|
2014-06-08 11:36:55 -05:00
|
|
|
dialog_send(chan, (intptr_t) [box runModal]);
|
2014-06-04 23:53:26 -05:00
|
|
|
else
|
|
|
|
[box beginSheetModalForWindow:toNSWindow(parent)
|
|
|
|
modalDelegate:[NSApp delegate]
|
|
|
|
didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:)
|
2014-06-08 11:36:55 -05:00
|
|
|
contextInfo:chan];
|
2014-05-15 18:08:24 -05:00
|
|
|
}
|
|
|
|
|
2014-06-08 11:36:55 -05:00
|
|
|
void msgBox(id parent, id primary, id secondary, void *chan)
|
2014-05-15 18:08:24 -05:00
|
|
|
{
|
2014-06-08 11:36:55 -05:00
|
|
|
alert(parent, (NSString *) primary, (NSString *) secondary, NSInformationalAlertStyle, chan);
|
2014-05-15 18:08:24 -05:00
|
|
|
}
|
|
|
|
|
2014-06-08 11:36:55 -05:00
|
|
|
void msgBoxError(id parent, id primary, id secondary, void *chan)
|
2014-05-15 18:08:24 -05:00
|
|
|
{
|
2014-06-08 11:36:55 -05:00
|
|
|
alert(parent, (NSString *) primary, (NSString *) secondary, NSCriticalAlertStyle, chan);
|
2014-05-15 18:08:24 -05:00
|
|
|
}
|