mirror of
https://github.com/fltk/fltk.git
synced 2026-05-27 10:57:58 +08:00
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
This commit is contained in:
+43
-14
@@ -1287,24 +1287,48 @@ void
|
|||||||
Fl_File_Chooser::update_preview()
|
Fl_File_Chooser::update_preview()
|
||||||
{
|
{
|
||||||
const char *filename; // Current filename
|
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
|
*oldimage; // Old image
|
||||||
int pbw, pbh; // Width and height of preview box
|
int pbw, pbh; // Width and height of preview box
|
||||||
int w, h; // Width and height of preview image
|
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 (!previewButton->value()) return;
|
||||||
|
|
||||||
if ((filename = value()) == NULL || fl_filename_isdir(filename)) image = NULL;
|
filename = value();
|
||||||
else {
|
if (filename == NULL) {
|
||||||
window->cursor(FL_CURSOR_WAIT);
|
// no file name at all, so we have an empty preview
|
||||||
Fl::check();
|
set = 1;
|
||||||
|
} else if (fl_filename_isdir(filename)) {
|
||||||
image = Fl_Shared_Image::get(filename);
|
// filename is a directory, show a folder icon
|
||||||
|
newlabel = "@fileopen";
|
||||||
if (image) {
|
set = 1;
|
||||||
window->cursor(FL_CURSOR_DEFAULT);
|
} else {
|
||||||
Fl::check();
|
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);
|
previewBox->image(0);
|
||||||
|
|
||||||
if (!image) {
|
if (!set) {
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
int bytes;
|
int bytes;
|
||||||
char *ptr;
|
char *ptr;
|
||||||
@@ -1371,7 +1395,7 @@ Fl_File_Chooser::update_preview()
|
|||||||
// Non-printable file, just show a big ?...
|
// Non-printable file, just show a big ?...
|
||||||
previewBox->label(filename ? "?" : 0);
|
previewBox->label(filename ? "?" : 0);
|
||||||
previewBox->align(FL_ALIGN_CLIP);
|
previewBox->align(FL_ALIGN_CLIP);
|
||||||
previewBox->labelsize(100);
|
previewBox->labelsize(75);
|
||||||
previewBox->labelfont(FL_HELVETICA);
|
previewBox->labelfont(FL_HELVETICA);
|
||||||
} else {
|
} else {
|
||||||
// Show the first 1k of text...
|
// Show the first 1k of text...
|
||||||
@@ -1385,7 +1409,7 @@ Fl_File_Chooser::update_preview()
|
|||||||
previewBox->labelsize(size);
|
previewBox->labelsize(size);
|
||||||
previewBox->labelfont(FL_COURIER);
|
previewBox->labelfont(FL_COURIER);
|
||||||
}
|
}
|
||||||
} else {
|
} else if (image) {
|
||||||
pbw = previewBox->w() - 20;
|
pbw = previewBox->w() - 20;
|
||||||
pbh = previewBox->h() - 20;
|
pbh = previewBox->h() - 20;
|
||||||
|
|
||||||
@@ -1408,6 +1432,11 @@ Fl_File_Chooser::update_preview()
|
|||||||
|
|
||||||
previewBox->align(FL_ALIGN_CLIP);
|
previewBox->align(FL_ALIGN_CLIP);
|
||||||
previewBox->label(0);
|
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();
|
previewBox->redraw();
|
||||||
|
|||||||
Reference in New Issue
Block a user