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-09-24 13:57:09 +00:00
|
|
|
* \author John Levon
|
|
|
|
*
|
|
|
|
* 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-07-22 14:04:38 +00:00
|
|
|
#include "support/filetools.h" // ChangeExtension
|
|
|
|
#include "support/lstrings.h" // getVectorFromString
|
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-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())
|
|
|
|
dialog_->databaseLB->inSort(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?
|
|
|
|
if (prefixIs(bibstyle,bibtotoc)) {
|
|
|
|
dialog_->bibtocCB->setChecked(true);
|
|
|
|
|
|
|
|
// bibstyle exists?
|
|
|
|
if (contains(bibstyle,','))
|
|
|
|
bibstyle = split(bibstyle, bibtotoc, ',');
|
|
|
|
else
|
|
|
|
bibstyle = "";
|
|
|
|
} else
|
|
|
|
dialog_->bibtocCB->setChecked(false);
|
2002-07-28 22:50:13 +00:00
|
|
|
|
2002-07-22 14:04:38 +00:00
|
|
|
|
|
|
|
vector<string> const str = getVectorFromString(
|
|
|
|
controller().getBibStyles(),"\n");
|
|
|
|
for (vector<string>::const_iterator it = str.begin();
|
|
|
|
it != str.end(); ++it) {
|
2002-07-23 13:12:55 +00:00
|
|
|
dialog_->styleCB->insertItem(ChangeExtension(*it,"").c_str());
|
2001-08-26 03:20:52 +00:00
|
|
|
}
|
2002-07-23 13:12:55 +00:00
|
|
|
dialog_->styleCB->insertItem(bibstyle.c_str(),0);
|
2001-08-26 03:20:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QBibtex::apply()
|
|
|
|
{
|
|
|
|
string dbs;
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < dialog_->databaseLB->count(); ++i) {
|
|
|
|
dbs += dialog_->databaseLB->text(i).latin1();
|
|
|
|
if (i != dialog_->databaseLB->count())
|
2001-08-27 20:41:45 +00:00
|
|
|
dbs += ",";
|
2001-08-26 03:20:52 +00:00
|
|
|
}
|
|
|
|
controller().params().setContents(dbs);
|
|
|
|
|
2002-07-23 13:12:55 +00:00
|
|
|
string bibstyle(dialog_->styleCB->text(0).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");
|
|
|
|
} else if (!bibstyle.empty()){
|
|
|
|
// only style
|
|
|
|
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
|
|
|
}
|