3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 // Too hard to make concept checks work with this file
14 #ifdef _GLIBCXX_CONCEPT_CHECKS
15 #undef _GLIBCXX_CONCEPT_CHECKS
17 #ifdef _GLIBCPP_CONCEPT_CHECKS
18 #undef _GLIBCPP_CONCEPT_CHECKS
22 #include "ControlBibtex.h"
25 #include "support/filetools.h"
26 #include "support/lstrings.h"
28 #include <libglademm.h>
30 using lyx::support::changeExtension;
31 using lyx::support::split;
32 using lyx::support::trim;
41 GBibtex::GBibtex(Dialog & parent)
42 : GViewCB<ControlBibtex, GViewGladeB>(parent, lyx::to_utf8(_("BibTeX Bibliography")), false)
46 void GBibtex::doBuild()
48 string const gladeName = findGladeFile("bibtex");
49 xml_ = Gnome::Glade::Xml::create(gladeName);
52 xml_->get_widget("Cancel", button);
54 xml_->get_widget("OK", button);
57 xml_->get_widget("Databases", databasesview_);
58 databasessel_ = databasesview_->get_selection();
59 // signal_changed gets connected at the end of this fn.
61 Gtk::TreeModel::ColumnRecord listcols;
62 listcols.add (stringcol_);
63 databasesstore_ = Gtk::ListStore::create(listcols);
64 databasesview_->set_model(databasesstore_);
65 databasesview_->append_column("Database", stringcol_);
67 xml_->get_widget("Add", button);
68 button->signal_clicked().connect(
69 sigc::mem_fun(*this, &GBibtex::add));
70 bcview().addReadOnly(button);
71 xml_->get_widget("Remove", removebutton_);
72 removebutton_->signal_clicked().connect(
73 sigc::mem_fun(*this, &GBibtex::remove));
74 bcview().addReadOnly(removebutton_);
75 xml_->get_widget("Browse", button);
76 button->signal_clicked().connect(
77 sigc::mem_fun(*this, &GBibtex::browse));
78 bcview().addReadOnly(button);
81 xml_->get_widget("Style", box);
82 box->pack_start(stylecombo_);
84 bcview().addReadOnly(&stylecombo_);
86 xml_->get_widget("Content", contentcombo_);
87 bcview().addReadOnly(contentcombo_);
88 xml_->get_widget("TOC", toccheck_);
89 bcview().addReadOnly(toccheck_);
91 databasessel_->signal_changed().connect(
92 sigc::mem_fun(*this, &GBibtex::validate));
96 void GBibtex::update()
98 string bibs(controller().params().getContents());
101 databasesstore_->clear();
102 while (!bibs.empty()) {
103 bibs = split(bibs, bib, ',');
106 Gtk::TreeModel::iterator const row = databasesstore_->append();
107 (*row)[stringcol_] = bib;
111 string bibstyle(controller().getStylefile());
113 bool const bibtopic = controller().usingBibtopic();
114 if (controller().bibtotoc() && !bibtopic)
115 toccheck_->set_active(true);
117 toccheck_->set_active(false);
119 toccheck_->set_sensitive(!bibtopic);
121 string btprint(controller().params().getSecOptions());
123 if (btprint == "btPrintNotCited")
125 else if (btprint == "btPrintAll")
128 contentcombo_->set_active(btp);
129 contentcombo_->set_sensitive(bibtopic);
133 controller().getBibStyles(str);
136 vector<string>::const_iterator it = str.begin();
137 vector<string>::const_iterator const end = str.end();
138 for (; it != end; ++it) {
139 string item(changeExtension(*it, ""));
140 if (item == bibstyle)
141 item_nr = int(it - str.begin());
142 stylecombo_.append_text (item);
145 if (item_nr == -1 && !bibstyle.empty()) {
146 stylecombo_.append_text (bibstyle);
147 item_nr = stylecombo_.get_model()->children().size() - 1;
151 stylecombo_.set_active(item_nr);
153 stylecombo_.get_entry()->set_text("");
159 void GBibtex::apply()
161 Gtk::TreeModel::iterator it = databasesstore_->children().begin();
162 Gtk::TreeModel::iterator const end = databasesstore_->children().end();
165 for (; it != end; ++it) {
166 Glib::ustring db = (*it)[stringcol_];
167 dblist += string(db);
172 controller().params().setContents(dblist);
174 string const bibstyle = stylecombo_.get_active_text();
175 bool const bibtotoc = toccheck_->get_active();
176 bool const bibtopic = controller().usingBibtopic();
178 if (!bibtopic && bibtotoc && (!bibstyle.empty())) {
179 // both bibtotoc and style
180 controller().params().setOptions("bibtotoc," + bibstyle);
181 } else if (!bibtopic && bibtotoc) {
182 // bibtotoc and no style
183 controller().params().setOptions("bibtotoc");
185 // only style. An empty one is valid, because some
186 // documentclasses have an own \bibliographystyle{}
188 controller().params().setOptions(bibstyle);
191 // bibtopic allows three kinds of sections:
192 // 1. sections that include all cited references of the database(s)
193 // 2. sections that include all uncited references of the database(s)
194 // 3. sections that include all references of the database(s), cited or not
195 int const btp = contentcombo_->get_active_row_number();
199 controller().params().setSecOptions("btPrintCited");
202 controller().params().setSecOptions("btPrintNotCited");
205 controller().params().setSecOptions("btPrintAll");
210 controller().params().setSecOptions("");
216 string new_bib = controller().browseBib("");
220 new_bib = changeExtension(new_bib, string());
222 Gtk::TreeModel::iterator const row = databasesstore_->append();
223 (*row)[stringcol_] = new_bib;
229 void GBibtex::remove()
231 Gtk::TreeModel::iterator const selected = databasessel_->get_selected();
232 if (!databasesstore_->iter_is_valid(selected))
235 databasesstore_->erase(selected);
241 void GBibtex::browse()
243 string const file = controller().browseBst("");
246 string const filen = changeExtension(file, "");
247 bool present = false;
249 for (unsigned int i = 0; i < stylecombo_.get_model()->children().size(); ++i) {
250 stylecombo_.set_active(i);
251 Glib::ustring const item = stylecombo_.get_active_text ();
259 stylecombo_.append_text (filen);
260 stylecombo_.set_active_text(filen);
266 void GBibtex::validate()
268 if (databasesstore_->children().size())
273 Gtk::TreeModel::iterator selected = databasessel_->get_selected();
274 bool const enableremove = databasesstore_->iter_is_valid(selected) && !readOnly();
275 removebutton_->set_sensitive(enableremove);
279 } // namespace frontend