]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/helper_funcs.h
remove preamble dialog from the qt frontend
[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 /// Returns a vector of units that can be used to create a valid LaTeX length.
62 std::vector<string> const getLatexUnits();
63
64
65 /** Functions to extract vectors of the first and second elems from a
66     vector<pair<A,B> >
67 */
68
69 namespace detail {
70
71 template<class Pair>
72 struct firster {
73         typedef typename Pair::first_type first_type;
74         first_type const & operator()(Pair const & p) { return p.first; }
75 };
76
77 template<class Pair>
78 struct seconder {
79         typedef typename Pair::second_type second_type;
80         second_type const & operator()(Pair const & p) { return p.second; }
81 };
82
83 } // namespace detail
84
85 ///
86 template<class Pair>
87 std::vector<typename Pair::first_type> const
88 getFirst(std::vector<Pair> const & pr)
89 {
90         std::vector<typename Pair::first_type> tmp(pr.size());
91         std::transform(pr.begin(), pr.end(), tmp.begin(),
92                        detail::firster<Pair>());
93         return tmp;
94 }
95
96 ///
97 template<class Pair>
98 std::vector<typename Pair::second_type> const
99 getSecond(std::vector<Pair> const & pr)
100 {
101         std::vector<typename Pair::second_type> tmp(pr.size());
102         std::transform(pr.begin(), pr.end(), tmp.begin(),
103                        detail::seconder<Pair>());
104         return tmp;
105 }
106
107
108 #endif // HELPERFUNCS_H