Author: manolo
Date: 2011-01-16 10:26:51 -0800 (Sun, 16 Jan 2011)
New Revision: 8282
Log:
Fl_File_Chooser: added a "Show hidden files" button. Hidden files aren't shown
by default now. This removes a TODO clause.
Fl_Native_File_Chooser: removed the hack that added the "Show hidden files"
button, and
made the "file already exists" warning message localizable.
Modified:
branches/branch-1.3/FL/Fl_File_Chooser.H
branches/branch-1.3/FL/Fl_Native_File_Chooser_FLTK.H
branches/branch-1.3/FL/Fl_Native_File_Chooser_MAC.H
branches/branch-1.3/FL/Fl_Native_File_Chooser_WIN32.H
branches/branch-1.3/src/Fl_File_Chooser.cxx
branches/branch-1.3/src/Fl_File_Chooser2.cxx
branches/branch-1.3/src/Fl_Native_File_Chooser.cxx
branches/branch-1.3/src/Fl_Native_File_Chooser_FLTK.cxx
Modified: branches/branch-1.3/FL/Fl_File_Chooser.H
===================================================================
--- branches/branch-1.3/FL/Fl_File_Chooser.H 2011-01-16 18:21:39 UTC (rev
8281)
+++ branches/branch-1.3/FL/Fl_File_Chooser.H 2011-01-16 18:26:51 UTC (rev
8282)
@@ -123,6 +123,9 @@
Fl_Return_Button *favOkButton;
void cb_favOkButton_i(Fl_Return_Button*, void*);
static void cb_favOkButton(Fl_Return_Button*, void*);
+ Fl_Check_Button *show_hidden;
+ static void show_hidden_cb(Fl_Check_Button*, void*);
+ void remove_hidden_files();
public:
~Fl_File_Chooser();
void callback(void (*cb)(Fl_File_Chooser *, void *), void *d = 0);
@@ -213,6 +216,10 @@
[standard text may be customized at run-time]
*/
static const char *show_label;
+ /**
+ [standard text may be customized at run-time]
+ */
+ static const char *hidden_label;
/**
the sort function that is used when loading
the contents of a directory.
Modified: branches/branch-1.3/FL/Fl_Native_File_Chooser_FLTK.H
===================================================================
--- branches/branch-1.3/FL/Fl_Native_File_Chooser_FLTK.H 2011-01-16
18:21:39 UTC (rev 8281)
+++ branches/branch-1.3/FL/Fl_Native_File_Chooser_FLTK.H 2011-01-16
18:26:51 UTC (rev 8282)
@@ -72,6 +72,8 @@
- Under X windows, it's best if you call Fl_File_Icon::load_system_icons()
at the start of main(), to enable the nicer looking file browser widgets.
+ Use the static public attributes of class Fl_File_Chooser to localize
+ the browser.
- Some operating systems support certain OS specific options; see
Fl_Native_File_Chooser::options() for a list.
@@ -95,6 +97,8 @@
NEW_FOLDER = 0x0002, ///< Show 'New Folder' icon (if
supported)
PREVIEW = 0x0004 ///< enable preview mode
};
+ /** Localizable message */
+ static const char *file_exists_message;
private:
int _btype; // kind-of browser to show()
int _options; // general options
@@ -106,16 +110,8 @@
char *_prevvalue; // Returned filename
char *_directory;
char *_errmsg; // error message
- char *_old_dir;
Fl_File_Chooser *_file_chooser;
- // added by MG
- Fl_File_Browser *my_fileList;
- Fl_Check_Button *show_hidden;
- int prev_filtervalue;
- static void show_hidden_cb(Fl_Check_Button *o, void *data);
- static void remove_hidden_files(Fl_File_Browser *my_fileList);
-
// Private methods
void errmsg(const char *msg);
int type_fl_file(int);
Modified: branches/branch-1.3/FL/Fl_Native_File_Chooser_MAC.H
===================================================================
--- branches/branch-1.3/FL/Fl_Native_File_Chooser_MAC.H 2011-01-16 18:21:39 UTC
(rev 8281)
+++ branches/branch-1.3/FL/Fl_Native_File_Chooser_MAC.H 2011-01-16 18:26:51 UTC
(rev 8282)
@@ -49,6 +49,7 @@
NEW_FOLDER = 0x0002, // Show 'New Folder' icon (if supported)
PREVIEW = 0x0004 // enable preview mode
};
+ static const char *file_exists_message;
private:
int _btype; // kind-of browser to show()
int _options; // general options
Modified: branches/branch-1.3/FL/Fl_Native_File_Chooser_WIN32.H
===================================================================
--- branches/branch-1.3/FL/Fl_Native_File_Chooser_WIN32.H 2011-01-16
18:21:39 UTC (rev 8281)
+++ branches/branch-1.3/FL/Fl_Native_File_Chooser_WIN32.H 2011-01-16
18:26:51 UTC (rev 8282)
@@ -52,6 +52,7 @@
NEW_FOLDER = 0x0002, // Show 'New Folder' icon (if supported)
PREVIEW = 0x0004, // enable preview mode
};
+ static const char *file_exists_message;
private:
int _btype; // kind-of browser to show()
int _options; // general options
Modified: branches/branch-1.3/src/Fl_File_Chooser.cxx
===================================================================
--- branches/branch-1.3/src/Fl_File_Chooser.cxx 2011-01-16 18:21:39 UTC (rev
8281)
+++ branches/branch-1.3/src/Fl_File_Chooser.cxx 2011-01-16 18:26:51 UTC (rev
8282)
@@ -88,6 +88,26 @@
((Fl_File_Chooser*)(o->parent()->parent()->parent()->user_data()))->cb_previewButton_i(o,v);
}
+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();
+ }
+}
+
void Fl_File_Chooser::cb_fileName_i(Fl_File_Input*, void*) {
fileNameCB();
}
@@ -208,6 +228,15 @@
previewButton->callback((Fl_Callback*)cb_previewButton);
previewButton->label(preview_label);
} // Fl_Check_Button* previewButton
+
+ { 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
+
{ Fl_Box* o = new Fl_Box(115, 275, 365, 20);
Fl_Group::current()->resizable(o);
} // Fl_Box* o
Modified: branches/branch-1.3/src/Fl_File_Chooser2.cxx
===================================================================
--- branches/branch-1.3/src/Fl_File_Chooser2.cxx 2011-01-16 18:21:39 UTC
(rev 8281)
+++ branches/branch-1.3/src/Fl_File_Chooser2.cxx 2011-01-16 18:26:51 UTC
(rev 8282)
@@ -74,7 +74,11 @@
<TD>"My Computer" (WIN32)<BR>
"File Systems" (all others)</TD>
</TR>
- <TR>
+ <TR>
+ <TD>hidden_label</TD>
+ <TD>"Show hidden files:"</TD>
+ </TR>
+ <TR>
<TD>manage_favorites_label</TD>
<TD>"Manage Favorites"</TD>
</TR>
@@ -98,7 +102,7 @@
<TD>show_label</TD>
<TD>"Show:"</TD>
</TR>
- <TR>
+ <TR>
<TD>sort</TD>
<TD>fl_numericsort</TD>
</TR>
@@ -392,6 +396,7 @@
const char *Fl_File_Chooser::preview_label = "Preview";
const char *Fl_File_Chooser::save_label = "Save";
const char *Fl_File_Chooser::show_label = "Show:";
+const char *Fl_File_Chooser::hidden_label = "Show hidden files";
Fl_File_Sort_F *Fl_File_Chooser::sort = fl_numericsort;
@@ -1033,8 +1038,6 @@
showChoice->add(custom_filter_label);
- // TODO: add a menu item to switch hidden files on and off
-
showChoice->value(0);
showChoiceCB();
}
@@ -1147,6 +1150,7 @@
// Build the file list...
fileList->load(directory_, sort);
+ if (!show_hidden->value()) remove_hidden_files();
// Update the preview box...
update_preview();
@@ -1172,6 +1176,7 @@
// Build the file list...
fileList->load(directory_, sort);
+ if (!show_hidden->value()) remove_hidden_files();
// Update the preview box...
update_preview();
@@ -1297,7 +1302,6 @@
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;
filename = value();
Modified: branches/branch-1.3/src/Fl_Native_File_Chooser.cxx
===================================================================
--- branches/branch-1.3/src/Fl_Native_File_Chooser.cxx 2011-01-16 18:21:39 UTC
(rev 8281)
+++ branches/branch-1.3/src/Fl_Native_File_Chooser.cxx 2011-01-16 18:26:51 UTC
(rev 8282)
@@ -32,7 +32,7 @@
// Use Apple's chooser
#ifdef __APPLE__
-//#include "Fl_Native_File_Chooser_MAC.mm"
+#include <FL/Fl_Native_File_Chooser_MAC.H>
#endif
// All else falls back to FLTK's own chooser
@@ -40,6 +40,8 @@
#include "Fl_Native_File_Chooser_FLTK.cxx"
#endif
+const char *Fl_Native_File_Chooser::file_exists_message = "File exists. Are
you sure you want to overwrite?";
+
//
// End of "$Id$".
//
Modified: branches/branch-1.3/src/Fl_Native_File_Chooser_FLTK.cxx
===================================================================
--- branches/branch-1.3/src/Fl_Native_File_Chooser_FLTK.cxx 2011-01-16
18:21:39 UTC (rev 8281)
+++ branches/branch-1.3/src/Fl_Native_File_Chooser_FLTK.cxx 2011-01-16
18:26:51 UTC (rev 8282)
@@ -64,16 +64,6 @@
_file_chooser = new Fl_File_Chooser(NULL, NULL, 0, NULL);
type(val); // do this after _file_chooser created
_nfilters = 0;
-
- // Added by MG
- Fl_Button *b = _file_chooser->previewButton;
- Fl_Window *w = b->window();
- Fl_Group::current(w); // adds a "Show hidden files" check
button in _file_chooser's window
- show_hidden = new Fl_Check_Button(b->x() + b->w() + 10, b->y(), 145, b->h(),
"Show hidden files");
- show_hidden->callback((Fl_Callback*)show_hidden_cb, this);
- my_fileList = _file_chooser->browser();
- _old_dir = 0; // to detect
directory changes
- prev_filtervalue = _file_chooser->filter_value(); // to detect filter
changes
}
/**
@@ -88,7 +78,6 @@
_prevvalue = strfree(_prevvalue);
_directory = strfree(_directory);
_errmsg = strfree(_errmsg);
- _old_dir = strfree(_old_dir);
}
// PRIVATE: SET ERROR MESSAGE
@@ -198,14 +187,6 @@
// BLOCK WHILE BROWSER SHOWN
while ( _file_chooser->shown() ) {
- if (_old_dir==0 || strcmp(_old_dir, _file_chooser->directory()) != 0) {
- _old_dir = strfree(_old_dir);
- _old_dir = strnew(_file_chooser->directory());
- if (!show_hidden->value()) remove_hidden_files(my_fileList);
- } else if (prev_filtervalue != _file_chooser->filter_value() ) {
- prev_filtervalue = _file_chooser->filter_value();
- if (!show_hidden->value() ) remove_hidden_files(my_fileList);
- }
Fl::wait();
}
@@ -471,32 +452,9 @@
return(_preset_file);
}
-void Fl_Native_File_Chooser::show_hidden_cb(Fl_Check_Button *o, void *data)
-{
- Fl_Native_File_Chooser *mychooser = (Fl_Native_File_Chooser *)data;
- if (o->value()) {
- mychooser->my_fileList->load(mychooser->_file_chooser->directory());
- } else {
- remove_hidden_files(mychooser->my_fileList);
- mychooser->my_fileList->redraw();
- }
-}
-// PRIVATE: Don't show hidden files
-void Fl_Native_File_Chooser::remove_hidden_files(Fl_File_Browser *my_fileList)
-{
- int count = my_fileList->size();
- for(int num = count; num >= 1; num--) {
- const char *p = my_fileList->text(num);
- if (*p == '.' && strcmp(p, "../") != 0) my_fileList->remove(num);
- }
- my_fileList->topline(1);
-}
-
-// PRIVATE: Don't show hidden files
int Fl_Native_File_Chooser::exist_dialog() {
- return(fl_choice("File exists. Are you sure you want to overwrite?",
- "Cancel", " OK ", NULL));
+ return(fl_choice("%s", fl_cancel, fl_ok, NULL, file_exists_message));
}
//
_______________________________________________
fltk-commit mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-commit