From ae0a956f2e7ad36f5aab55aa030d6a0d9a82d97b Mon Sep 17 00:00:00 2001 From: Michael R Sweet Date: Thu, 2 May 2002 14:31:10 +0000 Subject: [PATCH] Add sort function as optional argument to Fl_File_Browser::load(). Add docos for sort functions and changes to fl_filename_list() and Fl_File_Browser::load(). git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@2176 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- FL/Fl_File_Browser.H | 7 +++--- documentation/Fl_File_Browser.html | 5 ++++- documentation/functions.html | 36 ++++++++++++++++++++++++++---- src/Fl_File_Browser.cxx | 35 +++++++++++++++-------------- 4 files changed, 58 insertions(+), 25 deletions(-) diff --git a/FL/Fl_File_Browser.H b/FL/Fl_File_Browser.H index c312077cd..67c33e179 100644 --- a/FL/Fl_File_Browser.H +++ b/FL/Fl_File_Browser.H @@ -1,5 +1,5 @@ // -// "$Id: Fl_File_Browser.H,v 1.1.2.2 2002/01/01 15:11:27 easysw Exp $" +// "$Id: Fl_File_Browser.H,v 1.1.2.3 2002/05/02 14:31:10 easysw Exp $" // // FileBrowser definitions. // @@ -32,6 +32,7 @@ # include "Fl_Browser.H" # include "Fl_File_Icon.H" +# include "filename.H" // @@ -62,7 +63,7 @@ public: FL_EXPORT void filter(const char *pattern); const char *filter() const { return (pattern_); }; - FL_EXPORT int load(const char *directory); + FL_EXPORT int load(const char *directory, Fl_File_Sort_F *sort = fl_numericsort); uchar textsize() const { return (Fl_Browser::textsize()); }; void textsize(uchar s) { Fl_Browser::textsize(s); iconsize_ = 3 * s / 2; }; @@ -74,5 +75,5 @@ public: #endif // !_Fl_File_Browser_H_ // -// End of "$Id: Fl_File_Browser.H,v 1.1.2.2 2002/01/01 15:11:27 easysw Exp $". +// End of "$Id: Fl_File_Browser.H,v 1.1.2.3 2002/05/02 14:31:10 easysw Exp $". // diff --git a/documentation/Fl_File_Browser.html b/documentation/Fl_File_Browser.html index 6137bdddc..82447904a 100644 --- a/documentation/Fl_File_Browser.html +++ b/documentation/Fl_File_Browser.html @@ -69,10 +69,13 @@ int filetype() const files and directories are shown. Otherwise only directories are shown. -

int load(const char *directory)

+

int load(const char *directory, Fl_File_Sort_F *sort = fl_numeric_sort)

Loads the specified directory into the browser. If icons have been loaded then the correct icon is associated with each file in the list. +

The sort argument specifies a sort function to be used with +fl_filename_list(). + diff --git a/documentation/functions.html b/documentation/functions.html index 24d42a23d..f35a31fbe 100644 --- a/documentation/functions.html +++ b/documentation/functions.html @@ -579,7 +579,7 @@ int fl_filename_isdir(const char *f);

Prototype

Description

@@ -595,9 +595,37 @@ pointer to the array is returned in *list. The number of entries is given as a return value. If there is an error reading the directory a number less than zero is returned, and errno has the reason; errno does not work -under WIN32. The files are sorted in "alphanumeric" -order, where an attempt is made to put unpadded numbers in -consecutive order. +under WIN32. + +

The sort argument specifies a sort function to be used +when on the array of filenames. The following standard sort functions +are provided with FLTK: + +

You can free the returned list of files with the following code: diff --git a/src/Fl_File_Browser.cxx b/src/Fl_File_Browser.cxx index c5b7835a7..06a5b2ba3 100644 --- a/src/Fl_File_Browser.cxx +++ b/src/Fl_File_Browser.cxx @@ -1,5 +1,5 @@ // -// "$Id: Fl_File_Browser.cxx,v 1.1.2.13 2002/05/01 20:05:19 easysw Exp $" +// "$Id: Fl_File_Browser.cxx,v 1.1.2.14 2002/05/02 14:31:10 easysw Exp $" // // Fl_File_Browser routines. // @@ -24,13 +24,13 @@ // // Contents: // -// Fl_File_Browser::full_height() - Return the height of the list. -// Fl_File_Browser::item_height() - Return the height of a list item. -// Fl_File_Browser::item_width() - Return the width of a list item. -// Fl_File_Browser::item_draw() - Draw a list item. +// Fl_File_Browser::full_height() - Return the height of the list. +// Fl_File_Browser::item_height() - Return the height of a list item. +// Fl_File_Browser::item_width() - Return the width of a list item. +// Fl_File_Browser::item_draw() - Draw a list item. // Fl_File_Browser::Fl_File_Browser() - Create a Fl_File_Browser widget. -// Fl_File_Browser::load() - Load a directory into the browser. -// Fl_File_Browser::filter() - Set the filename filter. +// Fl_File_Browser::load() - Load a directory into the browser. +// Fl_File_Browser::filter() - Set the filename filter. // // @@ -394,14 +394,15 @@ Fl_File_Browser::Fl_File_Browser(int x, // I - Upper-lefthand X coordinat // 'Fl_File_Browser::load()' - Load a directory into the browser. // -int // O - Number of files loaded -Fl_File_Browser::load(const char *directory)// I - Directory to load +int // O - Number of files loaded +Fl_File_Browser::load(const char *directory,// I - Directory to load + Fl_File_Sort_F *sort) // I - Sort function to use { - int i; // Looping var - int num_files; // Number of files in directory - int num_dirs; // Number of directories in list - char filename[4096]; // Current file - Fl_File_Icon *icon; // Icon to use + int i; // Looping var + int num_files; // Number of files in directory + int num_dirs; // Number of directories in list + char filename[4096]; // Current file + Fl_File_Icon *icon; // Icon to use // printf("Fl_File_Browser::load(\"%s\")\n", directory); @@ -559,9 +560,9 @@ Fl_File_Browser::load(const char *directory)// I - Directory to load else if (filename[i] != '/' && filename[i] != '\\') strcat(filename, "/"); - num_files = fl_filename_list(filename, &files); + num_files = fl_filename_list(filename, &files, sort); #else - num_files = fl_filename_list(directory_, &files); + num_files = fl_filename_list(directory_, &files, sort); #endif /* WIN32 || __EMX__ */ if (num_files <= 0) @@ -626,5 +627,5 @@ Fl_File_Browser::filter(const char *pattern) // I - Pattern string // -// End of "$Id: Fl_File_Browser.cxx,v 1.1.2.13 2002/05/01 20:05:19 easysw Exp $". +// End of "$Id: Fl_File_Browser.cxx,v 1.1.2.14 2002/05/02 14:31:10 easysw Exp $". //