summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorManolo Gouy <Manolo>2011-06-06 16:11:22 +0000
committerManolo Gouy <Manolo>2011-06-06 16:11:22 +0000
commit7feb5a9dfeeae416cb86e7019ffda697c94c8f90 (patch)
tree5a8bcdb60c1ca0e55c9f660cd2e7955463a13082 /src
parent922352799211caa32187bdd92af26a0527d3b304 (diff)
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
Diffstat (limited to 'src')
-rw-r--r--src/Fl_File_Chooser.cxx147
-rw-r--r--src/Fl_File_Chooser.fl27
-rw-r--r--src/Fl_File_Chooser2.cxx39
3 files changed, 113 insertions, 100 deletions
diff --git a/src/Fl_File_Chooser.cxx b/src/Fl_File_Chooser.cxx
index 75718cdd1..8ef6e15ca 100644
--- a/src/Fl_File_Chooser.cxx
+++ b/src/Fl_File_Chooser.cxx
@@ -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) {
((Fl_File_Chooser*)(o->parent()->parent()->parent()->user_data()))->cb_previewButton_i(o,v);
}
-#ifndef WIN32
-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);
-}
-
-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_showHiddenButton_i(Fl_Check_Button*, void*) {
+ showHidden(showHiddenButton->value());
+}
+void Fl_File_Chooser::cb_showHiddenButton(Fl_Check_Button* o, void* v) {
+ ((Fl_File_Chooser*)(o->parent()->parent()->parent()->user_data()))->cb_showHiddenButton_i(o,v);
+}
+
void Fl_File_Chooser::cb_fileName_i(Fl_File_Input*, void*) {
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->label(preview_label);
} // Fl_Check_Button* previewButton
-#ifndef WIN32
- { show_hidden = new Fl_Check_Button(
- previewButton->x() + previewButton->w() + 30, 275, 140, 20, "Show hidden files");
- show_hidden->down_box(FL_DOWN_BOX);
- show_hidden->value(0);
- show_hidden->callback((Fl_Callback*)show_hidden_cb, this);
- show_hidden->label(hidden_label);
- } // Fl_Check_Button* show_hidden
-#endif
+ { showHiddenButton = new Fl_Check_Button(115, 275, 165, 20, "Show hidden files");
+ showHiddenButton->down_box(FL_DOWN_BOX);
+ showHiddenButton->callback((Fl_Callback*)cb_showHiddenButton);
+ showHiddenButton->label(hidden_label);
+ } // Fl_Check_Button* showHiddenButton
{ Fl_Box* o = new Fl_Box(115, 275, 365, 20);
Fl_Group::current()->resizable(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();
} // Fl_Double_Window* favWindow
callback_ = 0;
-data_ = 0;
-directory_[0] = 0;
-window->size_range(window->w(), window->h(), Fl::w(), Fl::h());
-type(t);
-filter(p);
-update_favorites();
-value(d);
-type(t);
-int e;
-prefs_.get("preview", e, 1);
-preview(e);
-Fl_Group::current(prev_current);
+ data_ = 0;
+ directory_[0] = 0;
+ window->size_range(window->w(), window->h(), Fl::w(), Fl::h());
+ type(t);
+ filter(p);
+ update_favorites();
+ value(d);
+ type(t);
+ int e;
+ prefs_.get("preview", e, 1);
+ preview(e);
+ Fl_Group::current(prev_current);
ext_group=(Fl_Widget*)0;
}
Fl_File_Chooser::~Fl_File_Chooser() {
Fl::remove_timeout((Fl_Timeout_Handler)previewCB, this);
-if(ext_group)window->remove(ext_group);
-delete window;
-delete favWindow;
+ if(ext_group)window->remove(ext_group);
+ delete window;
+ delete favWindow;
}
void Fl_File_Chooser::callback(void (*cb)(Fl_File_Chooser *, void *), void *d ) {
callback_ = cb;
-data_ = d;
+ data_ = d;
}
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) {
showChoice->value(f);
-showChoiceCB();
+ showChoiceCB();
}
void Fl_File_Chooser::hide() {
@@ -389,27 +372,17 @@ const char * Fl_File_Chooser::label() {
void Fl_File_Chooser::ok_label(const char *l) {
okButton->label(l);
-int w=0, h=0;
-okButton->measure_label(w, h);
-okButton->resize(cancelButton->x() - 50 - w, cancelButton->y(),
- w + 40, 25);
-okButton->parent()->init_sizes();
+ int w=0, h=0;
+ okButton->measure_label(w, h);
+ okButton->resize(cancelButton->x() - 50 - w, cancelButton->y(),
+ w + 40, 25);
+ okButton->parent()->init_sizes();
}
const char * Fl_File_Chooser::ok_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() {
return window->shown();
}
@@ -440,18 +413,18 @@ Fl_Fontsize Fl_File_Chooser::textsize() {
void Fl_File_Chooser::type(int t) {
type_ = t;
-if (t & MULTI)
- fileList->type(FL_MULTI_BROWSER);
-else
- fileList->type(FL_HOLD_BROWSER);
-if (t & CREATE)
- newButton->activate();
-else
- newButton->deactivate();
-if (t & DIRECTORY)
- fileList->filetype(Fl_File_Browser::DIRECTORIES);
-else
- fileList->filetype(Fl_File_Browser::FILES);
+ if (t & MULTI)
+ fileList->type(FL_MULTI_BROWSER);
+ else
+ fileList->type(FL_HOLD_BROWSER);
+ if (t & CREATE)
+ newButton->activate();
+ else
+ newButton->deactivate();
+ if (t & DIRECTORY)
+ fileList->filetype(Fl_File_Browser::DIRECTORIES);
+ else
+ fileList->filetype(Fl_File_Browser::FILES);
}
int Fl_File_Chooser::type() {
@@ -477,22 +450,22 @@ Fl_Widget* Fl_File_Chooser::add_extra(Fl_Widget* gr) {
}
if (ext_group) {
int sh=ext_group->h()+4;
-Fl_Widget* svres=window->resizable();
-window->resizable(NULL);
-window->size(window->w(),window->h()-sh);
-window->remove(ext_group);
-ext_group=NULL;
-window->resizable(svres);
+ Fl_Widget* svres=window->resizable();
+ window->resizable(NULL);
+ window->size(window->w(),window->h()-sh);
+ window->remove(ext_group);
+ ext_group=NULL;
+ window->resizable(svres);
}
if (gr) {
int nh=window->h()+gr->h()+4;
-Fl_Widget* svres=window->resizable();
-window->resizable(NULL);
-window->size(window->w(),nh);
-gr->position(2,okButton->y()+okButton->h()+2);
-window->add(gr);
-ext_group=gr;
-window->resizable(svres);
+ Fl_Widget* svres=window->resizable();
+ window->resizable(NULL);
+ window->size(window->w(),nh);
+ gr->position(2,okButton->y()+okButton->h()+2);
+ window->add(gr);
+ ext_group=gr;
+ window->resizable(svres);
}
return ret;
}
diff --git a/src/Fl_File_Chooser.fl b/src/Fl_File_Chooser.fl
index bf1980dd2..c0d14fe3f 100644
--- a/src/Fl_File_Chooser.fl
+++ b/src/Fl_File_Chooser.fl
@@ -40,8 +40,8 @@ class FL_EXPORT Fl_File_Chooser {open
decl {static Fl_Preferences prefs_;} {}
decl {void (*callback_)(Fl_File_Chooser*, void *);} {}
decl {void *data_;} {}
- decl {char directory_[1024];} {}
- decl {char pattern_[1024];} {}
+ decl {char directory_[FL_PATH_MAX];} {}
+ decl {char pattern_[FL_PATH_MAX];} {}
decl {char preview_text_[2048];} {}
decl {int type_;} {}
decl {void favoritesButtonCB();} {}
@@ -115,6 +115,12 @@ window->hide();} open
xywh {10 275 73 20} down_box DOWN_BOX shortcut 0x80070 value 1
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 {} {
private xywh {115 275 365 20} resizable
}
@@ -301,19 +307,15 @@ okButton->parent()->init_sizes();} {}
}
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_keep_filename();} {public
}
- Function {show()} {open return_type void
- } {
- code {window->hotspot(fileList);
-window->show();
-Fl::flush();
-fl_cursor(FL_CURSOR_WAIT);
-rescan_keep_filename();
-fl_cursor(FL_CURSOR_DEFAULT);
-fileName->take_focus();} {}
+ decl {void show();} {public
}
Function {shown()} {return_type int
} {
@@ -418,6 +420,9 @@ else
decl {static const char *show_label;} {
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;} {
comment {the sort function that is used when loading
the contents of a directory.} public
diff --git a/src/Fl_File_Chooser2.cxx b/src/Fl_File_Chooser2.cxx
index 7b9105e00..37a788145 100644
--- a/src/Fl_File_Chooser2.cxx
+++ b/src/Fl_File_Chooser2.cxx
@@ -347,6 +347,7 @@
#include <FL/fl_ask.H>
#include <FL/x.H>
#include <FL/Fl_Shared_Image.H>
+#include <FL/fl_draw.H>
#include <stdio.h>
#include <stdlib.h>
@@ -1151,7 +1152,7 @@ Fl_File_Chooser::rescan()
// Build the file list...
fileList->load(directory_, sort);
#ifndef WIN32
- if (!show_hidden->value()) remove_hidden_files();
+ if (!showHiddenButton->value()) remove_hidden_files();
#endif
// Update the preview box...
update_preview();
@@ -1178,7 +1179,7 @@ void Fl_File_Chooser::rescan_keep_filename()
// Build the file list...
fileList->load(directory_, sort);
#ifndef WIN32
- if (!show_hidden->value()) remove_hidden_files();
+ if (!showHiddenButton->value()) remove_hidden_files();
#endif
// Update the preview box...
update_preview();
@@ -1576,8 +1577,42 @@ Fl_File_Chooser::value(const char *filename)
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.
//