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