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