]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/controllers/helper_funcs.h
fix crash due to invalidated iterator
[lyx.git] / src / frontends / controllers / helper_funcs.h
index 4e6be14a621b88f8672e881c3d1fb9b7f63c244e..36def74d207e43bc6f45c97b371d475ea7fc4304 100644 (file)
 // -*- C++ -*-
-/* This file is part of
- * ====================================================== 
+/**
+ * \file helper_funcs.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
  *
- *           LyX, The Document Processor
+ * \author Angus Leeming
  *
- *           Copyright 2001 The LyX Team.
- *
- * ======================================================
- *
- * \file ControlCitation.h
- * \author Angus Leeming <a.leeming@ic.ac.uk>
+ * Full author contact details are available in file CREDITS.
  */
 
 #ifndef HELPERFUNCS_H
 #define HELPERFUNCS_H
 
-#ifdef __GNUG__
-#pragma interface
-#endif
-
-/** Functions to convert a string to/from a vector. */
-
-///
-string const
-getStringFromVector(std::vector<string> const & vec, string const & delim=",");
+#include <boost/bind.hpp>
+#include <utility>
+#include <vector>
+#include <string>
 
-///
-std::vector<string> const
-getVectorFromString(string const & str, string const & delim=",");
 
-/** Functions to extract vectors of the first and second elems from a
-    vector<pair<A,B> >
-*/
+namespace lyx {
 
-///
-template <class A, class B>
-std::vector<A> const getFirst(std::vector<std::pair<A,B> > const & pairVec)
-{
-       typedef std::vector<std::pair<A,B> > PV;
-
-       std::vector<A> first(pairVec.size());
-
-       for (PV::size_type i = 0; i < pairVec.size(); ++i) {
-               first[i] = pairVec[i].first;
-       }
-
-       return first;
-}
-///
-template <class A, class B>
-std::vector<B> const getSecond(std::vector<std::pair<A,B> > const & pairVec)
-{
-       typedef std::vector<std::pair<A,B> > PV;
+namespace support {
+class FileFilterList;
+} // namespace support
 
-       std::vector<B> second(pairVec.size());
 
-       for (PV::size_type i = 0; i < pairVec.size(); ++i) {
-               second[i] = pairVec[i].second;
-       }
+namespace frontend {
 
-       return second;
-}
+/** Launch a file dialog and return the chosen file.
+    filename: a suggested filename.
+    title: the title of the dialog.
+    pattern: *.ps etc.
+    dir1 = (name, dir), dir2 = (name, dir): extra buttons on the dialog.
+*/
+std::string const
+browseFile(std::string const & filename,
+          std::string const & title,
+          support::FileFilterList const & filters,
+          bool save = false,
+          std::pair<std::string,std::string> const & dir1 =
+          std::make_pair(std::string(), std::string()),
+          std::pair<std::string,std::string> const & dir2 =
+          std::make_pair(std::string(), std::string()));
+
+
+/** Wrapper around browseFile which tries to provide a filename
+    relative to relpath.  If the relative path is of the form "foo.txt"
+    or "bar/foo.txt", then it is returned as relative. OTOH, if it is
+    of the form "../baz/foo.txt", an absolute path is returned. This is
+    intended to be useful for insets which encapsulate files/
+*/
+std::string const
+browseRelFile(std::string const & filename,
+             std::string const & refpath,
+             std::string const & title,
+             support::FileFilterList const & filters,
+             bool save = false,
+             std::pair<std::string,std::string> const & dir1 =
+             std::make_pair(std::string(), std::string()),
+             std::pair<std::string,std::string> const & dir2 =
+             std::make_pair(std::string(), std::string()));
+
+
+/** Wrapper around browseFile which tries to provide a filename
+ *  relative to the user or system directory. The dir, name and ext
+ *  parameters have the same meaning as in the
+ *  lyx::support::LibFileSearch function.
+ */
+std::string const
+browseLibFile(std::string const & dir,
+             std::string const & name,
+             std::string const & ext,
+             std::string const & title,
+             support::FileFilterList const & filters);
+
+
+/** Launch a file dialog and return the chosen directory.
+    pathname: a suggested pathname.
+    title: the title of the dialog.
+    dir1 = (name, dir), dir2 = (name, dir): extra buttons on the dialog.
+*/
+std::string const
+browseDir(std::string const & pathname,
+          std::string const & title,
+          std::pair<std::string,std::string> const & dir1 =
+          std::make_pair(std::string(), std::string()),
+          std::pair<std::string,std::string> const & dir2 =
+          std::make_pair(std::string(), std::string()));
 
 
-template<class Pair>
-struct firster {
-       typedef typename Pair::first_type first_type;
-       first_type const & operator()(Pair const & p) { return p.first; }
-};
+/// Returns a vector of units that can be used to create a valid LaTeX length.
+std::vector<std::string> const getLatexUnits();
 
-template<class Pair>
-struct seconder {
-       typedef typename Pair::second_type second_type;
-       second_type const & operator()(Pair const & p) { return p.second; }
-};
 
+/** Functions to extract vectors of the first and second elems from a
+    vector<pair<A,B> >
+*/
 template<class Pair>
-typename Pair::first_type const getFirst(std::vector<Pair> const & pr)
+std::vector<typename Pair::first_type> const
+getFirst(std::vector<Pair> const & pr)
 {
-       std::vector<typename Pair::first_type> tmp(pr.size);
-       std::transform(pr.begin(), pr.end(), tmp.begin(), firster<Pair>());
+       std::vector<typename Pair::first_type> tmp(pr.size());
+       std::transform(pr.begin(), pr.end(), tmp.begin(),
+                      boost::bind(&Pair::first, _1));
        return tmp;
 }
 
 template<class Pair>
-typename Pair::second_type const getSecond(std::vector<Pair> const & pr)
+std::vector<typename Pair::second_type> const
+getSecond(std::vector<Pair> const & pr)
 {
-       std::vector<typename Pair::second_type> tmp(pr.size);
-       std::transform(pr.begin(), pr.end(), tmp.begin(), seconder<Pair>());
+       std::vector<typename Pair::second_type> tmp(pr.size());
+       std::transform(pr.begin(), pr.end(), tmp.begin(),
+                      boost::bind(&Pair::second, _1));
        return tmp;
 }
 
+} // namespace frontend
+} // namespace lyx
 
-
-#endif // HELPERFUNCS_H
-
+#endif // NOT HELPERFUNCS_H