2001-08-26 03:20:52 +00:00
|
|
|
/**
|
|
|
|
* \file QBibtex.C
|
2002-09-24 13:57:09 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
2001-08-26 03:20:52 +00:00
|
|
|
*
|
2002-10-20 01:48:28 +00:00
|
|
|
* \author John Levon
|
2002-11-13 01:34:29 +00:00
|
|
|
* \author Herbert Voss
|
2002-09-24 13:57:09 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS
|
2001-08-26 03:20:52 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2002-09-24 13:57:09 +00:00
|
|
|
|
2001-08-26 03:20:52 +00:00
|
|
|
#include "support/lstrings.h"
|
|
|
|
|
|
|
|
#include "ControlBibtex.h"
|
2002-12-17 20:37:13 +00:00
|
|
|
#include "qt_helpers.h"
|
2002-03-21 21:21:28 +00:00
|
|
|
#include "debug.h"
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2002-07-22 14:04:38 +00:00
|
|
|
#include "support/filetools.h" // ChangeExtension
|
|
|
|
#include "support/lstrings.h" // getVectorFromString
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2001-08-26 03:20:52 +00:00
|
|
|
#include <qlineedit.h>
|
|
|
|
#include <qcombobox.h>
|
|
|
|
#include <qpushbutton.h>
|
|
|
|
#include <qlistbox.h>
|
|
|
|
#include <qcheckbox.h>
|
|
|
|
|
2003-04-12 03:08:08 +00:00
|
|
|
#include "ui/QBibtexAddDialogBase.h"
|
2002-06-19 03:38:44 +00:00
|
|
|
#include "QBibtexDialog.h"
|
|
|
|
#include "QBibtex.h"
|
|
|
|
#include "Qt2BC.h"
|
2002-07-24 07:35:59 +00:00
|
|
|
|
2003-06-30 23:56:22 +00:00
|
|
|
using namespace lyx::support;
|
|
|
|
|
2002-07-24 07:35:59 +00:00
|
|
|
using std::vector;
|
|
|
|
|
2003-02-25 14:51:38 +00:00
|
|
|
typedef QController<ControlBibtex, QView<QBibtexDialog> > base_class;
|
2001-08-26 03:20:52 +00:00
|
|
|
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2003-02-25 14:51:38 +00:00
|
|
|
QBibtex::QBibtex(Dialog & parent)
|
2003-05-22 15:42:50 +00:00
|
|
|
: base_class(parent, _("BibTeX"))
|
2001-08-26 03:20:52 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QBibtex::build_dialog()
|
|
|
|
{
|
|
|
|
dialog_.reset(new QBibtexDialog(this));
|
|
|
|
|
2003-03-10 03:13:28 +00:00
|
|
|
bcview().setOK(dialog_->okPB);
|
|
|
|
bcview().setCancel(dialog_->closePB);
|
|
|
|
bcview().addReadOnly(dialog_->databaseLB);
|
|
|
|
bcview().addReadOnly(dialog_->stylePB);
|
|
|
|
bcview().addReadOnly(dialog_->styleCB);
|
|
|
|
bcview().addReadOnly(dialog_->bibtocCB);
|
2003-04-12 03:08:08 +00:00
|
|
|
bcview().addReadOnly(dialog_->addBibPB);
|
2003-03-10 03:13:28 +00:00
|
|
|
bcview().addReadOnly(dialog_->deletePB);
|
2001-08-26 03:20:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QBibtex::update_contents()
|
|
|
|
{
|
|
|
|
dialog_->databaseLB->clear();
|
|
|
|
|
|
|
|
string bibs(controller().params().getContents());
|
|
|
|
string bib;
|
|
|
|
|
|
|
|
while (!bibs.empty()) {
|
|
|
|
bibs = split(bibs, bib, ',');
|
2002-07-28 22:50:13 +00:00
|
|
|
bib = trim(bib);
|
2001-08-27 20:41:45 +00:00
|
|
|
if (!bib.empty())
|
2002-12-17 20:37:13 +00:00
|
|
|
dialog_->databaseLB->insertItem(toqstr(bib));
|
2001-08-26 03:20:52 +00:00
|
|
|
}
|
2003-02-25 13:35:26 +00:00
|
|
|
|
2003-04-12 03:08:08 +00:00
|
|
|
dialog_->add_->bibLB->clear();
|
2003-02-14 17:23:50 +00:00
|
|
|
|
2003-06-20 14:03:49 +00:00
|
|
|
vector<string> bib_str;
|
|
|
|
controller().getBibFiles(bib_str);
|
2003-02-14 17:23:50 +00:00
|
|
|
for (vector<string>::const_iterator it = bib_str.begin();
|
|
|
|
it != bib_str.end(); ++it) {
|
|
|
|
string bibItem(ChangeExtension(*it, ""));
|
2003-04-12 03:08:08 +00:00
|
|
|
dialog_->add_->bibLB->insertItem(toqstr(bibItem));
|
2003-02-14 17:23:50 +00:00
|
|
|
}
|
2001-08-26 03:20:52 +00:00
|
|
|
|
2002-03-21 21:21:28 +00:00
|
|
|
string bibtotoc = "bibtotoc";
|
2003-01-04 21:42:59 +00:00
|
|
|
string bibstyle(controller().params().getOptions());
|
2001-08-26 03:20:52 +00:00
|
|
|
|
|
|
|
// bibtotoc exists?
|
2002-11-13 01:34:29 +00:00
|
|
|
if (prefixIs(bibstyle, bibtotoc)) {
|
2001-08-26 03:20:52 +00:00
|
|
|
dialog_->bibtocCB->setChecked(true);
|
|
|
|
|
|
|
|
// bibstyle exists?
|
|
|
|
if (contains(bibstyle,','))
|
|
|
|
bibstyle = split(bibstyle, bibtotoc, ',');
|
|
|
|
else
|
2002-10-20 01:48:28 +00:00
|
|
|
bibstyle.erase();
|
2001-08-26 03:20:52 +00:00
|
|
|
} else
|
|
|
|
dialog_->bibtocCB->setChecked(false);
|
2002-07-28 22:50:13 +00:00
|
|
|
|
2002-07-22 14:04:38 +00:00
|
|
|
|
2002-11-13 01:34:29 +00:00
|
|
|
dialog_->styleCB->clear();
|
2002-12-01 22:59:25 +00:00
|
|
|
|
2002-11-13 01:34:29 +00:00
|
|
|
int item_nr(-1);
|
2002-12-01 22:59:25 +00:00
|
|
|
|
2003-06-20 14:03:49 +00:00
|
|
|
vector<string> str;
|
|
|
|
controller().getBibStyles(str);
|
2002-07-22 14:04:38 +00:00
|
|
|
for (vector<string>::const_iterator it = str.begin();
|
|
|
|
it != str.end(); ++it) {
|
2002-12-01 22:59:25 +00:00
|
|
|
string item(ChangeExtension(*it, ""));
|
2002-11-13 01:34:29 +00:00
|
|
|
if (item == bibstyle)
|
|
|
|
item_nr = int(it - str.begin());
|
2002-12-17 20:37:13 +00:00
|
|
|
dialog_->styleCB->insertItem(toqstr(item));
|
2001-08-26 03:20:52 +00:00
|
|
|
}
|
2002-11-13 01:34:29 +00:00
|
|
|
|
|
|
|
if (item_nr == -1) {
|
2002-12-17 20:37:13 +00:00
|
|
|
dialog_->styleCB->insertItem(toqstr(bibstyle));
|
2002-11-13 01:34:29 +00:00
|
|
|
item_nr = dialog_->styleCB->count() - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
dialog_->styleCB->setCurrentItem(item_nr);
|
2001-08-26 03:20:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QBibtex::apply()
|
|
|
|
{
|
2002-12-17 20:37:13 +00:00
|
|
|
string dbs(fromqstr(dialog_->databaseLB->text(0)));
|
2001-08-26 03:20:52 +00:00
|
|
|
|
2002-11-13 01:34:29 +00:00
|
|
|
unsigned int maxCount = dialog_->databaseLB->count();
|
|
|
|
for (unsigned int i = 1; i < maxCount; i++) {
|
|
|
|
dbs += ',';
|
2002-12-17 20:37:13 +00:00
|
|
|
dbs += fromqstr(dialog_->databaseLB->text(i));
|
2001-08-26 03:20:52 +00:00
|
|
|
}
|
|
|
|
|
2002-11-13 01:34:29 +00:00
|
|
|
controller().params().setContents(dbs);
|
2001-08-26 03:20:52 +00:00
|
|
|
|
2002-12-17 20:37:13 +00:00
|
|
|
string const bibstyle(fromqstr(dialog_->styleCB->currentText()));
|
2001-08-26 03:20:52 +00:00
|
|
|
bool const bibtotoc(dialog_->bibtocCB->isChecked());
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2001-08-26 03:20:52 +00:00
|
|
|
if (bibtotoc && (!bibstyle.empty())) {
|
|
|
|
// both bibtotoc and style
|
|
|
|
controller().params().setOptions("bibtotoc," + bibstyle);
|
|
|
|
} else if (bibtotoc) {
|
|
|
|
// bibtotoc and no style
|
|
|
|
controller().params().setOptions("bibtotoc");
|
2002-11-13 01:34:29 +00:00
|
|
|
} else {
|
2002-11-13 23:46:55 +00:00
|
|
|
// only style. An empty one is valid, because some
|
|
|
|
// documentclasses have an own \bibliographystyle{}
|
|
|
|
// command!
|
2001-08-26 03:20:52 +00:00
|
|
|
controller().params().setOptions(bibstyle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool QBibtex::isValid()
|
|
|
|
{
|
2002-11-13 23:46:55 +00:00
|
|
|
return dialog_->databaseLB->count() != 0;
|
2001-08-26 03:20:52 +00:00
|
|
|
}
|