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