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