]> git.lyx.org Git - features.git/blob - src/frontends/controllers/frontend_helpers.h
merge src/frontends/controllers/biblio, character, frnt_lang, helper_funcs and tex_he...
[features.git] / src / frontends / controllers / frontend_helpers.h
1 // -*- C++ -*-
2 /**
3  * \file biblio.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 BIBLIOHELPERS_H
13 #define BIBLIOHELPERS_H
14
15 #include "support/docstring.h"
16
17 #include <map>
18 #include <vector>
19
20 class Buffer;
21
22 /** Functions of use to citation and bibtex GUI controllers and views */
23 namespace lyx {
24 namespace biblio {
25
26 enum CiteEngine {
27         ENGINE_BASIC,
28         ENGINE_NATBIB_AUTHORYEAR,
29         ENGINE_NATBIB_NUMERICAL,
30         ENGINE_JURABIB
31 };
32
33
34 enum CiteStyle {
35         CITE,
36         CITET,
37         CITEP,
38         CITEALT,
39         CITEALP,
40         CITEAUTHOR,
41         CITEYEAR,
42         CITEYEARPAR
43 };
44
45
46 enum Search {
47         SIMPLE,
48         REGEX
49 };
50
51
52 enum Direction {
53         FORWARD,
54         BACKWARD
55 };
56
57
58 /** Each citation engine recognizes only a subset of all possible
59  *  citation commands. Given a latex command \c input, this function
60  *  returns an appropriate command, valid for \c engine.
61  */
62 std::string const asValidLatexCommand(std::string const & input,
63                                       CiteEngine const engine);
64
65 /// First entry is the bibliography key, second the data
66 typedef std::map<std::string, docstring> InfoMap;
67
68 /// Returns a vector of bibliography keys
69 std::vector<std::string> const getKeys(InfoMap const &);
70
71 /** Returns the BibTeX data associated with a given key.
72     Empty if no info exists. */
73 docstring const getInfo(InfoMap const &, std::string const & key);
74
75 /// return the year from the bibtex data record
76 docstring const getYear(InfoMap const & map, std::string const & key);
77
78 /// return the short form of an authorlist
79 docstring const getAbbreviatedAuthor(InfoMap const & map, std::string const & key);
80
81 // return only the family name
82 docstring const familyName(docstring const & name);
83
84 /** Search a BibTeX info field for the given key and return the
85     associated field. */
86 docstring const parseBibTeX(docstring data, std::string const & findkey);
87
88 /** Returns an iterator to the first key that meets the search
89     criterion, or end() if unsuccessful.
90
91     User supplies :
92     the InfoMap of bibkeys info,
93     the vector of keys to be searched,
94     the search criterion,
95     an iterator defining the starting point of the search,
96     an enum defining a Simple or Regex search,
97     an enum defining the search direction.
98 */
99
100 std::vector<std::string>::const_iterator
101 searchKeys(InfoMap const & map,
102            std::vector<std::string> const & keys_to_search,
103            docstring const & search_expression,
104            std::vector<std::string>::const_iterator start,
105            Search,
106            Direction,
107            bool caseSensitive=false);
108
109
110 class CitationStyle {
111 public:
112         ///
113         CitationStyle(CiteStyle s = CITE, bool f = false, bool force = false)
114                 : style(s), full(f), forceUCase(force) {}
115         /// \param latex_str a LaTeX command, "cite", "Citep*", etc
116         CitationStyle(std::string const & latex_str);
117         ///
118         std::string const asLatexStr() const;
119         ///
120         CiteStyle style;
121         ///
122         bool full;
123         ///
124         bool forceUCase;
125 };
126
127
128 /// Returns a vector of available Citation styles.
129 std::vector<CiteStyle> const getCiteStyles(CiteEngine const );
130
131 /**
132    "Translates" the available Citation Styles into strings for this key.
133    The returned string is displayed by the GUI.
134
135
136    [XX] is used in place of the actual reference
137    Eg, the vector will contain: [XX], Jones et al. [XX], ...
138
139    User supplies :
140    the key,
141    the InfoMap of bibkeys info,
142    the available citation styles
143 */
144 std::vector<docstring> const
145 getNumericalStrings(std::string const & key,
146                     InfoMap const & map,
147                     std::vector<CiteStyle> const & styles);
148
149 /**
150    "Translates" the available Citation Styles into strings for this key.
151    The returned string is displayed by the GUI.
152
153    Eg, the vector will contain:
154    Jones et al. (1990), (Jones et al. 1990), Jones et al. 1990, ...
155
156    User supplies :
157    the key,
158    the InfoMap of bibkeys info,
159    the available citation styles
160 */
161 std::vector<docstring> const
162 getAuthorYearStrings(std::string const & key,
163                      InfoMap const & map,
164                      std::vector<CiteStyle> const & styles);
165
166 } // namespace biblio
167 } // namespace lyx
168
169 #endif // BIBLIOHELPERS_H
170 // -*- C++ -*-
171 /**
172  * \file character.h
173  * This file is part of LyX, the document processor.
174  * Licence details can be found in the file COPYING.
175  *
176  * \author Angus Leeming
177  *
178  * Full author contact details are available in file CREDITS.
179  */
180
181 #ifndef CHARACTERHELPERS_H
182 #define CHARACTERHELPERS_H
183
184
185 #include "lyxfont.h"
186
187 #include <utility>
188 #include <vector>
189
190
191 class LColor_color;
192
193
194 /** Functions of use to the character GUI controller and view */
195 namespace lyx {
196 namespace frontend {
197
198 ///
199 enum FONT_STATE {
200         ///
201         IGNORE,
202         ///
203         EMPH_TOGGLE,
204         ///
205         UNDERBAR_TOGGLE,
206         ///
207         NOUN_TOGGLE,
208         ///
209         INHERIT
210 };
211
212 ///
213 typedef std::pair<docstring, LyXFont::FONT_FAMILY> FamilyPair;
214 ///
215 typedef std::pair<docstring, LyXFont::FONT_SERIES> SeriesPair;
216 ///
217 typedef std::pair<docstring, LyXFont::FONT_SHAPE>  ShapePair;
218 ///
219 typedef std::pair<docstring, LyXFont::FONT_SIZE>   SizePair;
220 ///
221 typedef std::pair<docstring, FONT_STATE> BarPair;
222 ///
223 typedef std::pair<docstring, LColor_color> ColorPair;
224
225 ///
226 std::vector<FamilyPair>   const getFamilyData();
227 ///
228 std::vector<SeriesPair>   const getSeriesData();
229 ///
230 std::vector<ShapePair>    const getShapeData();
231 ///
232 std::vector<SizePair>     const getSizeData();
233 ///
234 std::vector<BarPair>      const getBarData();
235 ///
236 std::vector<ColorPair>    const getColorData();
237
238 } // namespace frontend
239 } // namespace lyx
240
241 #endif // CHARACTERHELPERS
242 // -*- C++ -*-
243 /**
244  * \file frnt_lang.h
245  * This file is part of LyX, the document processor.
246  * Licence details can be found in the file COPYING.
247  *
248  * \author Angus Leeming
249  *
250  * Full author contact details are available in file CREDITS.
251  *
252  * Ease the use of internationalised language strings in the dialogs.
253  */
254
255 #ifndef FRNT_LANG_H
256 #define FRNT_LANG_H
257
258 #include "support/docstring.h"
259
260 #include <utility>
261 #include <vector>
262
263 namespace lyx {
264 namespace frontend {
265
266 ///
267 typedef std::pair<docstring, std::string> LanguagePair;
268
269 /** If the caller is the character dialog, add "No change" and "Reset"
270  *  to the vector.
271  */
272 std::vector<LanguagePair> const getLanguageData(bool character_dlg);
273
274 } // namespace frontend
275 } // namespace lyx
276
277 #endif // FRNT_LANG_H
278 // -*- C++ -*-
279 /**
280  * \file helper_funcs.h
281  * This file is part of LyX, the document processor.
282  * Licence details can be found in the file COPYING.
283  *
284  * \author Angus Leeming
285  *
286  * Full author contact details are available in file CREDITS.
287  */
288
289 #ifndef HELPERFUNCS_H
290 #define HELPERFUNCS_H
291
292 #include "support/docstring.h"
293
294 #include <boost/bind.hpp>
295 #include <utility>
296 #include <vector>
297 #include <string>
298 #include <algorithm>
299
300
301 namespace lyx {
302
303 namespace support { class FileFilterList; }
304
305
306 namespace frontend {
307
308 /** Launch a file dialog and return the chosen file.
309     filename: a suggested filename.
310     title: the title of the dialog.
311     pattern: *.ps etc.
312     dir1 = (name, dir), dir2 = (name, dir): extra buttons on the dialog.
313 */
314 docstring const
315 browseFile(docstring const & filename,
316            docstring const & title,
317            support::FileFilterList const & filters,
318            bool save = false,
319            std::pair<docstring, docstring> const & dir1 =
320            std::make_pair(docstring(), docstring()),
321            std::pair<docstring, docstring> const & dir2 =
322            std::make_pair(docstring(), docstring()));
323
324
325 /** Wrapper around browseFile which tries to provide a filename
326     relative to relpath.  If the relative path is of the form "foo.txt"
327     or "bar/foo.txt", then it is returned as relative. OTOH, if it is
328     of the form "../baz/foo.txt", an absolute path is returned. This is
329     intended to be useful for insets which encapsulate files/
330 */
331 docstring const
332 browseRelFile(docstring const & filename,
333               docstring const & refpath,
334               docstring const & title,
335               support::FileFilterList const & filters,
336               bool save = false,
337               std::pair<docstring, docstring> const & dir1 =
338               std::make_pair(docstring(), docstring()),
339               std::pair<docstring, docstring> const & dir2 =
340               std::make_pair(docstring(), docstring()));
341
342
343 /** Wrapper around browseFile which tries to provide a filename
344  *  relative to the user or system directory. The dir, name and ext
345  *  parameters have the same meaning as in the
346  *  support::LibFileSearch function.
347  */
348 docstring const
349 browseLibFile(docstring const & dir,
350               docstring const & name,
351               docstring const & ext,
352               docstring const & title,
353               support::FileFilterList const & filters);
354
355
356 /** Launch a file dialog and return the chosen directory.
357     pathname: a suggested pathname.
358     title: the title of the dialog.
359     dir1 = (name, dir), dir2 = (name, dir): extra buttons on the dialog.
360 */
361 docstring const
362 browseDir(docstring const & pathname,
363            docstring const & title,
364            std::pair<docstring, docstring> const & dir1 =
365            std::make_pair(docstring(), docstring()),
366            std::pair<docstring, docstring> const & dir2 =
367            std::make_pair(docstring(), docstring()));
368
369
370 /// Returns a vector of units that can be used to create a valid LaTeX length.
371 std::vector<docstring> const getLatexUnits();
372
373
374 /** Functions to extract vectors of the first and second elems from a
375     vector<pair<A,B> >
376 */
377 template<class Pair>
378 std::vector<typename Pair::first_type> const
379 getFirst(std::vector<Pair> const & pr)
380 {
381         std::vector<typename Pair::first_type> tmp(pr.size());
382         std::transform(pr.begin(), pr.end(), tmp.begin(),
383                        boost::bind(&Pair::first, _1));
384         return tmp;
385 }
386
387 template<class Pair>
388 std::vector<typename Pair::second_type> const
389 getSecond(std::vector<Pair> const & pr)
390 {
391         std::vector<typename Pair::second_type> tmp(pr.size());
392         std::transform(pr.begin(), pr.end(), tmp.begin(),
393                        boost::bind(&Pair::second, _1));
394         return tmp;
395 }
396
397 } // namespace frontend
398 } // namespace lyx
399
400 #endif // NOT HELPERFUNCS_H
401 // -*- C++ -*-
402 /**
403  * \file tex_helpers.h
404  * This file is part of LyX, the document processor.
405  * Licence details can be found in the file COPYING.
406  *
407  * \author Herbert Voß
408  *
409  * Full author contact details are available in file CREDITS.
410  */
411
412 #ifndef TEX_HELPERS_H
413 #define TEX_HELPERS_H
414
415 #include <string>
416 #include <vector>
417
418 namespace lyx {
419 namespace frontend {
420
421 /** Build filelists of all availabe bst/cls/sty-files. Done through
422  *  kpsewhich and an external script, saved in *Files.lst.
423  */
424 void rescanTexStyles();
425
426 /// rebuild the textree
427 void texhash();
428
429 /** Fill \c contents from one of the three texfiles.
430  *  Each entry in the file list is returned as a name_with_path
431  */
432 void getTexFileList(std::string const & filename, std::vector<std::string> & contents);
433
434 /// get the options of stylefile
435 std::string const getListOfOptions(std::string const & classname, std::string const & type);
436
437 /// get a class with full path from the list
438 std::string const getTexFileFromList(std::string const & classname, std::string const & type);
439
440 } // namespace frontend
441 } // namespace lyx
442
443 #endif // TEX_HELPERS_H