]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/xforms/FormFiledialog.C
get rid of broken_header.h and some unneeded tests
[lyx.git] / src / frontends / xforms / FormFiledialog.C
index df009195aa5b5286a33eaa655dde17130236689b..1c8aec402417cf13c4c52ed5313c3c84a7bed979 100644 (file)
@@ -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"
 
 #include <boost/bind.hpp>
 #include <boost/regex.hpp>
+#include <boost/tokenizer.hpp>
 
 #include <algorithm>
 #include <map>
+#include <sstream>
+
 #include <grp.h>
 #include <pwd.h>
 
@@ -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 "<glob> <glob> <glob>", 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 "<glob> <glob> <glob>".
+ *  \param directory the current working directory from
+ *  which \c glob is invoked.
+ *  \returns a vector of all matching file names.
+ */
+vector<string> const expand_globs(string const & mask,
+                                 string const & directory)
+{
+       // Split into individual globs and then call 'glob' on each one.
+       typedef boost::tokenizer<boost::char_separator<char> > Tokenizer;
+       boost::char_separator<char> const separator(" ");
+
+       vector<string> 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<string> const glob_matches =
-               lyx::support::expand_globs(mask_, directory_);
+       vector<string> 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());
 }