From ccd46d11f72c0b137717e8ff4abe7f6a9f11df27 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Tue, 25 Aug 2015 19:10:29 -0400 Subject: [PATCH] Implemented uiOpenFile() and uiSaveFile() on OS X. --- redo/reredo/darwin/stddialogs.m | 40 +++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/redo/reredo/darwin/stddialogs.m b/redo/reredo/darwin/stddialogs.m index 7890ad55..88878d32 100644 --- a/redo/reredo/darwin/stddialogs.m +++ b/redo/reredo/darwin/stddialogs.m @@ -1,16 +1,48 @@ // 26 june 2015 #import "uipriv_darwin.h" +// TODO is whether extensions are shown a Finder setting? +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; +} + char *uiOpenFile(void) { - // TODO - return NULL; + 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); } char *uiSaveFile(void) { - // TODO - return NULL; + NSSavePanel *s; + + s = [NSSavePanel savePanel]; + setupSavePanel(s); + // panel is autoreleased + return runSavePanel(s); } void uiMsgBox(const char *title, const char *description)