diff options
| author | Michael R Sweet <michael.r.sweet@gmail.com> | 2005-05-13 03:16:30 +0000 |
|---|---|---|
| committer | Michael R Sweet <michael.r.sweet@gmail.com> | 2005-05-13 03:16:30 +0000 |
| commit | 2c8fc6f66aaea63087979ca411cfa0d68abdca3c (patch) | |
| tree | e54bb143913e26ca923ee730ebe5fa289c737159 | |
| parent | 5ca7674da3692509b0ee79aaee78d51b3a7d3c61 (diff) | |
Fl_File_Chooser::value() and ::directory() now handle paths with
backslashes on WIN32 (STR #811)
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@4346 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
| -rw-r--r-- | CHANGES | 2 | ||||
| -rw-r--r-- | src/Fl_File_Chooser2.cxx | 44 |
2 files changed, 37 insertions, 9 deletions
@@ -2,6 +2,8 @@ CHANGES IN FLTK 1.1.7 - Documentation fixes (STR #648, STR #692, STR #730, STR #744, STR #745) + - Fl_File_Chooser::value() and ::directory() now handle + paths with backslashes on WIN32 (STR #811) - Added the standard rgb.txt file from X11 to the test directory, allowing all platforms to try the colbrowser demo (STR #843) diff --git a/src/Fl_File_Chooser2.cxx b/src/Fl_File_Chooser2.cxx index d199215f4..aa8bf6a58 100644 --- a/src/Fl_File_Chooser2.cxx +++ b/src/Fl_File_Chooser2.cxx @@ -158,6 +158,20 @@ Fl_File_Chooser::directory(const char *d)// I - Directory to change to if (d == NULL) d = "."; +#ifdef WIN32 + // See if the filename contains backslashes... + char fixpath[1024]; // Path with slashes converted + if (strchr(d, '\\')) { + // Convert backslashes to slashes... + strlcpy(fixpath, d, sizeof(fixpath)); + + for (slash = strchr(fixpath, '\\'); slash; slash = strchr(slash + 1, '\\')) + *slash = '/'; + + d = fixpath; + } +#endif // WIN32 + if (d[0] != '\0') { // Make the directory absolute... @@ -1071,12 +1085,13 @@ Fl_File_Chooser::value(int f) // I - File number // void -Fl_File_Chooser::value(const char *filename) // I - Filename + directory +Fl_File_Chooser::value(const char *filename) + // I - Filename + directory { - int i, // Looping var - fcount; // Number of items in list - char *slash; // Directory separator - char pathname[1024]; // Local copy of filename + int i, // Looping var + fcount; // Number of items in list + char *slash; // Directory separator + char pathname[1024]; // Local copy of filename // printf("Fl_File_Chooser::value(\"%s\")\n", filename == NULL ? "(null)" : filename); @@ -1090,13 +1105,24 @@ Fl_File_Chooser::value(const char *filename) // I - Filename + directory return; } +#ifdef WIN32 + // See if the filename contains backslashes... + char fixpath[1024]; // Path with slashes converted + if (strchr(filename, '\\')) { + // Convert backslashes to slashes... + strlcpy(fixpath, filename, sizeof(fixpath)); + + for (slash = strchr(fixpath, '\\'); slash; slash = strchr(slash + 1, '\\')) + *slash = '/'; + + filename = fixpath; + } +#endif // WIN32 + // See if there is a directory in there... fl_filename_absolute(pathname, sizeof(pathname), filename); - if ((slash = strrchr(pathname, '/')) == NULL) - slash = strrchr(pathname, '\\'); - - if (slash != NULL) { + if ((slash = strrchr(pathname, '/')) != NULL) { // Yes, change the display to the directory... if (!fl_filename_isdir(pathname)) *slash++ = '\0'; |
