2015-08-16 21:30:44 -05:00
|
|
|
// 26 june 2015
|
|
|
|
#import "uipriv_darwin.h"
|
|
|
|
|
2015-11-28 11:09:14 -06:00
|
|
|
// TODO while a dialog is running no other window receives events
|
|
|
|
|
|
|
|
#define windowWindow(w) ((NSWindow *) uiControlHandle(uiControl(w)))
|
|
|
|
|
|
|
|
// source of code modal logic: http://stackoverflow.com/questions/604768/wait-for-nsalert-beginsheetmodalforwindow
|
|
|
|
|
2015-08-25 18:26:51 -05:00
|
|
|
// note: whether extensions are actually shown depends on a user setting in Finder; we can't control it here
|
2015-08-25 18:10:29 -05:00
|
|
|
static void setupSavePanel(NSSavePanel *s)
|
|
|
|
{
|
|
|
|
[s setCanCreateDirectories:YES];
|
|
|
|
[s setShowsHiddenFiles:YES];
|
|
|
|
[s setExtensionHidden:NO];
|
|
|
|
[s setCanSelectHiddenExtension:NO];
|
|
|
|
[s setTreatsFilePackagesAsDirectories:YES];
|
|
|
|
}
|
|
|
|
|
2015-11-28 11:09:14 -06:00
|
|
|
static char *runSavePanel(NSWindow *parent, NSSavePanel *s)
|
2015-08-25 18:10:29 -05:00
|
|
|
{
|
|
|
|
char *filename;
|
|
|
|
|
2015-11-28 11:09:14 -06:00
|
|
|
[s beginSheetModalForWindow:parent completionHandler:^(NSInteger result) {
|
|
|
|
[realNSApp() stopModalWithCode:result];
|
|
|
|
}];
|
|
|
|
if ([realNSApp() runModalForWindow:s] != NSFileHandlingPanelOKButton)
|
2015-08-25 18:10:29 -05:00
|
|
|
return NULL;
|
|
|
|
filename = uiDarwinNSStringToText([[s URL] path]);
|
|
|
|
return filename;
|
|
|
|
}
|
|
|
|
|
2015-11-28 11:09:14 -06:00
|
|
|
char *uiOpenFile(uiWindow *parent)
|
2015-08-16 21:30:44 -05:00
|
|
|
{
|
2015-08-25 18:10:29 -05:00
|
|
|
NSOpenPanel *o;
|
|
|
|
|
|
|
|
o = [NSOpenPanel openPanel];
|
|
|
|
[o setCanChooseFiles:YES];
|
|
|
|
[o setCanChooseDirectories:NO];
|
|
|
|
[o setResolvesAliases:NO];
|
|
|
|
[o setAllowsMultipleSelection:NO];
|
|
|
|
setupSavePanel(o);
|
|
|
|
// panel is autoreleased
|
2015-11-28 11:09:14 -06:00
|
|
|
return runSavePanel(windowWindow(parent), o);
|
2015-08-16 21:30:44 -05:00
|
|
|
}
|
|
|
|
|
2015-11-28 11:09:14 -06:00
|
|
|
char *uiSaveFile(uiWindow *parent)
|
2015-08-16 21:30:44 -05:00
|
|
|
{
|
2015-08-25 18:10:29 -05:00
|
|
|
NSSavePanel *s;
|
|
|
|
|
|
|
|
s = [NSSavePanel savePanel];
|
|
|
|
setupSavePanel(s);
|
|
|
|
// panel is autoreleased
|
2015-11-28 11:09:14 -06:00
|
|
|
return runSavePanel(windowWindow(parent), s);
|
|
|
|
}
|
|
|
|
|
|
|
|
// I would use a completion handler for NSAlert as well, but alas NSAlert's are 10.9 and higher only
|
|
|
|
@interface libuiCodeModalAlertPanel : NSObject {
|
|
|
|
NSAlert *panel;
|
|
|
|
NSWindow *parent;
|
|
|
|
}
|
|
|
|
- (id)initWithPanel:(NSAlert *)p parent:(NSWindow *)w;
|
|
|
|
- (NSInteger)run;
|
|
|
|
- (void)panelEnded:(NSAlert *)panel result:(NSInteger)result data:(void *)data;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation libuiCodeModalAlertPanel
|
|
|
|
|
|
|
|
- (id)initWithPanel:(NSAlert *)p parent:(NSWindow *)w
|
|
|
|
{
|
|
|
|
self = [super init];
|
|
|
|
if (self) {
|
|
|
|
self->panel = p;
|
|
|
|
self->parent = w;
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSInteger)run
|
|
|
|
{
|
|
|
|
[self->panel beginSheetModalForWindow:self->parent
|
|
|
|
modalDelegate:self
|
|
|
|
didEndSelector:@selector(panelEnded:result:data:)
|
|
|
|
contextInfo:NULL];
|
|
|
|
return [realNSApp() runModalForWindow:[self->panel window]];
|
2015-08-16 21:30:44 -05:00
|
|
|
}
|
|
|
|
|
2015-11-28 11:09:14 -06:00
|
|
|
- (void)panelEnded:(NSAlert *)panel result:(NSInteger)result data:(void *)data
|
|
|
|
{
|
|
|
|
[realNSApp() stopModalWithCode:result];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
static void msgbox(NSWindow *parent, const char *title, const char *description, NSAlertStyle style)
|
2015-08-25 18:26:51 -05:00
|
|
|
{
|
|
|
|
NSAlert *a;
|
2015-11-28 11:09:14 -06:00
|
|
|
libuiCodeModalAlertPanel *cm;
|
2015-08-25 18:26:51 -05:00
|
|
|
|
|
|
|
a = [NSAlert new];
|
|
|
|
[a setAlertStyle:style];
|
|
|
|
[a setShowsHelp:NO];
|
|
|
|
[a setShowsSuppressionButton:NO];
|
|
|
|
[a setMessageText:toNSString(title)];
|
|
|
|
[a setInformativeText:toNSString(description)];
|
|
|
|
[a addButtonWithTitle:@"OK"];
|
2015-11-28 11:09:14 -06:00
|
|
|
cm = [[libuiCodeModalAlertPanel alloc] initWithPanel:a parent:parent];
|
|
|
|
[cm run];
|
|
|
|
[cm release];
|
2015-08-25 18:26:51 -05:00
|
|
|
[a release];
|
|
|
|
}
|
|
|
|
|
2015-11-28 11:09:14 -06:00
|
|
|
void uiMsgBox(uiWindow *parent, const char *title, const char *description)
|
2015-08-16 21:30:44 -05:00
|
|
|
{
|
2015-11-28 11:09:14 -06:00
|
|
|
msgbox(windowWindow(parent), title, description, NSInformationalAlertStyle);
|
2015-08-16 21:30:44 -05:00
|
|
|
}
|
|
|
|
|
2015-11-28 11:09:14 -06:00
|
|
|
void uiMsgBoxError(uiWindow *parent, const char *title, const char *description)
|
2015-08-16 21:30:44 -05:00
|
|
|
{
|
2015-11-28 11:09:14 -06:00
|
|
|
msgbox(windowWindow(parent), title, description, NSCriticalAlertStyle);
|
2015-08-16 21:30:44 -05:00
|
|
|
}
|