fix #3234 native open window crash problem at OSX

since default_filename will be null at opening(code set default_filename only at save), setting filePath with default_filename will raise exception.

Fixed by setting filePath, basename only at save(since two vars only used at creating nameFieldStringValue) and setting directory with initial_directory at opening.
This commit is contained in:
YJSoft authored and Ted John committed 2016-04-04 07:25:33 +01:00
1 parent 49772db412
commit c5ff5a3ce9
1 file changed
+5 -4
+5 -4
View File
@@ -143,18 +143,19 @@ bool platform_open_common_file_dialog(utf8 *outFilename, file_dialog_desc *desc)
}
}
NSString *filePath = [NSString stringWithUTF8String:desc->default_filename];
NSString *directory = filePath.stringByDeletingLastPathComponent;
NSString *basename = filePath.lastPathComponent;
NSString *directory;
NSSavePanel *panel;
if (desc->type == FD_SAVE)
{
NSString *filePath = [NSString stringWithUTF8String:desc->default_filename];
directory = filePath.stringByDeletingLastPathComponent;
NSString *basename = filePath.lastPathComponent;
panel = [NSSavePanel savePanel];
panel.nameFieldStringValue = [NSString stringWithFormat:@"%@.%@", basename, extensions.firstObject];
}
else if (desc->type == FD_OPEN)
{
directory = [NSString stringWithUTF8String:desc->initial_directory];
NSOpenPanel *open = [NSOpenPanel openPanel];
open.canChooseDirectories = false;
open.canChooseFiles = true;