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;
40 GBibtex::GBibtex(Dialog & parent)
41 : GViewCB<ControlBibtex, GViewGladeB>(parent, _("BibTeX Bibliography"), false)
45 void GBibtex::doBuild()
47 string const gladeName = findGladeFile("bibtex");
48 xml_ = Gnome::Glade::Xml::create(gladeName);
51 xml_->get_widget("Cancel", button);
53 xml_->get_widget("OK", button);
56 xml_->get_widget("Databases", databasesview_);
57 databasessel_ = databasesview_->get_selection();
58 // signal_changed gets connected at the end of this fn.
60 Gtk::TreeModel::ColumnRecord listcols;
61 listcols.add (stringcol_);
62 databasesstore_ = Gtk::ListStore::create(listcols);
63 databasesview_->set_model(databasesstore_);
64 databasesview_->append_column("Database", stringcol_);
66 xml_->get_widget("Add", button);
67 button->signal_clicked().connect(
68 sigc::mem_fun(*this, &GBibtex::add));
69 bcview().addReadOnly(button);
70 xml_->get_widget("Remove", removebutton_);
71 removebutton_->signal_clicked().connect(
72 sigc::mem_fun(*this, &GBibtex::remove));
73 bcview().addReadOnly(removebutton_);
74 xml_->get_widget("Browse", button);
75 button->signal_clicked().connect(
76 sigc::mem_fun(*this, &GBibtex::browse));
77 bcview().addReadOnly(button);
80 xml_->get_widget("Style", box);
81 box->pack_start(stylecombo_);
83 bcview().addReadOnly(&stylecombo_);
85 xml_->get_widget("Content", contentcombo_);
86 bcview().addReadOnly(contentcombo_);
87 xml_->get_widget("TOC", toccheck_);
88 bcview().addReadOnly(toccheck_);
90 databasessel_->signal_changed().connect(
91 sigc::mem_fun(*this, &GBibtex::validate));
95 void GBibtex::update()
97 string bibs(controller().params().getContents());
100 databasesstore_->clear();
101 while (!bibs.empty()) {
102 bibs = split(bibs, bib, ',');
105 Gtk::TreeModel::iterator const row = databasesstore_->append();
106 (*row)[stringcol_] = bib;
110 string bibstyle(controller().getStylefile());
112 bool const bibtopic = controller().usingBibtopic();
113 if (controller().bibtotoc() && !bibtopic)
114 toccheck_->set_active(true);
116 toccheck_->set_active(false);
118 toccheck_->set_sensitive(!bibtopic);
120 string btprint(controller().params().getSecOptions());
122 if (btprint == "btPrintNotCited")
124 else if (btprint == "btPrintAll")
127 contentcombo_->set_active(btp);
128 contentcombo_->set_sensitive(bibtopic);
132 controller().getBibStyles(str);
135 vector<string>::const_iterator it = str.begin();
136 vector<string>::const_iterator const end = str.end();
137 for (; it != end; ++it) {
138 string item(changeExtension(*it, ""));
139 if (item == bibstyle)
140 item_nr = int(it - str.begin());
141 stylecombo_.append_text (item);
144 if (item_nr == -1 && !bibstyle.empty()) {
145 stylecombo_.append_text (bibstyle);
146 item_nr = stylecombo_.get_model()->children().size() - 1;
150 stylecombo_.set_active(item_nr);
152 stylecombo_.get_entry()->set_text("");
158 void GBibtex::apply()
160 Gtk::TreeModel::iterator it = databasesstore_->children().begin();
161 Gtk::TreeModel::iterator const end = databasesstore_->children().end();
164 for (; it != end; ++it) {
165 Glib::ustring db = (*it)[stringcol_];
166 dblist += string(db);
171 controller().params().setContents(dblist);
173 string const bibstyle = stylecombo_.get_active_text();
174 bool const bibtotoc = toccheck_->get_active();
175 bool const bibtopic = controller().usingBibtopic();
177 if (!bibtopic && bibtotoc && (!bibstyle.empty())) {
178 // both bibtotoc and style
179 controller().params().setOptions("bibtotoc," + bibstyle);
180 } else if (!bibtopic && bibtotoc) {
181 // bibtotoc and no style
182 controller().params().setOptions("bibtotoc");
184 // only style. An empty one is valid, because some
185 // documentclasses have an own \bibliographystyle{}
187 controller().params().setOptions(bibstyle);
190 // bibtopic allows three kinds of sections:
191 // 1. sections that include all cited references of the database(s)
192 // 2. sections that include all uncited references of the database(s)
193 // 3. sections that include all references of the database(s), cited or not
194 int const btp = contentcombo_->get_active_row_number();
198 controller().params().setSecOptions("btPrintCited");
201 controller().params().setSecOptions("btPrintNotCited");
204 controller().params().setSecOptions("btPrintAll");
209 controller().params().setSecOptions("");
215 string new_bib = controller().browseBib("");
219 new_bib = changeExtension(new_bib, string());
221 Gtk::TreeModel::iterator const row = databasesstore_->append();
222 (*row)[stringcol_] = new_bib;
228 void GBibtex::remove()
230 Gtk::TreeModel::iterator const selected = databasessel_->get_selected();
231 if (!databasesstore_->iter_is_valid(selected))
234 databasesstore_->erase(selected);
240 void GBibtex::browse()
242 string const file = controller().browseBst("");
245 string const filen = changeExtension(file, "");
246 bool present = false;
248 for (unsigned int i = 0; i < stylecombo_.get_model()->children().size(); ++i) {
249 stylecombo_.set_active(i);
250 Glib::ustring const item = stylecombo_.get_active_text ();
258 stylecombo_.append_text (filen);
259 stylecombo_.set_active_text(filen);
265 void GBibtex::validate()
267 if (databasesstore_->children().size())
272 Gtk::TreeModel::iterator selected = databasessel_->get_selected();
273 bool const enableremove = databasesstore_->iter_is_valid(selected) && !readOnly();
274 removebutton_->set_sensitive(enableremove);
278 } // namespace frontend