# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1320142908 0 # Node ID 4bc8b6ffbe1eab3a94809f1cb2ecd870b4ebeddd # Parent 0712ee0f311e4e20ffff7e99e898d34e51bb11a7 Code changes to enable default filename on Windows with dw_file_browse(). Also added an example in the test program. diff -r 0712ee0f311e -r 4bc8b6ffbe1e dwtest.c --- a/dwtest.c Tue Nov 01 06:01:26 2011 +0000 +++ b/dwtest.c Tue Nov 01 10:21:48 2011 +0000 @@ -591,7 +591,7 @@ int DWSIGNAL browse_file_callback(HWND window, void *data) { char *tmp; - tmp = dw_file_browse("Pick a file", ".", "c", DW_FILE_OPEN ); + tmp = dw_file_browse("Pick a file", "dwtest.c", "c", DW_FILE_OPEN ); if ( tmp ) { if ( current_file ) diff -r 0712ee0f311e -r 4bc8b6ffbe1e win/dw.c --- a/win/dw.c Tue Nov 01 06:01:26 2011 +0000 +++ b/win/dw.c Tue Nov 01 10:21:48 2011 +0000 @@ -10147,6 +10147,22 @@ #endif } +/* Helper to make sure all /s are \s */ +void _to_dos(char *dst, char *src) +{ + int x = 0; + + while(src[x]) + { + if(src[x] == '/') + dst[x] = '\\'; + else + dst[x] = src[x]; + x++; + } + dst[x] = 0; +} + /* * Opens a file dialog and queries user selection. * Parameters: @@ -10214,6 +10230,8 @@ } else { + DWORD att = defpath ? GetFileAttributes(defpath) : INVALID_FILE_ATTRIBUTES; + if (ext) { /* @@ -10237,13 +10255,16 @@ of.lStructSize = sizeof(OPENFILENAME); of.hwndOwner = HWND_DESKTOP; of.hInstance = DWInstance; - of.lpstrInitialDir = defpath; of.lpstrTitle = title; + if(att != INVALID_FILE_ATTRIBUTES && (att & FILE_ATTRIBUTE_DIRECTORY)) + of.lpstrInitialDir = defpath; + else if(defpath) + _to_dos(filenamebuf, defpath); of.lpstrFile = filenamebuf; of.lpstrFilter = filterbuf; of.nFilterIndex = 1; of.nMaxFile = 1000; - //of.lpstrDefExt = ext; + /*of.lpstrDefExt = ext;*/ of.Flags = OFN_NOCHANGEDIR; if (flags & DW_FILE_SAVE)