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
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
2001-08-26 03:20:52 +00:00
|
|
|
#include "support/lstrings.h"
|
|
|
|
|
|
|
|
#include "ControlBibtex.h"
|
|
|
|
#include "gettext.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>
|
|
|
|
|
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
|
|
|
|
|
|
|
using std::vector;
|
|
|
|
|
2001-08-26 03:20:52 +00:00
|
|
|
typedef Qt2CB<ControlBibtex, Qt2DB<QBibtexDialog> > base_class;
|
|
|
|
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2002-08-12 14:28:43 +00:00
|
|
|
QBibtex::QBibtex()
|
|
|
|
: base_class(_("BibTeX"))
|
2001-08-26 03:20:52 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QBibtex::build_dialog()
|
|
|
|
{
|
|
|
|
dialog_.reset(new QBibtexDialog(this));
|
|
|
|
|
|
|
|
bc().setOK(dialog_->okPB);
|
|
|
|
bc().setCancel(dialog_->closePB);
|
|
|
|
bc().addReadOnly(dialog_->databaseLB);
|
|
|
|
bc().addReadOnly(dialog_->databasePB);
|
|
|
|
bc().addReadOnly(dialog_->stylePB);
|
2002-07-23 13:12:55 +00:00
|
|
|
bc().addReadOnly(dialog_->styleCB);
|
2001-08-26 03:20:52 +00:00
|
|
|
bc().addReadOnly(dialog_->bibtocCB);
|
2001-08-27 20:41:45 +00:00
|
|
|
bc().addReadOnly(dialog_->databasePB);
|
2002-03-21 21:21:28 +00:00
|
|
|
bc().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-11-13 01:34:29 +00:00
|
|
|
dialog_->databaseLB->insertItem(bib.c_str());
|
2001-08-26 03:20:52 +00:00
|
|
|
}
|
|
|
|
|
2002-03-21 21:21:28 +00:00
|
|
|
string bibtotoc = "bibtotoc";
|
2001-08-26 03:20:52 +00:00
|
|
|
string bibstyle(controller().params().getOptions().c_str());
|
|
|
|
|
|
|
|
// 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();
|
|
|
|
|
|
|
|
int item_nr(-1);
|
|
|
|
|
2002-07-22 14:04:38 +00:00
|
|
|
vector<string> const str = getVectorFromString(
|
2002-11-13 01:34:29 +00:00
|
|
|
controller().getBibStyles(), "\n");
|
2002-07-22 14:04:38 +00:00
|
|
|
for (vector<string>::const_iterator it = str.begin();
|
|
|
|
it != str.end(); ++it) {
|
2002-11-13 01:34:29 +00:00
|
|
|
string item(ChangeExtension(*it, ""));
|
|
|
|
if (item == bibstyle)
|
|
|
|
item_nr = int(it - str.begin());
|
|
|
|
dialog_->styleCB->insertItem(item.c_str());
|
2001-08-26 03:20:52 +00:00
|
|
|
}
|
2002-11-13 01:34:29 +00:00
|
|
|
|
|
|
|
if (item_nr == -1) {
|
|
|
|
dialog_->styleCB->insertItem(bibstyle.c_str());
|
|
|
|
item_nr = dialog_->styleCB->count() - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
dialog_->styleCB->setCurrentItem(item_nr);
|
2001-08-26 03:20:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QBibtex::apply()
|
|
|
|
{
|
2002-11-13 01:34:29 +00:00
|
|
|
string dbs(dialog_->databaseLB->text(0).latin1());
|
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 += ',';
|
2001-08-26 03:20:52 +00:00
|
|
|
dbs += dialog_->databaseLB->text(i).latin1();
|
|
|
|
}
|
|
|
|
|
2002-11-13 01:34:29 +00:00
|
|
|
controller().params().setContents(dbs);
|
2001-08-26 03:20:52 +00:00
|
|
|
|
2002-11-13 01:34:29 +00:00
|
|
|
string const bibstyle(dialog_->styleCB->currentText().latin1());
|
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 {
|
|
|
|
// only style. An empty one is valid!
|
2001-08-26 03:20:52 +00:00
|
|
|
controller().params().setOptions(bibstyle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool QBibtex::isValid()
|
|
|
|
{
|
2001-08-27 20:41:45 +00:00
|
|
|
return dialog_->databaseLB->count() != 0 &&
|
2002-07-23 13:12:55 +00:00
|
|
|
!string(dialog_->styleCB->text(0)).empty();
|
2001-08-26 03:20:52 +00:00
|
|
|
}
|