]> git.lyx.org Git - lyx.git/blobdiff - src/support/globbing.h
Remove cached var from RenderPreview. Changes elsewhere to suit.
[lyx.git] / src / support / globbing.h
index 809aae6bc1eb677ae3d5ffa26b7d2af19bfccee8..08f117c47d68d6f4772e4591ecfc4fb76b2a8b2f 100644 (file)
@@ -26,6 +26,7 @@ namespace support {
  */
 std::string const convert_brace_glob(std::string const & glob);
 
+
 /** A wrapper for the Posix function 'glob'.
  *  \param pattern the glob to be expanded. Eg "*.[Ch]".
  *  \param flags flags to be passed to the system function. See 'man glob'.
@@ -33,19 +34,56 @@ std::string const convert_brace_glob(std::string const & glob);
  */
 std::vector<std::string> const glob(std::string const & pattern, int flags = 0);
 
+
 /** Given a string "<glob> <glob> <glob>", expand each glob in turn.
  *  Any glob that cannot be expanded is ignored silently.
- *  Invokes \c expand_brace_glob and \c glob internally, so use only
+ *  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 (if not empty) the current working directory from
- * which \c glob is invoked.
+ *  \param mask the string "<glob> <glob> <glob>".
+ *  \param directory (if not empty) the current working directory from
+ *  which \c glob is invoked.
  *  \returns a vector of all matching file names.
  */
 std::vector<std::string> const
 expand_globs(std::string const & mask,
             std::string const & directory = std::string());
 
+
+/** \c FileFilterList parses a Qt-style list of available file filters
+ *  to generate the corresponding vector.
+ *  For example "TeX documents (*.tex);;LyX Documents (*.lyx)"
+ *  will be parsed to fill a vector of size 2, whilst "*.{p[bgp]m} *.pdf"
+ *  will result in a vector of size 1 in which the description field is empty.
+ */
+class FileFilterList {
+public:
+       class Filter {
+               std::string desc_;
+               std::string globs_;
+       public:
+               Filter(std::string const & d, std::string const & g)
+                       : desc_(d), globs_(g) {}
+               std::string const & description() const { return desc_; }
+               std::string const & globs() const { return globs_; }
+       };
+
+       /** \param qt_style_filter a list of available file filters.
+        *  Eg. "TeX documents (*.tex);;LyX Documents (*.lyx)"
+        *  If empty, set to "All files (*)".
+        */
+       explicit FileFilterList(std::string const & qt_style_filter = std::string());
+       std::vector<Filter> const & filters() const { return filters_; }
+
+       /** \param expand pass each glob through \c convert_brace_glob.
+        *  \returns the equivalent of the string passed to the c-tor.
+        */
+       std::string const str(bool expand) const;
+
+private:
+       void parse_filter(std::string const & filter);
+       std::vector<Filter> filters_;
+};
+
 } // namespace support
 } // namespace lyx