]> git.lyx.org Git - features.git/blob - src/frontends/controllers/frontend_helpers.h
Move the lyx::biblio namespace into src/. Also make changes to how the BibTeX
[features.git] / src / frontends / controllers / frontend_helpers.h
1 // -*- C++ -*-
2 /**
3  * \file frontend_helpers.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  * \author Herbert Voß
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #ifndef FRONTEND_HELPERS_H
14 #define FRONTEND_HELPERS_H
15
16 #include "Font.h"
17 #include "support/docstring.h"
18
19 #include <utility>
20 #include <vector>
21 #include <string>
22 #include <boost/bind.hpp>
23 #include <algorithm>
24 #include <utility>
25 #include <map>
26
27 class Buffer;
28
29 class Color_color;
30
31 /** Functions of use to the character GUI controller and view */
32 namespace lyx {
33 namespace frontend {
34
35 ///
36 enum FONT_STATE {
37         ///
38         IGNORE,
39         ///
40         EMPH_TOGGLE,
41         ///
42         UNDERBAR_TOGGLE,
43         ///
44         NOUN_TOGGLE,
45         ///
46         INHERIT
47 };
48
49 ///
50 typedef std::pair<docstring, Font::FONT_FAMILY> FamilyPair;
51 ///
52 typedef std::pair<docstring, Font::FONT_SERIES> SeriesPair;
53 ///
54 typedef std::pair<docstring, Font::FONT_SHAPE>  ShapePair;
55 ///
56 typedef std::pair<docstring, Font::FONT_SIZE>   SizePair;
57 ///
58 typedef std::pair<docstring, FONT_STATE> BarPair;
59 ///
60 typedef std::pair<docstring, Color_color> ColorPair;
61
62 ///
63 std::vector<FamilyPair>   const getFamilyData();
64 ///
65 std::vector<SeriesPair>   const getSeriesData();
66 ///
67 std::vector<ShapePair>    const getShapeData();
68 ///
69 std::vector<SizePair>     const getSizeData();
70 ///
71 std::vector<BarPair>      const getBarData();
72 ///
73 std::vector<ColorPair>    const getColorData();
74
75
76 ///
77 typedef std::pair<docstring, std::string> LanguagePair;
78
79 /** If the caller is the character dialog, add "No change" and "Reset"
80  *  to the vector.
81  */
82 std::vector<LanguagePair> const getLanguageData(bool character_dlg);
83 /// sort colors for the gui
84 std::vector<Color_color> const getSortedColors(std::vector<Color_color> colors);
85
86 } // namespace frontend
87
88
89 namespace support { class FileFilterList; }
90
91
92 namespace frontend {
93
94 /** Launch a file dialog and return the chosen file.
95     filename: a suggested filename.
96     title: the title of the dialog.
97     pattern: *.ps etc.
98     dir1 = (name, dir), dir2 = (name, dir): extra buttons on the dialog.
99 */
100 docstring const
101 browseFile(docstring const & filename,
102            docstring const & title,
103            support::FileFilterList const & filters,
104            bool save = false,
105            std::pair<docstring, docstring> const & dir1 =
106            std::make_pair(docstring(), docstring()),
107            std::pair<docstring, docstring> const & dir2 =
108            std::make_pair(docstring(), docstring()));
109
110
111 /** Wrapper around browseFile which tries to provide a filename
112     relative to relpath.  If the relative path is of the form "foo.txt"
113     or "bar/foo.txt", then it is returned as relative. OTOH, if it is
114     of the form "../baz/foo.txt", an absolute path is returned. This is
115     intended to be useful for insets which encapsulate files/
116 */
117 docstring const
118 browseRelFile(docstring const & filename,
119               docstring const & refpath,
120               docstring const & title,
121               support::FileFilterList const & filters,
122               bool save = false,
123               std::pair<docstring, docstring> const & dir1 =
124               std::make_pair(docstring(), docstring()),
125               std::pair<docstring, docstring> const & dir2 =
126               std::make_pair(docstring(), docstring()));
127
128
129 /** Wrapper around browseFile which tries to provide a filename
130  *  relative to the user or system directory. The dir, name and ext
131  *  parameters have the same meaning as in the
132  *  support::LibFileSearch function.
133  */
134 docstring const
135 browseLibFile(docstring const & dir,
136               docstring const & name,
137               docstring const & ext,
138               docstring const & title,
139               support::FileFilterList const & filters);
140
141
142 /** Launch a file dialog and return the chosen directory.
143     pathname: a suggested pathname.
144     title: the title of the dialog.
145     dir1 = (name, dir), dir2 = (name, dir): extra buttons on the dialog.
146 */
147 docstring const
148 browseDir(docstring const & pathname,
149            docstring const & title,
150            std::pair<docstring, docstring> const & dir1 =
151            std::make_pair(docstring(), docstring()),
152            std::pair<docstring, docstring> const & dir2 =
153            std::make_pair(docstring(), docstring()));
154
155
156 /// Returns a vector of units that can be used to create a valid LaTeX length.
157 std::vector<docstring> const getLatexUnits();
158
159
160 /** Functions to extract vectors of the first and second elems from a
161     vector<pair<A,B> >
162 */
163 template<class Pair>
164 std::vector<typename Pair::first_type> const
165 getFirst(std::vector<Pair> const & pr)
166 {
167         std::vector<typename Pair::first_type> tmp(pr.size());
168         std::transform(pr.begin(), pr.end(), tmp.begin(),
169                        boost::bind(&Pair::first, _1));
170         return tmp;
171 }
172
173 template<class Pair>
174 std::vector<typename Pair::second_type> const
175 getSecond(std::vector<Pair> const & pr)
176 {
177         std::vector<typename Pair::second_type> tmp(pr.size());
178         std::transform(pr.begin(), pr.end(), tmp.begin(),
179                        boost::bind(&Pair::second, _1));
180         return tmp;
181 }
182
183 /** Build filelists of all availabe bst/cls/sty-files. Done through
184  *  kpsewhich and an external script, saved in *Files.lst.
185  */
186 void rescanTexStyles();
187
188 /// rebuild the textree
189 void texhash();
190
191 /** Fill \c contents from one of the three texfiles.
192  *  Each entry in the file list is returned as a name_with_path
193  */
194 void getTexFileList(std::string const & filename, std::vector<std::string> & contents);
195
196 /// get the options of stylefile
197 std::string const getListOfOptions(std::string const & classname, std::string const & type);
198
199 /// get a class with full path from the list
200 std::string const getTexFileFromList(std::string const & classname, std::string const & type);
201
202 } // namespace frontend
203 } // namespace lyx
204
205 #endif // FRONTEND_HELPERS_H