summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorManolo Gouy <Manolo>2017-11-13 21:41:33 +0000
committerManolo Gouy <Manolo>2017-11-13 21:41:33 +0000
commit15750ea378ff9f03826b400e217bbc754b16377f (patch)
treed5e549086b279dffa2b05d5afd364190782d80c2
parent00eef649ca4b71d1525328d502fb05d8868c720c (diff)
MacOS: Fix STR#3406 where native file chooser does not show preset file
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.4@12561 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
-rw-r--r--src/Fl_Native_File_Chooser_MAC.mm18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/Fl_Native_File_Chooser_MAC.mm b/src/Fl_Native_File_Chooser_MAC.mm
index bb09a1789..fa69d9ff2 100644
--- a/src/Fl_Native_File_Chooser_MAC.mm
+++ b/src/Fl_Native_File_Chooser_MAC.mm
@@ -602,8 +602,22 @@ int Fl_Quartz_Native_File_Chooser_Driver::runmodal()
}
if (_directory && !dir) dir = [[NSString alloc] initWithUTF8String:_directory];
if (fl_mac_os_version >= 100600) {
- if (dir) [(NSSavePanel*)_panel performSelector:@selector(setDirectoryURL:) withObject:[NSURL fileURLWithPath:dir]];
- if (fname) [(NSSavePanel*)_panel performSelector:@selector(setNameFieldStringValue:) withObject:fname];
+ if (dir && fname) {
+ // STR #3406: If both dir + fname specified, combine and pass to setDirectoryURL
+ NSString *path = [[NSString alloc] initWithFormat:@"%@/%@", dir, fname]; // dir+fname -> path
+ // See if full path to file exists
+ // If dir exists but fname doesn't, avoid using setDirectoryURL,
+ // otherwise NSSavePanel falls back to showing user's Documents dir.
+ //
+ if ( [[NSFileManager defaultManager] fileExistsAtPath:path] ) {
+ // Set only if full path exists
+ [(NSSavePanel*)_panel performSelector:@selector(setDirectoryURL:) withObject:[NSURL fileURLWithPath:path]];
+ } else { // didn't setDirectoryURL to full path? Set dir + fname separately..
+ if (dir) [(NSSavePanel*)_panel performSelector:@selector(setDirectoryURL:) withObject:[NSURL fileURLWithPath:dir]];
+ if (fname) [(NSSavePanel*)_panel performSelector:@selector(setNameFieldStringValue:) withObject:fname];
+ }
+ [path release];
+ }
retval = [(NSSavePanel*)_panel runModal];
}
else {