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