* Licence details can be found in the file COPYING.
*
* \author John Levon
- * \author Herbert Voß
+ * \author Herbert Voß
* \author Angus Leeming
- * \author Jürgen Spitzmüller
+ * \author Jürgen Spitzmüller
*
* Full author contact details are available in file CREDITS.
*/
#include "Buffer.h"
#include "BufferParams.h"
-#include "EmbeddedFiles.h"
-#include "ui_BibtexAddUi.h"
+#include "CiteEnginesList.h"
+#include "FuncRequest.h"
+#include "LyXRC.h"
#include "qt_helpers.h"
#include "Validator.h"
-#include "LyXRC.h"
+
+#include "ui_BibtexAddUi.h"
#include "ButtonPolicy.h"
#include "frontends/alert.h"
+#include "insets/InsetBibtex.h"
+
#include "support/debug.h"
#include "support/ExceptionMessage.h"
-#include "support/FileFilterList.h"
+#include "support/FileName.h"
#include "support/filetools.h" // changeExtension
#include "support/gettext.h"
#include "support/lstrings.h"
GuiBibtex::GuiBibtex(GuiView & lv)
- : GuiCommand(lv, "bibtex", qt_("BibTeX Bibliography"))
+ : GuiDialog(lv, "bibtex", qt_("BibTeX Bibliography")),
+ params_(insetCode("bibtex"))
{
setupUi(this);
this, SLOT(change_adaptor()));
connect(addBibPB, SIGNAL(clicked()),
this, SLOT(addPressed()));
+ connect(rescanPB, SIGNAL(clicked()),
+ this, SLOT(rescanClicked()));
+ connect(biblatexOptsLE, SIGNAL(textChanged(QString)),
+ this, SLOT(change_adaptor()));
add_ = new GuiBibtexAddDialog(this);
add_bc_.setPolicy(ButtonPolicy::OkCancelPolicy);
this, SLOT(addDatabase()));
connect(add_->addPB, SIGNAL(clicked()),
add_, SLOT(accept()));
+ connect(add_->rescanPB, SIGNAL(clicked()),
+ this, SLOT(rescanClicked()));
connect(add_->bibLW, SIGNAL(itemActivated(QListWidgetItem *)),
this, SLOT(addDatabase()));
connect(add_->bibLW, SIGNAL(itemActivated(QListWidgetItem *)),
if (matches.empty()) {
QString label = item->text();
QListWidgetItem * db = new QListWidgetItem(label);
- db->setFlags(db->flags() | Qt::ItemIsSelectable
- | Qt::ItemIsUserCheckable);
- db->setCheckState(Qt::Checked);
+ db->setFlags(db->flags() | Qt::ItemIsSelectable);
databaseLW->addItem(db);
}
}
databaseLW->findItems(f, Qt::MatchExactly);
if (matches.empty()) {
QListWidgetItem * db = new QListWidgetItem(f);
- db->setFlags(db->flags() | Qt::ItemIsSelectable
- | Qt::ItemIsUserCheckable);
- db->setCheckState(Qt::Checked);
+ db->setFlags(db->flags() | Qt::ItemIsSelectable);
databaseLW->addItem(db);
}
}
}
+void GuiBibtex::rescanClicked()
+{
+ rescanBibStyles();
+ updateContents();
+}
+
+
void GuiBibtex::databaseChanged()
{
bool readOnly = isBufferReadonly();
void GuiBibtex::updateContents()
{
bool bibtopic = usingBibtopic();
+ bool biblatex = usingBiblatex();
databaseLW->clear();
docstring bibs = params_["bibfiles"];
- docstring embs = params_["embed"];
docstring bib;
- docstring emb;
while (!bibs.empty()) {
bibs = split(bibs, bib, ',');
- embs = split(embs, emb, ',');
bib = trim(bib);
if (!bib.empty()) {
QListWidgetItem * db = new QListWidgetItem(toqstr(bib));
- db->setFlags(db->flags() | Qt::ItemIsSelectable
- | Qt::ItemIsUserCheckable);
- db->setCheckState(emb.empty() ? Qt::Unchecked : Qt::Checked);
+ db->setFlags(db->flags() | Qt::ItemIsSelectable);
databaseLW->addItem(db);
}
}
for (int i = 0; i != bibfiles.count(); ++i)
add_->bibLW->addItem(changeExtension(bibfiles[i], ""));
- QString bibstyle = styleFile();
+ QString const bibstyle = styleFile();
bibtocCB->setChecked(bibtotoc() && !bibtopic);
bibtocCB->setEnabled(!bibtopic);
else if (bibtopic && btPrintCO->count() < 3)
btPrintCO->insertItem(1, qt_("all uncited references", 0));
- docstring btprint = params_["btprint"];
+ docstring const & btprint = params_["btprint"];
int btp = 0;
- if ((bibtopic && btprint == "btPrintNotCited") ||
- (!bibtopic && btprint == "btPrintAll"))
+ if ((bibtopic && btprint == from_ascii("btPrintNotCited")) ||
+ (!bibtopic && btprint == from_ascii("btPrintAll")))
btp = 1;
- else if (bibtopic && btprint == "btPrintAll")
+ else if (bibtopic && btprint == from_ascii("btPrintAll"))
btp = 2;
btPrintCO->setCurrentIndex(btp);
- styleCB->clear();
+ // Only useful for biblatex
+ biblatexOptsLA->setVisible(biblatex);
+ biblatexOptsLE->setVisible(biblatex);
- int item_nr = -1;
+ // only useful for BibTeX
+ styleCB->setVisible(!biblatex);
+ styleLA->setVisible(!biblatex);
+ stylePB->setVisible(!biblatex);
- QStringList str = bibStyles();
- for (int i = 0; i != str.count(); ++i) {
- QString item = changeExtension(str[i], "");
- if (item == bibstyle)
- item_nr = i;
- styleCB->addItem(item);
- }
+ if (!biblatex) {
+ styleCB->clear();
- if (item_nr == -1 && !bibstyle.isEmpty()) {
- styleCB->addItem(bibstyle);
- item_nr = styleCB->count() - 1;
- }
+ int item_nr = -1;
- if (item_nr != -1)
- styleCB->setCurrentIndex(item_nr);
- else
- styleCB->clearEditText();
+ QStringList const str = bibStyles();
+ for (int i = 0; i != str.count(); ++i) {
+ QString item = changeExtension(str[i], "");
+ if (item == bibstyle)
+ item_nr = i;
+ styleCB->addItem(item);
+ }
+
+ if (item_nr == -1 && !bibstyle.isEmpty()) {
+ styleCB->addItem(bibstyle);
+ item_nr = styleCB->count() - 1;
+ }
+
+
+ if (item_nr != -1)
+ styleCB->setCurrentIndex(item_nr);
+ else
+ styleCB->clearEditText();
+ } else
+ biblatexOptsLE->setText(toqstr(params_["biblatexopts"]));
}
void GuiBibtex::applyView()
{
docstring dbs;
- docstring emb;
unsigned int maxCount = databaseLW->count();
- Buffer & buf = buffer();
for (unsigned int i = 0; i < maxCount; i++) {
- if (i != 0) {
+ if (i != 0)
dbs += ',';
- emb += ',';
- }
- QString filename = databaseLW->item(i)->text();
- dbs += qstring_to_ucs4(filename);
- try {
- EmbeddedFile file(fromqstr(changeExtension(filename, "bib")),
- buf.filePath());
- file.setEmbed(databaseLW->item(i)->checkState() == Qt::Checked);
- // move file around if needed, an exception may be raised.
- file.enable(buf.embedded(), &buf, true);
- // if things are OK...,
- if (file.embedded())
- emb += from_utf8(file.inzipName());
- } catch (ExceptionMessage const & message) {
- Alert::error(message.title_, message.details_);
- // failed to embed
- }
+ QString item = databaseLW->item(i)->text();
+ docstring bibfile = qstring_to_ucs4(item);
+ dbs += bibfile;
}
params_["bibfiles"] = dbs;
- params_["embed"] = emb;
docstring const bibstyle = qstring_to_ucs4(styleCB->currentText());
bool const bibtotoc = bibtocCB->isChecked();
params_["options"] = bibstyle;
}
+ params_["biblatexopts"] = qstring_to_ucs4(biblatexOptsLE->text());
+
int btp = btPrintCO->currentIndex();
if (usingBibtopic()) {
// use \nocite{*}
params_["btprint"] = from_ascii("btPrintAll");
break;
- }
+ }
}
}
{
QString const label1 = qt_("Documents|#o#O");
QString const dir1 = toqstr(lyxrc.document_path);
- FileFilterList const filter(_("BibTeX Databases (*.bib)"));
- return browseRelFile(in_name, bufferFilepath(),
+ QStringList const filter(qt_("BibTeX Databases (*.bib)"));
+ return browseRelToParent(in_name, bufferFilePath(),
qt_("Select a BibTeX database to add"), filter, false, label1, dir1);
}
{
QString const label1 = qt_("Documents|#o#O");
QString const dir1 = toqstr(lyxrc.document_path);
- FileFilterList const filter(_("BibTeX Styles (*.bst)"));
- return browseRelFile(in_name, bufferFilepath(),
+ QStringList const filter(qt_("BibTeX Styles (*.bst)"));
+ return browseRelToParent(in_name, bufferFilePath(),
qt_("Select a BibTeX style"), filter, false, label1, dir1);
}
data = texFileList("bstFiles.lst");
}
for (int i = 0; i != data.size(); ++i)
- data[i] = onlyFilename(data[i]);
+ data[i] = onlyFileName(data[i]);
// sort on filename only (no path)
data.sort();
return data;
data = texFileList("bibFiles.lst");
}
for (int i = 0; i != data.size(); ++i)
- data[i] = onlyFilename(data[i]);
+ data[i] = onlyFileName(data[i]);
// sort on filename only (no path)
data.sort();
return data;
void GuiBibtex::rescanBibStyles() const
{
- rescanTexStyles();
+ if (usingBiblatex())
+ rescanTexStyles("bib");
+ else
+ rescanTexStyles("bst bib");
}
}
+bool GuiBibtex::usingBiblatex() const
+{
+ return buffer().params().useBiblatex();
+}
+
+
QString GuiBibtex::styleFile() const
{
// the different bibtex packages have (and need) their
// own "plain" stylefiles
- biblio::CiteEngine const engine = buffer().params().getEngine();
- QString defaultstyle;
- switch (engine) {
- case biblio::ENGINE_BASIC:
- defaultstyle = "plain";
- break;
- case biblio::ENGINE_NATBIB_AUTHORYEAR:
- defaultstyle = "plainnat";
- break;
- case biblio::ENGINE_NATBIB_NUMERICAL:
- defaultstyle = "plainnat";
- break;
- case biblio::ENGINE_JURABIB:
- defaultstyle = "jurabib";
- break;
- }
+ QString defaultstyle = toqstr(buffer().params().defaultBiblioStyle());
QString bst = toqstr(params_["options"]);
if (bibtotoc()){
// FIXME: check
// docstring bibtotoc = from_ascii("bibtotoc");
// bst = split(bst, bibtotoc, ',');
- bst = bst.mid(pos);
+ bst = bst.mid(pos + 1);
} else {
bst.clear();
}
}
+bool GuiBibtex::initialiseParams(std::string const & data)
+{
+ InsetCommand::string2params(data, params_);
+ return true;
+}
+
+
+void GuiBibtex::dispatchParams()
+{
+ std::string const lfun = InsetCommand::params2string(params_);
+ dispatch(FuncRequest(getLfun(), lfun));
+}
+
+
+
Dialog * createGuiBibtex(GuiView & lv) { return new GuiBibtex(lv); }
} // namespace frontend
} // namespace lyx
-#include "GuiBibtex_moc.cpp"
+#include "moc_GuiBibtex.cpp"