]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/frontend_helpers.h
Fixed some lines that were too long. It compiled afterwards.
[lyx.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 /** Functions of use to citation and bibtex GUI controllers and views */
30 namespace lyx {
31 namespace biblio {
32
33 enum CiteEngine {
34         ENGINE_BASIC,
35         ENGINE_NATBIB_AUTHORYEAR,
36         ENGINE_NATBIB_NUMERICAL,
37         ENGINE_JURABIB
38 };
39
40
41 enum CiteStyle {
42         CITE,
43         CITET,
44         CITEP,
45         CITEALT,
46         CITEALP,
47         CITEAUTHOR,
48         CITEYEAR,
49         CITEYEARPAR
50 };
51
52
53 enum Search {
54         SIMPLE,
55         REGEX
56 };
57
58
59 enum Direction {
60         FORWARD,
61         BACKWARD
62 };
63
64
65 /** Each citation engine recognizes only a subset of all possible
66  *  citation commands. Given a latex command \c input, this function
67  *  returns an appropriate command, valid for \c engine.
68  */
69 std::string const asValidLatexCommand(std::string const & input,
70                                       CiteEngine const engine);
71
72 /// First entry is the bibliography key, second the data
73 typedef std::map<std::string, docstring> InfoMap;
74
75 /// Returns a vector of bibliography keys
76 std::vector<std::string> const getKeys(InfoMap const &);
77
78 /** Returns the BibTeX data associated with a given key.
79     Empty if no info exists. */
80 docstring const getInfo(InfoMap const &, std::string const & key);
81
82 /// return the year from the bibtex data record
83 docstring const getYear(InfoMap const & map, std::string const & key);
84
85 /// return the short form of an authorlist
86 docstring const getAbbreviatedAuthor(InfoMap const & map, std::string const & key);
87
88 // return only the family name
89 docstring const familyName(docstring const & name);
90
91 /** Search a BibTeX info field for the given key and return the
92     associated field. */
93 docstring const parseBibTeX(docstring data, std::string const & findkey);
94
95 /** Returns an iterator to the first key that meets the search
96     criterion, or end() if unsuccessful.
97
98     User supplies :
99     the InfoMap of bibkeys info,
100     the vector of keys to be searched,
101     the search criterion,
102     an iterator defining the starting point of the search,
103     an enum defining a Simple or Regex search,
104     an enum defining the search direction.
105 */
106
107 std::vector<std::string>::const_iterator
108 searchKeys(InfoMap const & map,
109            std::vector<std::string> const & keys_to_search,
110            docstring const & search_expression,
111            std::vector<std::string>::const_iterator start,
112            Search,
113            Direction,
114            bool caseSensitive=false);
115
116
117 class CitationStyle {
118 public:
119         ///
120         CitationStyle(CiteStyle s = CITE, bool f = false, bool force = false)
121                 : style(s), full(f), forceUCase(force) {}
122         /// \param latex_str a LaTeX command, "cite", "Citep*", etc
123         CitationStyle(std::string const & latex_str);
124         ///
125         std::string const asLatexStr() const;
126         ///
127         CiteStyle style;
128         ///
129         bool full;
130         ///
131         bool forceUCase;
132 };
133
134
135 /// Returns a vector of available Citation styles.
136 std::vector<CiteStyle> const getCiteStyles(CiteEngine const );
137
138 /**
139    "Translates" the available Citation Styles into strings for this key.
140    The returned string is displayed by the GUI.
141
142
143    [XX] is used in place of the actual reference
144    Eg, the vector will contain: [XX], Jones et al. [XX], ...
145
146    User supplies :
147    the key,
148    the InfoMap of bibkeys info,
149    the available citation styles
150 */
151 std::vector<docstring> const
152 getNumericalStrings(std::string const & key,
153                     InfoMap const & map,
154                     std::vector<CiteStyle> const & styles);
155
156 /**
157    "Translates" the available Citation Styles into strings for this key.
158    The returned string is displayed by the GUI.
159
160    Eg, the vector will contain:
161    Jones et al. (1990), (Jones et al. 1990), Jones et al. 1990, ...
162
163    User supplies :
164    the key,
165    the InfoMap of bibkeys info,
166    the available citation styles
167 */
168 std::vector<docstring> const
169 getAuthorYearStrings(std::string const & key,
170                      InfoMap const & map,
171                      std::vector<CiteStyle> const & styles);
172
173 } // namespace biblio
174 } // namespace lyx
175
176
177 class Color_color;
178
179
180 /** Functions of use to the character GUI controller and view */
181 namespace lyx {
182 namespace frontend {
183
184 ///
185 enum FONT_STATE {
186         ///
187         IGNORE,
188         ///
189         EMPH_TOGGLE,
190         ///
191         UNDERBAR_TOGGLE,
192         ///
193         NOUN_TOGGLE,
194         ///
195         INHERIT
196 };
197
198 ///
199 typedef std::pair<docstring, Font::FONT_FAMILY> FamilyPair;
200 ///
201 typedef std::pair<docstring, Font::FONT_SERIES> SeriesPair;
202 ///
203 typedef std::pair<docstring, Font::FONT_SHAPE>  ShapePair;
204 ///
205 typedef std::pair<docstring, Font::FONT_SIZE>   SizePair;
206 ///
207 typedef std::pair<docstring, FONT_STATE> BarPair;
208 ///
209 typedef std::pair<docstring, Color_color> ColorPair;
210
211 ///
212 std::vector<FamilyPair>   const getFamilyData();
213 ///
214 std::vector<SeriesPair>   const getSeriesData();
215 ///
216 std::vector<ShapePair>    const getShapeData();
217 ///
218 std::vector<SizePair>     const getSizeData();
219 ///
220 std::vector<BarPair>      const getBarData();
221 ///
222 std::vector<ColorPair>    const getColorData();
223
224
225 ///
226 typedef std::pair<docstring, std::string> LanguagePair;
227
228 /** If the caller is the character dialog, add "No change" and "Reset"
229  *  to the vector.
230  */
231 std::vector<LanguagePair> const getLanguageData(bool character_dlg);
232 /// sort colors for the gui
233 std::vector<Color_color> const getSortedColors(std::vector<Color_color> colors);
234
235 } // namespace frontend
236
237
238 namespace support { class FileFilterList; }
239
240
241 namespace frontend {
242
243 /** Launch a file dialog and return the chosen file.
244     filename: a suggested filename.
245     title: the title of the dialog.
246     pattern: *.ps etc.
247     dir1 = (name, dir), dir2 = (name, dir): extra buttons on the dialog.
248 */
249 docstring const
250 browseFile(docstring const & filename,
251            docstring const & title,
252            support::FileFilterList const & filters,
253            bool save = false,
254            std::pair<docstring, docstring> const & dir1 =
255            std::make_pair(docstring(), docstring()),
256            std::pair<docstring, docstring> const & dir2 =
257            std::make_pair(docstring(), docstring()));
258
259
260 /** Wrapper around browseFile which tries to provide a filename
261     relative to relpath.  If the relative path is of the form "foo.txt"
262     or "bar/foo.txt", then it is returned as relative. OTOH, if it is
263     of the form "../baz/foo.txt", an absolute path is returned. This is
264     intended to be useful for insets which encapsulate files/
265 */
266 docstring const
267 browseRelFile(docstring const & filename,
268               docstring const & refpath,
269               docstring const & title,
270               support::FileFilterList const & filters,
271               bool save = false,
272               std::pair<docstring, docstring> const & dir1 =
273               std::make_pair(docstring(), docstring()),
274               std::pair<docstring, docstring> const & dir2 =
275               std::make_pair(docstring(), docstring()));
276
277
278 /** Wrapper around browseFile which tries to provide a filename
279  *  relative to the user or system directory. The dir, name and ext
280  *  parameters have the same meaning as in the
281  *  support::LibFileSearch function.
282  */
283 docstring const
284 browseLibFile(docstring const & dir,
285               docstring const & name,
286               docstring const & ext,
287               docstring const & title,
288               support::FileFilterList const & filters);
289
290
291 /** Launch a file dialog and return the chosen directory.
292     pathname: a suggested pathname.
293     title: the title of the dialog.
294     dir1 = (name, dir), dir2 = (name, dir): extra buttons on the dialog.
295 */
296 docstring const
297 browseDir(docstring const & pathname,
298            docstring const & title,
299            std::pair<docstring, docstring> const & dir1 =
300            std::make_pair(docstring(), docstring()),
301            std::pair<docstring, docstring> const & dir2 =
302            std::make_pair(docstring(), docstring()));
303
304
305 /// Returns a vector of units that can be used to create a valid LaTeX length.
306 std::vector<docstring> const getLatexUnits();
307
308
309 /** Functions to extract vectors of the first and second elems from a
310     vector<pair<A,B> >
311 */
312 template<class Pair>
313 std::vector<typename Pair::first_type> const
314 getFirst(std::vector<Pair> const & pr)
315 {
316         std::vector<typename Pair::first_type> tmp(pr.size());
317         std::transform(pr.begin(), pr.end(), tmp.begin(),
318                        boost::bind(&Pair::first, _1));
319         return tmp;
320 }
321
322 template<class Pair>
323 std::vector<typename Pair::second_type> const
324 getSecond(std::vector<Pair> const & pr)
325 {
326         std::vector<typename Pair::second_type> tmp(pr.size());
327         std::transform(pr.begin(), pr.end(), tmp.begin(),
328                        boost::bind(&Pair::second, _1));
329         return tmp;
330 }
331
332 /** Build filelists of all availabe bst/cls/sty-files. Done through
333  *  kpsewhich and an external script, saved in *Files.lst.
334  */
335 void rescanTexStyles();
336
337 /// rebuild the textree
338 void texhash();
339
340 /** Fill \c contents from one of the three texfiles.
341  *  Each entry in the file list is returned as a name_with_path
342  */
343 void getTexFileList(std::string const & filename, std::vector<std::string> & contents);
344
345 /// get the options of stylefile
346 std::string const getListOfOptions(std::string const & classname, std::string const & type);
347
348 /// get a class with full path from the list
349 std::string const getTexFileFromList(std::string const & classname, std::string const & type);
350
351 } // namespace frontend
352 } // namespace lyx
353
354 #endif // FRONTEND_HELPERS_H