]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/helper_funcs.h
obvious stuff
[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
23 namespace support {
24 class FileFilterList;
25 } // namespace support
26
27
28 namespace frontend {
29
30 /** Launch a file dialog and return the chosen file.
31     filename: a suggested filename.
32     title: the title of the dialog.
33     pattern: *.ps etc.
34     dir1 = (name, dir), dir2 = (name, dir): extra buttons on the dialog.
35 */
36 std::string const
37 browseFile(std::string const & filename,
38            std::string const & title,
39            support::FileFilterList const & filters,
40            bool save = false,
41            std::pair<std::string,std::string> const & dir1 =
42            std::make_pair(std::string(), std::string()),
43            std::pair<std::string,std::string> const & dir2 =
44            std::make_pair(std::string(), std::string()));
45
46
47 /* Wrapper around browseFile which tries to provide a filename
48    relative to relpath.  If the relative path is of the form "foo.txt"
49    or "bar/foo.txt", then it is returned as relative. OTOH, if it is
50    of the form "../baz/foo.txt", an absolute path is returned. This is
51    intended to be useful for insets which encapsulate files/
52 */
53 std::string const
54 browseRelFile(std::string const & filename,
55               std::string const & refpath,
56               std::string const & title,
57               support::FileFilterList const & filters,
58               bool save = false,
59               std::pair<std::string,std::string> const & dir1 =
60               std::make_pair(std::string(), std::string()),
61               std::pair<std::string,std::string> const & dir2 =
62               std::make_pair(std::string(), std::string()));
63
64
65 /** Launch a file dialog and return the chosen directory.
66     pathname: a suggested pathname.
67     title: the title of the dialog.
68     dir1 = (name, dir), dir2 = (name, dir): extra buttons on the dialog.
69 */
70 std::string const
71 browseDir(std::string const & pathname,
72            std::string const & title,
73            std::pair<std::string,std::string> const & dir1 =
74            std::make_pair(std::string(), std::string()),
75            std::pair<std::string,std::string> const & dir2 =
76            std::make_pair(std::string(), std::string()));
77
78
79 /// Returns a vector of units that can be used to create a valid LaTeX length.
80 std::vector<std::string> const getLatexUnits();
81
82
83 /** Functions to extract vectors of the first and second elems from a
84     vector<pair<A,B> >
85 */
86 template<class Pair>
87 std::vector<typename Pair::first_type> const
88 getFirst(std::vector<Pair> const & pr)
89 {
90         std::vector<typename Pair::first_type> tmp(pr.size());
91         std::transform(pr.begin(), pr.end(), tmp.begin(),
92                        boost::bind(&Pair::first, _1));
93         return tmp;
94 }
95
96 template<class Pair>
97 std::vector<typename Pair::second_type> const
98 getSecond(std::vector<Pair> const & pr)
99 {
100         std::vector<typename Pair::second_type> tmp(pr.size());
101         std::transform(pr.begin(), pr.end(), tmp.begin(),
102                        boost::bind(&Pair::second, _1));
103         return tmp;
104 }
105
106 } // namespace frontend
107 } // namespace lyx
108
109 #endif // NOT HELPERFUNCS_H