// -*- C++ -*- /** * \file helper_funcs.h * This file is part of LyX, the document processor. * Licence details can be found in the file COPYING. * * \author Angus Leeming * * Full author contact details are available in file CREDITS */ #ifndef HELPERFUNCS_H #define HELPERFUNCS_H #include "LString.h" #include // pair #include // pair /** 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. */ string const browseFile(string const & filename, string const & title, string const & pattern, bool save = false, std::pair const & dir1 = std::make_pair(string(), string()), std::pair const & dir2 = std::make_pair(string(), 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/ */ string const browseRelFile(string const & filename, string const & refpath, string const & title, string const & pattern, bool save = false, std::pair const & dir1 = std::make_pair(string(), string()), std::pair const & dir2 = std::make_pair(string(), string())); /** 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. */ string const browseDir(string const & pathname, string const & title, std::pair const & dir1 = std::make_pair(string(), string()), std::pair const & dir2 = std::make_pair(string(), string())); /// Returns a vector of units that can be used to create a valid LaTeX length. std::vector const getLatexUnits(); /** Functions to extract vectors of the first and second elems from a vector > */ namespace detail { template struct firster { typedef typename Pair::first_type first_type; first_type const & operator()(Pair const & p) { return p.first; } }; template struct seconder { typedef typename Pair::second_type second_type; second_type const & operator()(Pair const & p) { return p.second; } }; } // namespace detail /// template std::vector const getFirst(std::vector const & pr) { std::vector tmp(pr.size()); std::transform(pr.begin(), pr.end(), tmp.begin(), detail::firster()); return tmp; } /// template std::vector const getSecond(std::vector const & pr) { std::vector tmp(pr.size()); std::transform(pr.begin(), pr.end(), tmp.begin(), detail::seconder()); return tmp; } #endif // HELPERFUNCS_H