Finish rewrite of Fl_File_Chooser2.cxx for the driver model.

git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3-porting@11591 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Manolo Gouy 2016-04-12 21:32:55 +00:00
parent 7e04657ce7
commit e74f213704
3 changed files with 13 additions and 107 deletions

View File

@ -172,6 +172,8 @@ public:
virtual int colon_is_drive() {return 0;}
// return TRUE means that files whose name begins with dot are hidden
virtual int dot_file_hidden() {return 0;}
// return TRUE when file names are case insensitive
virtual int case_insensitive_filenames() {return 0;}
};
#endif // FL_SYSTEM_DRIVER_H

View File

@ -356,31 +356,6 @@
#include <stdlib.h>
#include "flstring.h"
#include <errno.h>
#include <sys/types.h>
#if defined(WIN32) || defined(__APPLE__) // PORTME: Fl_Screen_Driver - platform file browser
#elif defined(FL_PORTING)
# pragma message "FL_PORTING: implement the internals of your filechooser here"
#else
#endif
/*#if defined(WIN32) && ! defined (__CYGWIN__)
# include <direct.h>
# include <io.h>
// Visual C++ 2005 incorrectly displays a warning about the use of POSIX APIs
// on Windows, which is supposed to be POSIX compliant...
# define access _access
# define mkdir _mkdir
// Apparently Borland C++ defines DIRECTORY in <direct.h>, which
// interfers with the Fl_File_Icon enumeration of the same name.
# ifdef DIRECTORY
# undef DIRECTORY
# endif // DIRECTORY
#else
# include <unistd.h>
# include <pwd.h>
#endif / * WIN32 */
//
// File chooser label strings and sort function...
@ -394,11 +369,6 @@ const char *Fl_File_Chooser::custom_filter_label = "Custom Filter";
const char *Fl_File_Chooser::existing_file_label = "Please choose an existing file!";
const char *Fl_File_Chooser::favorites_label = "Favorites";
const char *Fl_File_Chooser::filename_label = "Filename:";
/*#ifdef WIN32
const char *Fl_File_Chooser::filesystems_label = "My Computer";
#else
const char *Fl_File_Chooser::filesystems_label = "File Systems";
#endif // WIN32*/
const char *Fl_File_Chooser::filesystems_label = Fl::system_driver()->filesystems_label();
const char *Fl_File_Chooser::manage_favorites_label = "Manage Favorites";
const char *Fl_File_Chooser::new_directory_label = "New Directory?";
@ -472,7 +442,6 @@ Fl_File_Chooser::directory(const char *d)// I - Directory to change to
d = ".";
if (Fl::system_driver()->backslash_as_slash()) {
//#ifdef WIN32
// See if the filename contains backslashes...
char *slash; // Pointer to slashes
char fixpath[FL_PATH_MAX]; // Path with slashes converted
@ -486,17 +455,11 @@ Fl_File_Chooser::directory(const char *d)// I - Directory to change to
d = fixpath;
}
}
//#endif // WIN32
if (d[0] != '\0')
{
// Make the directory absolute...
/*#if (defined(WIN32) && ! defined(__CYGWIN__))|| defined(__EMX__)
if (d[0] != '/' && d[0] != '\\' && d[1] != ':')
} else {
#else*/
if (d[0] != '/' && d[0] != '\\' && ( !Fl::system_driver()->colon_is_drive() || d[1] != ':' ) )
//#endif /* WIN32 || __EMX__ */
fl_filename_absolute(directory_, d);
else
strlcpy(directory_, d, sizeof(directory_));
@ -724,12 +687,6 @@ Fl_File_Chooser::fileListCB()
}
if (Fl::event_clicks()) {
/*#if (defined(WIN32) && ! defined(__CYGWIN__)) || defined(__EMX__)
if ((strlen(pathname) == 2 && pathname[1] == ':') ||
Fl::system_driver()->filename_isdir_quick(pathname))
#else
if (Fl::system_driver()->filename_isdir_quick(pathname))
#endif / * WIN32 || __EMX__ */
int condition = 0;
if (Fl::system_driver()->colon_is_drive() && strlen(pathname) == 2 && pathname[1] == ':') condition = 1;
if (!condition) condition = Fl::system_driver()->filename_isdir_quick(pathname);
@ -841,13 +798,6 @@ Fl_File_Chooser::fileNameCB()
}
// Make sure we have an absolute path...
/*#if (defined(WIN32) && !defined(__CYGWIN__)) || defined(__EMX__)
if (directory_[0] != '\0' && filename[0] != '/' &&
filename[0] != '\\' &&
!(isalpha(filename[0] & 255) && (!filename[1] || filename[1] == ':'))) {
#else
if (directory_[0] != '\0' && filename[0] != '/') {
#endif / * WIN32 || __EMX__ */
int condition = directory_[0] != '\0' && filename[0] != '/';
if (condition && Fl::system_driver()->colon_is_drive()) condition = !(isalpha(filename[0] & 255) && (!filename[1] || filename[1] == ':'));
if (condition) {
@ -864,14 +814,6 @@ Fl_File_Chooser::fileNameCB()
// Now process things according to the key pressed...
if (Fl::event_key() == FL_Enter || Fl::event_key() == FL_KP_Enter) {
// Enter pressed - select or change directory...
/*#if (defined(WIN32) && ! defined(__CYGWIN__)) || defined(__EMX__)
if ((isalpha(pathname[0] & 255) && pathname[1] == ':' && !pathname[2]) ||
(Fl::system_driver()->filename_isdir_quick(pathname) &&
compare_dirnames(pathname, directory_))) {
#else
if (Fl::system_driver()->filename_isdir_quick(pathname) &&
compare_dirnames(pathname, directory_)) {
#endif / * WIN32 || __EMX__ */
int condition = 0;
if (Fl::system_driver()->colon_is_drive()) condition = isalpha(pathname[0] & 255) && pathname[1] == ':' && !pathname[2];
if (!condition) condition = ( Fl::system_driver()->filename_isdir_quick(pathname) && compare_dirnames(pathname, directory_) );
@ -905,13 +847,9 @@ Fl_File_Chooser::fileNameCB()
*slash++ = '\0';
filename = slash;
#if defined(WIN32) || defined(__EMX__)
if (strcasecmp(pathname, directory_) &&
(pathname[0] || strcasecmp("/", directory_))) {
#else
if (strcmp(pathname, directory_) &&
(pathname[0] || strcasecmp("/", directory_))) {
#endif // WIN32 || __EMX__
int condition = Fl::system_driver()->case_insensitive_filenames() ?
strcasecmp(pathname, directory_) : strcmp(pathname, directory_);
if (condition && (pathname[0] || strcmp("/", directory_))) {
int p = fileName->position();
int m = fileName->mark();
@ -937,11 +875,8 @@ Fl_File_Chooser::fileNameCB()
for (i = 1; i <= num_files && max_match > min_match; i ++) {
file = fileList->text(i);
#if (defined(WIN32) && ! defined(__CYGWIN__)) || defined(__EMX__)
if (strncasecmp(filename, file, min_match) == 0) {
#else
if (strncmp(filename, file, min_match) == 0) {
#endif // WIN32 || __EMX__
if ( (Fl::system_driver()->case_insensitive_filenames()?
strncasecmp(filename, file, min_match) : strncmp(filename, file, min_match)) == 0) {
// OK, this one matches; check against the previous match
if (!first_line) {
// First match; copy stuff over...
@ -960,11 +895,8 @@ Fl_File_Chooser::fileNameCB()
} else {
// Succeeding match; compare to find maximum string match...
while (max_match > min_match)
#if (defined(WIN32) && ! defined(__CYGWIN__)) || defined(__EMX__)
if (strncasecmp(file, matchname, max_match) == 0)
#else
if (strncmp(file, matchname, max_match) == 0)
#endif // WIN32 || __EMX__
if ( (Fl::system_driver()->case_insensitive_filenames()?
strncasecmp(file, matchname, max_match) : strncmp(file, matchname, max_match)) == 0)
break;
else
max_match --;
@ -1085,22 +1017,13 @@ Fl_File_Chooser::newdir()
return;
// Make it relative to the current directory as needed...
/*#if (defined(WIN32) && ! defined (__CYGWIN__)) || defined(__EMX__)
if (dir[0] != '/' && dir[0] != '\\' && dir[1] != ':')
#else
if (dir[0] != '/' && dir[0] != '\\')
#endif / * WIN32 || __EMX__ */
if (dir[0] != '/' && dir[0] != '\\' && (!Fl::system_driver()->colon_is_drive() || dir[1] != ':') )
snprintf(pathname, sizeof(pathname), "%s/%s", directory_, dir);
else
strlcpy(pathname, dir, sizeof(pathname));
// Create the directory; ignore EEXIST errors...
/*#if defined(WIN32) && ! defined (__CYGWIN__)
if (mkdir(pathname))
#else*/
if (fl_mkdir(pathname, 0777))
//#endif /* WIN32 */
if (errno != EEXIST)
{
fl_alert("%s", strerror(errno));
@ -1177,9 +1100,7 @@ Fl_File_Chooser::rescan()
// Build the file list...
fileList->load(directory_, sort);
//#ifndef WIN32
if (Fl::system_driver()->dot_file_hidden() && !showHiddenButton->value()) remove_hidden_files();
//#endif
// Update the preview box...
update_preview();
}
@ -1204,9 +1125,7 @@ void Fl_File_Chooser::rescan_keep_filename()
// Build the file list...
fileList->load(directory_, sort);
//#ifndef WIN32
if (Fl::system_driver()->dot_file_hidden() && !showHiddenButton->value()) remove_hidden_files();
//#endif
// Update the preview box...
update_preview();
@ -1218,11 +1137,7 @@ void Fl_File_Chooser::rescan_keep_filename()
else
slash = pathname;
for (i = 1; i <= fileList->size(); i ++)
#if defined(WIN32) || defined(__EMX__)
if (strcasecmp(fileList->text(i), slash) == 0) {
#else
if (strcmp(fileList->text(i), slash) == 0) {
#endif // WIN32 || __EMX__
if ( (Fl::system_driver()->case_insensitive_filenames() ? strcasecmp(fileList->text(i), slash) : strcmp(fileList->text(i), slash)) == 0) {
fileList->topline(i);
fileList->select(i);
found = 1;
@ -1560,7 +1475,6 @@ Fl_File_Chooser::value(const char *filename)
return;
}
//#ifdef WIN32
if (Fl::system_driver()->backslash_as_slash()) {
// See if the filename contains backslashes...
char fixpath[FL_PATH_MAX]; // Path with slashes converted
@ -1574,7 +1488,6 @@ Fl_File_Chooser::value(const char *filename)
filename = fixpath;
}
}
//#endif // WIN32
// See if there is a directory in there...
fl_filename_absolute(pathname, sizeof(pathname), filename);
@ -1604,11 +1517,7 @@ Fl_File_Chooser::value(const char *filename)
fileList->redraw();
for (i = 1; i <= fcount; i ++)
#if defined(WIN32) || defined(__EMX__)
if (strcasecmp(fileList->text(i), slash) == 0) {
#else
if (strcmp(fileList->text(i), slash) == 0) {
#endif // WIN32 || __EMX__
if ( ( Fl::system_driver()->case_insensitive_filenames() ? strcasecmp(fileList->text(i), slash) : strcmp(fileList->text(i), slash)) == 0) {
// printf("Selecting line %d...\n", i);
fileList->topline(i);
fileList->select(i);
@ -1625,9 +1534,7 @@ void Fl_File_Chooser::show()
rescan_keep_filename();
fl_cursor(FL_CURSOR_DEFAULT);
fileName->take_focus();
//#ifdef WIN32
if (!Fl::system_driver()->dot_file_hidden()) showHiddenButton->hide();
//#endif
}
void Fl_File_Chooser::showHidden(int value)
@ -1673,11 +1580,7 @@ compare_dirnames(const char *a, const char *b) {
if (alen != blen) return alen - blen;
// Do a comparison of the first N chars (alen == blen at this point)...
#ifdef WIN32
return strncasecmp(a, b, alen);
#else
return strncmp(a, b, alen);
#endif // WIN32
return Fl::system_driver()->case_insensitive_filenames() ? strncasecmp(a, b, alen) : strncmp(a, b, alen);
}

View File

@ -101,6 +101,7 @@ public:
virtual const char *filesystems_label() { return "My Computer"; }
virtual int backslash_as_slash() {return 1;}
virtual int colon_is_drive() {return 1;}
virtual int case_insensitive_filenames() {return 1;}
};
#endif // FL_WINAPI_SYSTEM_DRIVER_H