Added "Show hidden files" check button to the file chooser panel.

This had been previously done in r.8282 and r.8286 without accounting for
the existence of the Fl_File_Chooser.fl file. With this commit, files
Fl_File_Chooser.{cxx, H} are properly generated by Fl_File_Chooser.fl

git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@8785 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Manolo Gouy
2011-06-06 16:11:22 +00:00
parent 9223527992
commit 7feb5a9dfe
4 changed files with 124 additions and 108 deletions

View File

@@ -95,6 +95,11 @@ public:
private: private:
void cb_previewButton_i(Fl_Check_Button*, void*); void cb_previewButton_i(Fl_Check_Button*, void*);
static void cb_previewButton(Fl_Check_Button*, void*); static void cb_previewButton(Fl_Check_Button*, void*);
public:
Fl_Check_Button *showHiddenButton;
private:
void cb_showHiddenButton_i(Fl_Check_Button*, void*);
static void cb_showHiddenButton(Fl_Check_Button*, void*);
Fl_File_Input *fileName; Fl_File_Input *fileName;
void cb_fileName_i(Fl_File_Input*, void*); void cb_fileName_i(Fl_File_Input*, void*);
static void cb_fileName(Fl_File_Input*, void*); static void cb_fileName(Fl_File_Input*, void*);
@@ -123,11 +128,6 @@ private:
Fl_Return_Button *favOkButton; Fl_Return_Button *favOkButton;
void cb_favOkButton_i(Fl_Return_Button*, void*); void cb_favOkButton_i(Fl_Return_Button*, void*);
static void cb_favOkButton(Fl_Return_Button*, void*); static void cb_favOkButton(Fl_Return_Button*, void*);
#ifndef WIN32
Fl_Check_Button *show_hidden;
static void show_hidden_cb(Fl_Check_Button*, void*);
void remove_hidden_files();
#endif
public: public:
~Fl_File_Chooser(); ~Fl_File_Chooser();
void callback(void (*cb)(Fl_File_Chooser *, void *), void *d = 0); void callback(void (*cb)(Fl_File_Chooser *, void *), void *d = 0);
@@ -149,9 +149,13 @@ public:
const char * ok_label(); const char * ok_label();
void preview(int e); void preview(int e);
int preview() const { return previewButton->value(); }; int preview() const { return previewButton->value(); };
private:
void showHidden(int e);
void remove_hidden_files();
public:
void rescan(); void rescan();
void rescan_keep_filename(); void rescan_keep_filename();
void show(); void show();
int shown(); int shown();
void textcolor(Fl_Color c); void textcolor(Fl_Color c);
Fl_Color textcolor(); Fl_Color textcolor();
@@ -218,10 +222,10 @@ public:
[standard text may be customized at run-time] [standard text may be customized at run-time]
*/ */
static const char *show_label; static const char *show_label;
/** /**
[standard text may be customized at run-time] [standard text may be customized at run-time]
*/ */
static const char *hidden_label; static const char *hidden_label;
/** /**
the sort function that is used when loading the sort function that is used when loading
the contents of a directory. the contents of a directory.
@@ -231,7 +235,6 @@ private:
Fl_Widget* ext_group; Fl_Widget* ext_group;
public: public:
Fl_Widget* add_extra(Fl_Widget* gr); Fl_Widget* add_extra(Fl_Widget* gr);
Fl_File_Browser *browser(void) {return fileList; };
}; };
FL_EXPORT char *fl_dir_chooser(const char *message,const char *fname,int relative=0); FL_EXPORT char *fl_dir_chooser(const char *message,const char *fname,int relative=0);
FL_EXPORT char *fl_file_chooser(const char *message,const char *pat,const char *fname,int relative=0); FL_EXPORT char *fl_file_chooser(const char *message,const char *pat,const char *fname,int relative=0);

View File

@@ -87,27 +87,14 @@ void Fl_File_Chooser::cb_previewButton_i(Fl_Check_Button*, void*) {
void Fl_File_Chooser::cb_previewButton(Fl_Check_Button* o, void* v) { void Fl_File_Chooser::cb_previewButton(Fl_Check_Button* o, void* v) {
((Fl_File_Chooser*)(o->parent()->parent()->parent()->user_data()))->cb_previewButton_i(o,v); ((Fl_File_Chooser*)(o->parent()->parent()->parent()->user_data()))->cb_previewButton_i(o,v);
} }
#ifndef WIN32
void Fl_File_Chooser::remove_hidden_files() void Fl_File_Chooser::cb_showHiddenButton_i(Fl_Check_Button*, void*) {
{ showHidden(showHiddenButton->value());
int count = fileList->size(); }
for(int num = count; num >= 1; num--) { void Fl_File_Chooser::cb_showHiddenButton(Fl_Check_Button* o, void* v) {
const char *p = fileList->text(num); ((Fl_File_Chooser*)(o->parent()->parent()->parent()->user_data()))->cb_showHiddenButton_i(o,v);
if (*p == '.' && strcmp(p, "../") != 0) fileList->remove(num);
}
fileList->topline(1);
} }
void Fl_File_Chooser::show_hidden_cb(Fl_Check_Button* o, void* data) {
Fl_File_Chooser *mychooser = (Fl_File_Chooser *)data;
if (o->value()) {
mychooser->browser()->load(mychooser->directory());
} else {
mychooser->remove_hidden_files();
mychooser->browser()->redraw();
}
}
#endif
void Fl_File_Chooser::cb_fileName_i(Fl_File_Input*, void*) { void Fl_File_Chooser::cb_fileName_i(Fl_File_Input*, void*) {
fileNameCB(); fileNameCB();
} }
@@ -228,15 +215,11 @@ Fl_File_Chooser::Fl_File_Chooser(const char *d, const char *p, int t, const char
previewButton->callback((Fl_Callback*)cb_previewButton); previewButton->callback((Fl_Callback*)cb_previewButton);
previewButton->label(preview_label); previewButton->label(preview_label);
} // Fl_Check_Button* previewButton } // Fl_Check_Button* previewButton
#ifndef WIN32 { showHiddenButton = new Fl_Check_Button(115, 275, 165, 20, "Show hidden files");
{ show_hidden = new Fl_Check_Button( showHiddenButton->down_box(FL_DOWN_BOX);
previewButton->x() + previewButton->w() + 30, 275, 140, 20, "Show hidden files"); showHiddenButton->callback((Fl_Callback*)cb_showHiddenButton);
show_hidden->down_box(FL_DOWN_BOX); showHiddenButton->label(hidden_label);
show_hidden->value(0); } // Fl_Check_Button* showHiddenButton
show_hidden->callback((Fl_Callback*)show_hidden_cb, this);
show_hidden->label(hidden_label);
} // Fl_Check_Button* show_hidden
#endif
{ Fl_Box* o = new Fl_Box(115, 275, 365, 20); { Fl_Box* o = new Fl_Box(115, 275, 365, 20);
Fl_Group::current()->resizable(o); Fl_Group::current()->resizable(o);
} // Fl_Box* o } // Fl_Box* o
@@ -315,31 +298,31 @@ Fl_File_Chooser::Fl_File_Chooser(const char *d, const char *p, int t, const char
favWindow->end(); favWindow->end();
} // Fl_Double_Window* favWindow } // Fl_Double_Window* favWindow
callback_ = 0; callback_ = 0;
data_ = 0; data_ = 0;
directory_[0] = 0; directory_[0] = 0;
window->size_range(window->w(), window->h(), Fl::w(), Fl::h()); window->size_range(window->w(), window->h(), Fl::w(), Fl::h());
type(t); type(t);
filter(p); filter(p);
update_favorites(); update_favorites();
value(d); value(d);
type(t); type(t);
int e; int e;
prefs_.get("preview", e, 1); prefs_.get("preview", e, 1);
preview(e); preview(e);
Fl_Group::current(prev_current); Fl_Group::current(prev_current);
ext_group=(Fl_Widget*)0; ext_group=(Fl_Widget*)0;
} }
Fl_File_Chooser::~Fl_File_Chooser() { Fl_File_Chooser::~Fl_File_Chooser() {
Fl::remove_timeout((Fl_Timeout_Handler)previewCB, this); Fl::remove_timeout((Fl_Timeout_Handler)previewCB, this);
if(ext_group)window->remove(ext_group); if(ext_group)window->remove(ext_group);
delete window; delete window;
delete favWindow; delete favWindow;
} }
void Fl_File_Chooser::callback(void (*cb)(Fl_File_Chooser *, void *), void *d ) { void Fl_File_Chooser::callback(void (*cb)(Fl_File_Chooser *, void *), void *d ) {
callback_ = cb; callback_ = cb;
data_ = d; data_ = d;
} }
void Fl_File_Chooser::color(Fl_Color c) { void Fl_File_Chooser::color(Fl_Color c) {
@@ -364,7 +347,7 @@ int Fl_File_Chooser::filter_value() {
void Fl_File_Chooser::filter_value(int f) { void Fl_File_Chooser::filter_value(int f) {
showChoice->value(f); showChoice->value(f);
showChoiceCB(); showChoiceCB();
} }
void Fl_File_Chooser::hide() { void Fl_File_Chooser::hide() {
@@ -389,27 +372,17 @@ const char * Fl_File_Chooser::label() {
void Fl_File_Chooser::ok_label(const char *l) { void Fl_File_Chooser::ok_label(const char *l) {
okButton->label(l); okButton->label(l);
int w=0, h=0; int w=0, h=0;
okButton->measure_label(w, h); okButton->measure_label(w, h);
okButton->resize(cancelButton->x() - 50 - w, cancelButton->y(), okButton->resize(cancelButton->x() - 50 - w, cancelButton->y(),
w + 40, 25); w + 40, 25);
okButton->parent()->init_sizes(); okButton->parent()->init_sizes();
} }
const char * Fl_File_Chooser::ok_label() { const char * Fl_File_Chooser::ok_label() {
return (okButton->label()); return (okButton->label());
} }
void Fl_File_Chooser::show() {
window->hotspot(fileList);
window->show();
Fl::flush();
fl_cursor(FL_CURSOR_WAIT);
rescan_keep_filename();
fl_cursor(FL_CURSOR_DEFAULT);
fileName->take_focus();
}
int Fl_File_Chooser::shown() { int Fl_File_Chooser::shown() {
return window->shown(); return window->shown();
} }
@@ -440,18 +413,18 @@ Fl_Fontsize Fl_File_Chooser::textsize() {
void Fl_File_Chooser::type(int t) { void Fl_File_Chooser::type(int t) {
type_ = t; type_ = t;
if (t & MULTI) if (t & MULTI)
fileList->type(FL_MULTI_BROWSER); fileList->type(FL_MULTI_BROWSER);
else else
fileList->type(FL_HOLD_BROWSER); fileList->type(FL_HOLD_BROWSER);
if (t & CREATE) if (t & CREATE)
newButton->activate(); newButton->activate();
else else
newButton->deactivate(); newButton->deactivate();
if (t & DIRECTORY) if (t & DIRECTORY)
fileList->filetype(Fl_File_Browser::DIRECTORIES); fileList->filetype(Fl_File_Browser::DIRECTORIES);
else else
fileList->filetype(Fl_File_Browser::FILES); fileList->filetype(Fl_File_Browser::FILES);
} }
int Fl_File_Chooser::type() { int Fl_File_Chooser::type() {
@@ -477,22 +450,22 @@ Fl_Widget* Fl_File_Chooser::add_extra(Fl_Widget* gr) {
} }
if (ext_group) { if (ext_group) {
int sh=ext_group->h()+4; int sh=ext_group->h()+4;
Fl_Widget* svres=window->resizable(); Fl_Widget* svres=window->resizable();
window->resizable(NULL); window->resizable(NULL);
window->size(window->w(),window->h()-sh); window->size(window->w(),window->h()-sh);
window->remove(ext_group); window->remove(ext_group);
ext_group=NULL; ext_group=NULL;
window->resizable(svres); window->resizable(svres);
} }
if (gr) { if (gr) {
int nh=window->h()+gr->h()+4; int nh=window->h()+gr->h()+4;
Fl_Widget* svres=window->resizable(); Fl_Widget* svres=window->resizable();
window->resizable(NULL); window->resizable(NULL);
window->size(window->w(),nh); window->size(window->w(),nh);
gr->position(2,okButton->y()+okButton->h()+2); gr->position(2,okButton->y()+okButton->h()+2);
window->add(gr); window->add(gr);
ext_group=gr; ext_group=gr;
window->resizable(svres); window->resizable(svres);
} }
return ret; return ret;
} }

View File

@@ -40,8 +40,8 @@ class FL_EXPORT Fl_File_Chooser {open
decl {static Fl_Preferences prefs_;} {} decl {static Fl_Preferences prefs_;} {}
decl {void (*callback_)(Fl_File_Chooser*, void *);} {} decl {void (*callback_)(Fl_File_Chooser*, void *);} {}
decl {void *data_;} {} decl {void *data_;} {}
decl {char directory_[1024];} {} decl {char directory_[FL_PATH_MAX];} {}
decl {char pattern_[1024];} {} decl {char pattern_[FL_PATH_MAX];} {}
decl {char preview_text_[2048];} {} decl {char preview_text_[2048];} {}
decl {int type_;} {} decl {int type_;} {}
decl {void favoritesButtonCB();} {} decl {void favoritesButtonCB();} {}
@@ -115,6 +115,12 @@ window->hide();} open
xywh {10 275 73 20} down_box DOWN_BOX shortcut 0x80070 value 1 xywh {10 275 73 20} down_box DOWN_BOX shortcut 0x80070 value 1
code0 {previewButton->label(preview_label);} code0 {previewButton->label(preview_label);}
} }
Fl_Check_Button showHiddenButton {
label {Show hidden files}
callback {showHidden(showHiddenButton->value());}
xywh {115 275 165 20} down_box DOWN_BOX
code0 {showHiddenButton->label(hidden_label);}
}
Fl_Box {} { Fl_Box {} {
private xywh {115 275 365 20} resizable private xywh {115 275 365 20} resizable
} }
@@ -301,19 +307,15 @@ okButton->parent()->init_sizes();} {}
} }
decl {int preview() const { return previewButton->value(); }} {public decl {int preview() const { return previewButton->value(); }} {public
} }
decl {void showHidden(int e);} {private
}
decl {void remove_hidden_files();} {private
}
decl {void rescan();} {public decl {void rescan();} {public
} }
decl {void rescan_keep_filename();} {public decl {void rescan_keep_filename();} {public
} }
Function {show()} {open return_type void decl {void show();} {public
} {
code {window->hotspot(fileList);
window->show();
Fl::flush();
fl_cursor(FL_CURSOR_WAIT);
rescan_keep_filename();
fl_cursor(FL_CURSOR_DEFAULT);
fileName->take_focus();} {}
} }
Function {shown()} {return_type int Function {shown()} {return_type int
} { } {
@@ -418,6 +420,9 @@ else
decl {static const char *show_label;} { decl {static const char *show_label;} {
comment {[standard text may be customized at run-time]} public comment {[standard text may be customized at run-time]} public
} }
decl {static const char *hidden_label;} {
comment {[standard text may be customized at run-time]} public
}
decl {static Fl_File_Sort_F *sort;} { decl {static Fl_File_Sort_F *sort;} {
comment {the sort function that is used when loading comment {the sort function that is used when loading
the contents of a directory.} public the contents of a directory.} public

View File

@@ -347,6 +347,7 @@
#include <FL/fl_ask.H> #include <FL/fl_ask.H>
#include <FL/x.H> #include <FL/x.H>
#include <FL/Fl_Shared_Image.H> #include <FL/Fl_Shared_Image.H>
#include <FL/fl_draw.H>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@@ -1151,7 +1152,7 @@ Fl_File_Chooser::rescan()
// Build the file list... // Build the file list...
fileList->load(directory_, sort); fileList->load(directory_, sort);
#ifndef WIN32 #ifndef WIN32
if (!show_hidden->value()) remove_hidden_files(); if (!showHiddenButton->value()) remove_hidden_files();
#endif #endif
// Update the preview box... // Update the preview box...
update_preview(); update_preview();
@@ -1178,7 +1179,7 @@ void Fl_File_Chooser::rescan_keep_filename()
// Build the file list... // Build the file list...
fileList->load(directory_, sort); fileList->load(directory_, sort);
#ifndef WIN32 #ifndef WIN32
if (!show_hidden->value()) remove_hidden_files(); if (!showHiddenButton->value()) remove_hidden_files();
#endif #endif
// Update the preview box... // Update the preview box...
update_preview(); update_preview();
@@ -1576,8 +1577,42 @@ Fl_File_Chooser::value(const char *filename)
break; break;
} }
} }
void Fl_File_Chooser::show()
{
window->hotspot(fileList);
window->show();
Fl::flush();
fl_cursor(FL_CURSOR_WAIT);
rescan_keep_filename();
fl_cursor(FL_CURSOR_DEFAULT);
fileName->take_focus();
#ifdef WIN32
showHiddenButton->hide();
#endif
}
void Fl_File_Chooser::showHidden(int value)
{
if (value) {
fileList->load(directory());
} else {
remove_hidden_files();
fileList->redraw();
}
}
void Fl_File_Chooser::remove_hidden_files()
{
int count = fileList->size();
for(int num = count; num >= 1; num--) {
const char *p = fileList->text(num);
if (*p == '.' && strcmp(p, "../") != 0) fileList->remove(num);
}
fileList->topline(1);
}
// //
// 'compare_dirnames()' - Compare two directory names. // 'compare_dirnames()' - Compare two directory names.
// //