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.
7 * \author Angus Leeming
10 * Full author contact details are available in file CREDITS.
13 #ifndef FRONTEND_HELPERS_H
14 #define FRONTEND_HELPERS_H
17 #include "support/docstring.h"
22 #include <boost/bind.hpp>
29 /** Functions of use to citation and bibtex GUI controllers and views */
35 ENGINE_NATBIB_AUTHORYEAR,
36 ENGINE_NATBIB_NUMERICAL,
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.
69 std::string const asValidLatexCommand(std::string const & input,
70 CiteEngine const engine);
72 /// First entry is the bibliography key, second the data
73 typedef std::map<std::string, docstring> InfoMap;
75 /// Returns a vector of bibliography keys
76 std::vector<std::string> const getKeys(InfoMap const &);
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);
82 /// return the year from the bibtex data record
83 docstring const getYear(InfoMap const & map, std::string const & key);
85 /// return the short form of an authorlist
86 docstring const getAbbreviatedAuthor(InfoMap const & map, std::string const & key);
88 // return only the family name
89 docstring const familyName(docstring const & name);
91 /** Search a BibTeX info field for the given key and return the
93 docstring const parseBibTeX(docstring data, std::string const & findkey);
95 /** Returns an iterator to the first key that meets the search
96 criterion, or end() if unsuccessful.
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.
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,
114 bool caseSensitive=false);
117 class CitationStyle {
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);
125 std::string const asLatexStr() const;
135 /// Returns a vector of available Citation styles.
136 std::vector<CiteStyle> const getCiteStyles(CiteEngine const );
139 "Translates" the available Citation Styles into strings for this key.
140 The returned string is displayed by the GUI.
143 [XX] is used in place of the actual reference
144 Eg, the vector will contain: [XX], Jones et al. [XX], ...
148 the InfoMap of bibkeys info,
149 the available citation styles
151 std::vector<docstring> const
152 getNumericalStrings(std::string const & key,
154 std::vector<CiteStyle> const & styles);
157 "Translates" the available Citation Styles into strings for this key.
158 The returned string is displayed by the GUI.
160 Eg, the vector will contain:
161 Jones et al. (1990), (Jones et al. 1990), Jones et al. 1990, ...
165 the InfoMap of bibkeys info,
166 the available citation styles
168 std::vector<docstring> const
169 getAuthorYearStrings(std::string const & key,
171 std::vector<CiteStyle> const & styles);
173 } // namespace biblio
180 /** Functions of use to the character GUI controller and view */
199 typedef std::pair<docstring, Font::FONT_FAMILY> FamilyPair;
201 typedef std::pair<docstring, Font::FONT_SERIES> SeriesPair;
203 typedef std::pair<docstring, Font::FONT_SHAPE> ShapePair;
205 typedef std::pair<docstring, Font::FONT_SIZE> SizePair;
207 typedef std::pair<docstring, FONT_STATE> BarPair;
209 typedef std::pair<docstring, Color_color> ColorPair;
212 std::vector<FamilyPair> const getFamilyData();
214 std::vector<SeriesPair> const getSeriesData();
216 std::vector<ShapePair> const getShapeData();
218 std::vector<SizePair> const getSizeData();
220 std::vector<BarPair> const getBarData();
222 std::vector<ColorPair> const getColorData();
226 typedef std::pair<docstring, std::string> LanguagePair;
228 /** If the caller is the character dialog, add "No change" and "Reset"
231 std::vector<LanguagePair> const getLanguageData(bool character_dlg);
233 } // namespace frontend
236 namespace support { class FileFilterList; }
241 /** Launch a file dialog and return the chosen file.
242 filename: a suggested filename.
243 title: the title of the dialog.
245 dir1 = (name, dir), dir2 = (name, dir): extra buttons on the dialog.
248 browseFile(docstring const & filename,
249 docstring const & title,
250 support::FileFilterList const & filters,
252 std::pair<docstring, docstring> const & dir1 =
253 std::make_pair(docstring(), docstring()),
254 std::pair<docstring, docstring> const & dir2 =
255 std::make_pair(docstring(), docstring()));
258 /** Wrapper around browseFile which tries to provide a filename
259 relative to relpath. If the relative path is of the form "foo.txt"
260 or "bar/foo.txt", then it is returned as relative. OTOH, if it is
261 of the form "../baz/foo.txt", an absolute path is returned. This is
262 intended to be useful for insets which encapsulate files/
265 browseRelFile(docstring const & filename,
266 docstring const & refpath,
267 docstring const & title,
268 support::FileFilterList const & filters,
270 std::pair<docstring, docstring> const & dir1 =
271 std::make_pair(docstring(), docstring()),
272 std::pair<docstring, docstring> const & dir2 =
273 std::make_pair(docstring(), docstring()));
276 /** Wrapper around browseFile which tries to provide a filename
277 * relative to the user or system directory. The dir, name and ext
278 * parameters have the same meaning as in the
279 * support::LibFileSearch function.
282 browseLibFile(docstring const & dir,
283 docstring const & name,
284 docstring const & ext,
285 docstring const & title,
286 support::FileFilterList const & filters);
289 /** Launch a file dialog and return the chosen directory.
290 pathname: a suggested pathname.
291 title: the title of the dialog.
292 dir1 = (name, dir), dir2 = (name, dir): extra buttons on the dialog.
295 browseDir(docstring const & pathname,
296 docstring const & title,
297 std::pair<docstring, docstring> const & dir1 =
298 std::make_pair(docstring(), docstring()),
299 std::pair<docstring, docstring> const & dir2 =
300 std::make_pair(docstring(), docstring()));
303 /// Returns a vector of units that can be used to create a valid LaTeX length.
304 std::vector<docstring> const getLatexUnits();
307 /** Functions to extract vectors of the first and second elems from a
311 std::vector<typename Pair::first_type> const
312 getFirst(std::vector<Pair> const & pr)
314 std::vector<typename Pair::first_type> tmp(pr.size());
315 std::transform(pr.begin(), pr.end(), tmp.begin(),
316 boost::bind(&Pair::first, _1));
321 std::vector<typename Pair::second_type> const
322 getSecond(std::vector<Pair> const & pr)
324 std::vector<typename Pair::second_type> tmp(pr.size());
325 std::transform(pr.begin(), pr.end(), tmp.begin(),
326 boost::bind(&Pair::second, _1));
330 /** Build filelists of all availabe bst/cls/sty-files. Done through
331 * kpsewhich and an external script, saved in *Files.lst.
333 void rescanTexStyles();
335 /// rebuild the textree
338 /** Fill \c contents from one of the three texfiles.
339 * Each entry in the file list is returned as a name_with_path
341 void getTexFileList(std::string const & filename, std::vector<std::string> & contents);
343 /// get the options of stylefile
344 std::string const getListOfOptions(std::string const & classname, std::string const & type);
346 /// get a class with full path from the list
347 std::string const getTexFileFromList(std::string const & classname, std::string const & type);
349 } // namespace frontend
352 #endif // FRONTEND_HELPERS_H