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