summaryrefslogtreecommitdiff
path: root/src/Fl_File_Chooser2.cxx
diff options
context:
space:
mode:
authorMatthias Melcher <fltk@matthiasm.com>2010-01-26 10:22:49 +0000
committerMatthias Melcher <fltk@matthiasm.com>2010-01-26 10:22:49 +0000
commitc83c17031012836902ca9fd4ee791e2c385ae767 (patch)
treeaf918ee676663f174ad6e84fecbd8dd68ddc4b34 /src/Fl_File_Chooser2.cxx
parent8af182fe51e35767ac1735d86390a7f3a6df19b7 (diff)
File chooser in preview mode would hand if user selected a special file in the /dev directory. It now shows a recycle symbol and also displays a folder and an empty file message. Untested on anything but OS X - sorry!
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@7031 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/Fl_File_Chooser2.cxx')
-rw-r--r--src/Fl_File_Chooser2.cxx57
1 files changed, 43 insertions, 14 deletions
diff --git a/src/Fl_File_Chooser2.cxx b/src/Fl_File_Chooser2.cxx
index 4f89cfa25..e785c3be2 100644
--- a/src/Fl_File_Chooser2.cxx
+++ b/src/Fl_File_Chooser2.cxx
@@ -1287,24 +1287,48 @@ void
Fl_File_Chooser::update_preview()
{
const char *filename; // Current filename
- Fl_Shared_Image *image, // New image
+ const char *newlabel = 0; // New label text
+ Fl_Shared_Image *image = 0, // New image
*oldimage; // Old image
int pbw, pbh; // Width and height of preview box
int w, h; // Width and height of preview image
+ int set = 0; // Set this flag as soon as a decent preview is found
if (!previewButton->value()) return;
- if ((filename = value()) == NULL || fl_filename_isdir(filename)) image = NULL;
- else {
- window->cursor(FL_CURSOR_WAIT);
- Fl::check();
-
- image = Fl_Shared_Image::get(filename);
-
- if (image) {
- window->cursor(FL_CURSOR_DEFAULT);
- Fl::check();
+ filename = value();
+ if (filename == NULL) {
+ // no file name at all, so we have an empty preview
+ set = 1;
+ } else if (fl_filename_isdir(filename)) {
+ // filename is a directory, show a folder icon
+ newlabel = "@fileopen";
+ set = 1;
+ } else {
+ struct stat s;
+ if (fl_stat(filename, &s)==0) {
+ if ((s.st_mode&S_IFMT)!=S_IFREG) {
+ // this is no regular file, probably some kind of device
+ newlabel = "@-3refresh"; // a cross
+ set = 1;
+ } else if (s.st_size==0) {
+ // this file is emty
+ newlabel = "<empty file>";
+ set = 1;
+ } else {
+ // if this file is an image, try to load it
+ window->cursor(FL_CURSOR_WAIT);
+ Fl::check();
+
+ image = Fl_Shared_Image::get(filename);
+
+ if (image) {
+ window->cursor(FL_CURSOR_DEFAULT);
+ Fl::check();
+ set = 1;
+ }
+ }
}
}
@@ -1314,7 +1338,7 @@ Fl_File_Chooser::update_preview()
previewBox->image(0);
- if (!image) {
+ if (!set) {
FILE *fp;
int bytes;
char *ptr;
@@ -1371,7 +1395,7 @@ Fl_File_Chooser::update_preview()
// Non-printable file, just show a big ?...
previewBox->label(filename ? "?" : 0);
previewBox->align(FL_ALIGN_CLIP);
- previewBox->labelsize(100);
+ previewBox->labelsize(75);
previewBox->labelfont(FL_HELVETICA);
} else {
// Show the first 1k of text...
@@ -1385,7 +1409,7 @@ Fl_File_Chooser::update_preview()
previewBox->labelsize(size);
previewBox->labelfont(FL_COURIER);
}
- } else {
+ } else if (image) {
pbw = previewBox->w() - 20;
pbh = previewBox->h() - 20;
@@ -1408,6 +1432,11 @@ Fl_File_Chooser::update_preview()
previewBox->align(FL_ALIGN_CLIP);
previewBox->label(0);
+ } else if (newlabel) {
+ previewBox->label(newlabel);
+ previewBox->align(FL_ALIGN_CLIP);
+ previewBox->labelsize(newlabel[0]=='@'?75:12);
+ previewBox->labelfont(FL_HELVETICA);
}
previewBox->redraw();