changeset 1294:4bc8b6ffbe1e

Code changes to enable default filename on Windows with dw_file_browse(). Also added an example in the test program.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 01 Nov 2011 10:21:48 +0000
parents 0712ee0f311e
children d0c9d4d0ff3b
files dwtest.c win/dw.c
diffstat 2 files changed, 24 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- 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 )
--- 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)