]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/helper_funcs.h
5 new lfuns, move all apply code out of ControlDocument and into the core.
[lyx.git] / src / frontends / controllers / helper_funcs.h
1 // -*- C++ -*-
2 /**
3  * \file helper_funcs.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Angus Leeming
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef HELPERFUNCS_H
13 #define HELPERFUNCS_H
14
15 #include <boost/bind.hpp>
16 #include <utility>
17 #include <vector>
18 #include <string>
19
20
21 namespace lyx {
22 namespace support {
23 class FileFilterList;
24 } // namespace support
25 } // namespace lyx
26
27 /** Launch a file dialog and return the chosen file.
28     filename: a suggested filename.
29     title: the title of the dialog.
30     pattern: *.ps etc.
31     dir1 = (name, dir), dir2 = (name, dir): extra buttons on the dialog.
32 */
33 std::string const
34 browseFile(std::string const & filename,
35            std::string const & title,
36            lyx::support::FileFilterList const & filters,
37            bool save = false,
38            std::pair<std::string,std::string> const & dir1 =
39            std::make_pair(std::string(), std::string()),
40            std::pair<std::string,std::string> const & dir2 =
41            std::make_pair(std::string(), std::string()));
42
43
44 /* Wrapper around browseFile which tries to provide a filename
45    relative to relpath.  If the relative path is of the form "foo.txt"
46    or "bar/foo.txt", then it is returned as relative. OTOH, if it is
47    of the form "../baz/foo.txt", an absolute path is returned. This is
48    intended to be useful for insets which encapsulate files/
49 */
50 std::string const
51 browseRelFile(std::string const & filename,
52               std::string const & refpath,
53               std::string const & title,
54               lyx::support::FileFilterList const & filters,
55               bool save = false,
56               std::pair<std::string,std::string> const & dir1 =
57               std::make_pair(std::string(), std::string()),
58               std::pair<std::string,std::string> const & dir2 =
59               std::make_pair(std::string(), std::string()));
60
61
62 /** Launch a file dialog and return the chosen directory.
63     pathname: a suggested pathname.
64     title: the title of the dialog.
65     dir1 = (name, dir), dir2 = (name, dir): extra buttons on the dialog.
66 */
67 std::string const
68 browseDir(std::string const & pathname,
69            std::string const & title,
70            std::pair<std::string,std::string> const & dir1 =
71            std::make_pair(std::string(), std::string()),
72            std::pair<std::string,std::string> const & dir2 =
73            std::make_pair(std::string(), std::string()));
74
75
76 /// Returns a vector of units that can be used to create a valid LaTeX length.
77 std::vector<std::string> const getLatexUnits();
78
79
80 /** Functions to extract vectors of the first and second elems from a
81     vector<pair<A,B> >
82 */
83 template<class Pair>
84 std::vector<typename Pair::first_type> const
85 getFirst(std::vector<Pair> const & pr)
86 {
87         std::vector<typename Pair::first_type> tmp(pr.size());
88         std::transform(pr.begin(), pr.end(), tmp.begin(),
89                        boost::bind(&Pair::first, _1));
90         return tmp;
91 }
92
93 template<class Pair>
94 std::vector<typename Pair::second_type> const
95 getSecond(std::vector<Pair> const & pr)
96 {
97         std::vector<typename Pair::second_type> tmp(pr.size());
98         std::transform(pr.begin(), pr.end(), tmp.begin(),
99                        boost::bind(&Pair::second, _1));
100         return tmp;
101 }
102
103 #endif // NOT HELPERFUNCS_H