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