X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fxforms%2FFormFiledialog.C;h=1c8aec402417cf13c4c52ed5313c3c84a7bed979;hb=37e82a546392d43f787826b85481a11f2a27af15;hp=df009195aa5b5286a33eaa655dde17130236689b;hpb=2a31934f38d624bef25c0b177852233eee9768f0;p=lyx.git diff --git a/src/frontends/xforms/FormFiledialog.C b/src/frontends/xforms/FormFiledialog.C index df009195aa..1c8aec4024 100644 --- a/src/frontends/xforms/FormFiledialog.C +++ b/src/frontends/xforms/FormFiledialog.C @@ -20,6 +20,7 @@ #include "frontends/Dialogs.h" #include "support/FileInfo.h" +#include "support/filefilterlist.h" #include "support/filetools.h" #include "support/globbing.h" #include "support/lstrings.h" @@ -30,9 +31,12 @@ #include #include +#include #include #include +#include + #include #include @@ -72,6 +76,7 @@ using lyx::support::trim; using std::max; using std::sort; +using std::ostringstream; using std::string; using std::map; using std::vector; @@ -80,6 +85,33 @@ using namespace lyx::frontend; namespace { +/** Given a string " ", expand each glob in turn. + * Any glob that cannot be expanded is ignored silently. + * Invokes \c convert_brace_glob and \c glob internally, so use only + * on systems supporting the Posix function 'glob'. + * \param mask the string " ". + * \param directory the current working directory from + * which \c glob is invoked. + * \returns a vector of all matching file names. + */ +vector const expand_globs(string const & mask, + string const & directory) +{ + // Split into individual globs and then call 'glob' on each one. + typedef boost::tokenizer > Tokenizer; + boost::char_separator const separator(" "); + + vector matches; + Tokenizer const tokens(mask, separator); + Tokenizer::const_iterator it = tokens.begin(); + Tokenizer::const_iterator const end = tokens.end(); + for (; it != end; ++it) + lyx::support::glob(matches, *it, directory); + + return matches; +} + + // six months, in seconds long const SIX_MONTH_SEC = 6L * 30L * 24L * 60L * 60L; //static @@ -240,8 +272,7 @@ void FileDialog::Private::Reread() ++depth_; } - vector const glob_matches = - lyx::support::expand_globs(mask_, directory_); + vector const glob_matches = expand_globs(mask_, directory_); time_t curTime = time(0); rewinddir(dir); @@ -403,8 +434,24 @@ void FileDialog::Private::SetFilters(string const & mask) void FileDialog::Private::SetFilters(FileFilterList const & filters) { + if (filters.empty()) + return; + // Just take the first one for now. - mask_ = filters.filters()[0].globs(); + typedef FileFilterList::Filter::glob_iterator glob_iterator; + glob_iterator const begin = filters[0].begin(); + glob_iterator const end = filters[0].end(); + if (begin == end) + return; + + ostringstream ss; + for (glob_iterator it = begin; it != end; ++it) { + if (it != begin) + ss << ' '; + ss << *it; + } + + mask_ = ss.str(); fl_set_input(file_dlg_form_->PatBox, mask_.c_str()); }