]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlBibtex.C
fix crash due to invalidated iterator
[lyx.git] / src / frontends / controllers / ControlBibtex.C
1 /**
2  * \file ControlBibtex.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author John Levon
7  * \author Angus Leeming
8  * \author Herbert Voß
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #include <config.h>
14
15 #include "ControlBibtex.h"
16
17 #include "buffer.h"
18 #include "bufferparams.h"
19
20 #include "lyxrc.h"
21 #include "helper_funcs.h"
22 #include "tex_helpers.h"
23 #include "gettext.h"
24
25 #include "support/filefilterlist.h"
26 #include "support/filetools.h"
27
28 using std::pair;
29 using std::string;
30 using std::vector;
31
32
33 namespace lyx {
34
35 using support::FileFilterList;
36 using support::OnlyFilename;
37
38 namespace frontend {
39
40
41 ControlBibtex::ControlBibtex(Dialog & d)
42         : ControlCommand(d, "bibtex")
43 {}
44
45
46 string const ControlBibtex::browseBib(string const & in_name) const
47 {
48         pair<string, string> dir1(_("Documents|#o#O"),
49                                   string(lyxrc.document_path));
50         FileFilterList const filter(_("BibTeX Databases (*.bib)"));
51         return browseRelFile(in_name, kernel().bufferFilepath(),
52                              _("Select a BibTeX database to add"),
53                              filter, false, dir1);
54 }
55
56
57 string const ControlBibtex::browseBst(string const & in_name) const
58 {
59         pair<string, string> dir1(_("Documents|#o#O"),
60                                   string(lyxrc.document_path));
61         FileFilterList const filter(_("BibTeX Styles (*.bst)"));
62         return browseRelFile(in_name, kernel().bufferFilepath(),
63                              _("Select a BibTeX style"), filter, false, dir1);
64 }
65
66
67 void ControlBibtex::getBibStyles(vector<string> & data) const
68 {
69         data.clear();
70
71         getTexFileList("bstFiles.lst", data);
72         // test, if we have a valid list, otherwise run rescan
73         if (data.empty()) {
74                 rescanBibStyles();
75                 getTexFileList("bstFiles.lst", data);
76         }
77         vector<string>::iterator it  = data.begin();
78         vector<string>::iterator end = data.end();
79         for (; it != end; ++it) {
80                 *it = OnlyFilename(*it);
81         }
82         // sort on filename only (no path)
83         std::sort(data.begin(), data.end());
84 }
85
86
87 void ControlBibtex::getBibFiles(vector<string> & data) const
88 {
89         data.clear();
90
91         getTexFileList("bibFiles.lst", data);
92         // test, if we have a valid list, otherwise run rescan
93         if (data.empty()) {
94                 rescanBibStyles();
95                 getTexFileList("bibFiles.lst", data);
96         }
97         vector<string>::iterator it  = data.begin();
98         vector<string>::iterator end = data.end();
99         for (; it != end; ++it) {
100                 *it = OnlyFilename(*it);
101         }
102         // sort on filename only (no path)
103         std::sort(data.begin(), data.end());
104 }
105
106
107 void ControlBibtex::rescanBibStyles() const
108 {
109         rescanTexStyles();
110 }
111
112
113 bool ControlBibtex::usingBibtopic() const
114 {
115     return kernel().buffer().params().use_bibtopic;
116 }
117
118 } // namespace frontend
119 } // namespace lyx