libui/darwin/stddialogs.m

72 lines
1.5 KiB
Mathematica
Raw Normal View History

2015-08-16 21:30:44 -05:00
// 26 june 2015
#import "uipriv_darwin.h"
// note: whether extensions are actually shown depends on a user setting in Finder; we can't control it here
static void setupSavePanel(NSSavePanel *s)
{
[s setCanCreateDirectories:YES];
[s setShowsHiddenFiles:YES];
[s setExtensionHidden:NO];
[s setCanSelectHiddenExtension:NO];
[s setTreatsFilePackagesAsDirectories:YES];
}
static char *runSavePanel(NSSavePanel *s)
{
char *filename;
if ([s runModal] != NSFileHandlingPanelOKButton)
return NULL;
filename = uiDarwinNSStringToText([[s URL] path]);
return filename;
}
2015-08-16 21:30:44 -05:00
char *uiOpenFile(void)
{
NSOpenPanel *o;
o = [NSOpenPanel openPanel];
[o setCanChooseFiles:YES];
[o setCanChooseDirectories:NO];
[o setResolvesAliases:NO];
[o setAllowsMultipleSelection:NO];
setupSavePanel(o);
// panel is autoreleased
return runSavePanel(o);
2015-08-16 21:30:44 -05:00
}
char *uiSaveFile(void)
{
NSSavePanel *s;
s = [NSSavePanel savePanel];
setupSavePanel(s);
// panel is autoreleased
return runSavePanel(s);
2015-08-16 21:30:44 -05:00
}
static void msgbox(const char *title, const char *description, NSAlertStyle style)
{
NSAlert *a;
a = [NSAlert new];
[a setAlertStyle:style];
[a setShowsHelp:NO];
[a setShowsSuppressionButton:NO];
[a setMessageText:toNSString(title)];
[a setInformativeText:toNSString(description)];
[a addButtonWithTitle:@"OK"];
[a runModal];
[a release];
}
2015-08-16 21:30:44 -05:00
void uiMsgBox(const char *title, const char *description)
{
msgbox(title, description, NSInformationalAlertStyle);
2015-08-16 21:30:44 -05:00
}
void uiMsgBoxError(const char *title, const char *description)
{
msgbox(title, description, NSCriticalAlertStyle);
2015-08-16 21:30:44 -05:00
}