# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1320148518 0 # Node ID 40d62db77c90e38ba06ee753b858156c80de35fd # Parent d0c9d4d0ff3b9ccb03f5f61f734092aa34f0bb40 Added some defpath support and extension support to the Mac dw_file_browse(). Also switched to using URLs instead of deprecated filenames method. Filename support does not currently work on the open dialog. diff -r d0c9d4d0ff3b -r 40d62db77c90 mac/dw.m --- a/mac/dw.m Tue Nov 01 10:48:19 2011 +0000 +++ b/mac/dw.m Tue Nov 01 11:55:18 2011 +0000 @@ -3130,6 +3130,13 @@ { /* Create the File Open Dialog class. */ NSOpenPanel* openDlg = [NSOpenPanel openPanel]; + struct stat buf; + + if(defpath && stat(defpath, &buf) == 0) + { + if(buf.st_mode & S_IFDIR) + [openDlg setDirectoryURL:[NSURL URLWithString:[NSString stringWithUTF8String:defpath]]]; + } /* Enable the selection of files in the dialog. */ if(flags == DW_FILE_OPEN) @@ -3142,6 +3149,13 @@ [openDlg setCanChooseFiles:NO]; [openDlg setCanChooseDirectories:YES]; } + + /* Handle file types */ + if(ext) + { + NSArray* fileTypes = [[NSArray alloc] initWithObjects:[NSString stringWithUTF8String:ext], nil]; + [openDlg setAllowedFileTypes:fileTypes]; + } /* Disable multiple selection */ [openDlg setAllowsMultipleSelection:NO]; @@ -3154,19 +3168,36 @@ /* Get an array containing the full filenames of all * files and directories selected. */ - NSArray* files = [openDlg filenames]; - NSString* fileName = [files objectAtIndex:0]; - return strdup([ fileName UTF8String ]); + NSArray *files = [openDlg URLs]; + NSString *fileName = [[files objectAtIndex:0] path]; + if(fileName) + return strdup([ fileName UTF8String ]); } } else { /* Create the File Save Dialog class. */ NSSavePanel* saveDlg = [NSSavePanel savePanel]; + struct stat buf; + + if(defpath && stat(defpath, &buf) == 0) + { + if(buf.st_mode & S_IFDIR) + [saveDlg setDirectoryURL:[NSURL URLWithString:[NSString stringWithUTF8String:defpath]]]; + else + [saveDlg setNameFieldStringValue:[NSString stringWithUTF8String:defpath]]; + } /* Enable the creation of directories in the dialog. */ [saveDlg setCanCreateDirectories:YES]; + /* Handle file types */ + if(ext) + { + NSArray* fileTypes = [[NSArray alloc] initWithObjects:[NSString stringWithUTF8String:ext], nil]; + [saveDlg setAllowedFileTypes:fileTypes]; + } + /* Display the dialog. If the OK button was pressed, * process the files. */ @@ -3175,8 +3206,9 @@ /* Get an array containing the full filenames of all * files and directories selected. */ - NSString* fileName = [saveDlg filename]; - return strdup([ fileName UTF8String ]); + NSString* fileName = [[saveDlg URL] path]; + if(fileName) + return strdup([ fileName UTF8String ]); } }