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