#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>
using std::max;
using std::sort;
+using std::ostringstream;
using std::string;
using std::map;
using std::vector;
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
++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);
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());
}