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