]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/helper_funcs.h
fix starting up which binary is really a symlink; make sure insetinclude file browser...
[lyx.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 <a.leeming@ic.ac.uk>
13  */
14
15 #ifndef HELPERFUNCS_H
16 #define HELPERFUNCS_H
17
18 #include <utility> // pair
19
20 #ifdef __GNUG__
21 #pragma interface
22 #endif
23
24 /** Functions to convert a string to/from a vector. */
25
26 ///
27 string const
28 getStringFromVector(std::vector<string> const & vec, string const & delim=",");
29
30 ///
31 std::vector<string> const
32 getVectorFromString(string const & str, string const & delim=",");
33
34 class LyXView;
35  
36 /** Launch a file dialog and return the chosen file.
37     filename: a suggested filename.
38     title: the title of the dialog.
39     pattern: *.ps etc.
40     dir1 = (name, dir), dir2 = (name, dir): extra buttons on the dialog.
41 */
42 string const browseFile(LyXView *lv, string const & filename,
43                         string const & title,
44                         string const & pattern, 
45                         std::pair<string,string> const & dir1 = std::make_pair(string(), string()),
46                         std::pair<string,string> const & dir2 = std::make_pair(string(), string()));
47
48
49 /* Wrapper around browseFile which tries to provide a filename
50    relative to relpath.  If the relative path is of the form "foo.txt"
51    or "bar/foo.txt", then it is returned as relative. OTOH, if it is
52    of the form "../baz/foo.txt", an absolute path is returned. This is
53    intended to be useful for insets which encapsulate files/
54 */
55 string const browseRelFile(LyXView *lv, string const & filename,
56                            string const & refpath,
57                            string const & title,
58                            string const & pattern, 
59                            std::pair<string,string> const & dir1 = std::make_pair(string(), string()),
60                            std::pair<string,string> const & dir2 = std::make_pair(string(), string()));
61
62
63 /// Returns a vector of units that can be used to create a valid LaTeX length.
64 std::vector<string> const getLatexUnits();
65
66
67 /** Functions to extract vectors of the first and second elems from a
68     vector<pair<A,B> >
69 */
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 ///
84 template<class Pair>
85 std::vector<typename Pair::first_type> const
86 getFirst(std::vector<Pair> const & pr)
87 {
88         std::vector<typename Pair::first_type> tmp(pr.size());
89         std::transform(pr.begin(), pr.end(), tmp.begin(), firster<Pair>());
90         return tmp;
91 }
92
93 ///
94 template<class Pair>
95 std::vector<typename Pair::second_type> const
96 getSecond(std::vector<Pair> const & pr)
97 {
98         std::vector<typename Pair::second_type> tmp(pr.size());
99         std::transform(pr.begin(), pr.end(), tmp.begin(), seconder<Pair>());
100         return tmp;
101 }
102
103
104 #endif // HELPERFUNCS_H