2002-09-25 14:26:13 +00:00
|
|
|
/**
|
2003-02-21 09:20:18 +00:00
|
|
|
* \file insetbibtex.C
|
2002-09-25 14:26:13 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Alejandro Aguilar Sierra
|
2003-09-03 17:28:39 +00:00
|
|
|
* \author Angus Leeming
|
2002-09-25 14:26:13 +00:00
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2002-09-25 14:26:13 +00:00
|
|
|
*/
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2003-06-02 10:03:27 +00:00
|
|
|
#include <config.h>
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2003-02-21 09:20:18 +00:00
|
|
|
#include "insetbibtex.h"
|
2003-08-26 10:33:59 +00:00
|
|
|
#include "metricsinfo.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "buffer.h"
|
2003-02-26 19:28:38 +00:00
|
|
|
#include "BufferView.h"
|
2003-02-21 09:20:18 +00:00
|
|
|
#include "debug.h"
|
2003-02-26 19:28:38 +00:00
|
|
|
#include "funcrequest.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "gettext.h"
|
2003-05-22 21:10:22 +00:00
|
|
|
#include "latexrunparams.h"
|
2003-09-03 17:28:39 +00:00
|
|
|
#include "lyxlex.h"
|
|
|
|
#include "Lsstream.h"
|
|
|
|
#include "metricsinfo.h"
|
2001-12-28 13:26:54 +00:00
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
#include "support/filetools.h"
|
2000-05-17 13:40:40 +00:00
|
|
|
#include "support/path.h"
|
2001-05-17 15:11:01 +00:00
|
|
|
#include "support/os.h"
|
2001-07-29 17:39:01 +00:00
|
|
|
#include "support/lstrings.h"
|
2003-09-03 17:28:39 +00:00
|
|
|
#include "support/lyxalgo.h"
|
2001-08-20 13:42:29 +00:00
|
|
|
#include "support/LAssert.h"
|
2003-09-03 17:28:39 +00:00
|
|
|
#include "support/tostr.h"
|
2001-12-28 13:26:54 +00:00
|
|
|
|
|
|
|
#include <fstream>
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2003-09-03 17:28:39 +00:00
|
|
|
using namespace lyx;
|
|
|
|
using support::FileName;
|
2003-06-30 23:56:22 +00:00
|
|
|
|
2000-04-04 00:19:15 +00:00
|
|
|
using std::ostream;
|
2000-05-05 07:54:27 +00:00
|
|
|
using std::ifstream;
|
2000-03-28 02:18:55 +00:00
|
|
|
using std::endl;
|
2000-06-07 08:53:40 +00:00
|
|
|
using std::vector;
|
|
|
|
using std::pair;
|
2003-02-18 12:36:02 +00:00
|
|
|
|
|
|
|
|
2003-09-03 17:28:39 +00:00
|
|
|
InsetBibtexParams::InsetBibtexParams()
|
|
|
|
: bibtotoc(false)
|
2000-07-15 23:51:46 +00:00
|
|
|
{}
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2003-09-03 17:28:39 +00:00
|
|
|
bool InsetBibtexParams::empty() const
|
2003-02-25 14:51:38 +00:00
|
|
|
{
|
2003-09-03 17:28:39 +00:00
|
|
|
return databases.empty();
|
2003-02-25 14:51:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-09-03 17:28:39 +00:00
|
|
|
void InsetBibtexParams::erase()
|
2003-07-28 23:53:36 +00:00
|
|
|
{
|
2003-09-03 17:28:39 +00:00
|
|
|
databases.clear();
|
|
|
|
style.erase();
|
|
|
|
bibtotoc = false;
|
2003-07-28 23:53:36 +00:00
|
|
|
}
|
|
|
|
|
2003-09-02 17:08:54 +00:00
|
|
|
|
2003-09-03 17:28:39 +00:00
|
|
|
void InsetBibtexParams::write(Buffer const & buffer, std::ostream & os) const
|
2003-08-26 10:33:59 +00:00
|
|
|
{
|
2003-09-03 17:28:39 +00:00
|
|
|
os << "Bibtex\n";
|
|
|
|
|
|
|
|
vector<FileName>::const_iterator it = databases.begin();
|
|
|
|
vector<FileName>::const_iterator end = databases.end();
|
|
|
|
for (; it != end; ++it) {
|
|
|
|
os << "\tfilename "
|
|
|
|
<< it->outputFilename(buffer.filePath())
|
|
|
|
<< '\n';
|
|
|
|
}
|
|
|
|
if (!style.empty())
|
|
|
|
os << "\tstyle " << style << '\n';
|
|
|
|
if (bibtotoc)
|
|
|
|
os << "\tbibtotoc " << tostr(bibtotoc) << '\n';
|
2003-08-26 10:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-09-03 17:28:39 +00:00
|
|
|
void InsetBibtexParams::read(Buffer const & buffer, LyXLex & lex)
|
|
|
|
{
|
|
|
|
enum BibtexTags {
|
|
|
|
BIB_FILENAME = 1,
|
|
|
|
BIB_STYLE,
|
|
|
|
BIB_BIBTOTOC,
|
|
|
|
BIB_END
|
|
|
|
};
|
|
|
|
|
|
|
|
keyword_item bibtex_tags[] = {
|
|
|
|
{ "\\end_inset", BIB_END },
|
|
|
|
{ "bibtotoc", BIB_BIBTOTOC },
|
|
|
|
{ "filename", BIB_FILENAME},
|
|
|
|
{ "style", BIB_STYLE}
|
|
|
|
};
|
|
|
|
|
|
|
|
pushpophelper pph(lex, bibtex_tags, BIB_END);
|
|
|
|
|
|
|
|
bool found_end = false;
|
|
|
|
bool read_error = false;
|
|
|
|
|
|
|
|
while (lex.isOK()) {
|
|
|
|
switch (lex.lex()) {
|
|
|
|
case BIB_FILENAME: {
|
|
|
|
lex.next();
|
|
|
|
FileName filename;
|
|
|
|
filename.set(lex.getString(), buffer.filePath());
|
|
|
|
databases.push_back(filename);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case BIB_STYLE: {
|
|
|
|
lex.next();
|
|
|
|
style = lex.getString();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case BIB_BIBTOTOC: {
|
|
|
|
lex.next();
|
|
|
|
bibtotoc = lex.getBool();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case BIB_END:
|
|
|
|
found_end = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
lex.printError("BibtexInset::read: "
|
|
|
|
"Wrong tag: $$Token");
|
|
|
|
read_error = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (found_end || read_error)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found_end) {
|
|
|
|
lex.printError("BibtexInset::read: "
|
|
|
|
"Missing \\end_inset.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
InsetBibtex::InsetBibtex()
|
|
|
|
: set_label_(false), center_indent_(0)
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
InsetBibtex::InsetBibtex(InsetBibtexParams const & p)
|
|
|
|
: params_(p), set_label_(false), center_indent_(0)
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
InsetBibtex::~InsetBibtex()
|
2003-08-26 10:33:59 +00:00
|
|
|
{
|
2003-09-03 17:28:39 +00:00
|
|
|
InsetBibtexMailer(*this).hideDialog();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::auto_ptr<InsetBase> InsetBibtex::clone() const
|
|
|
|
{
|
|
|
|
return std::auto_ptr<InsetBase>(new InsetBibtex(*this));
|
2003-08-26 10:33:59 +00:00
|
|
|
}
|
|
|
|
|
2003-07-28 23:53:36 +00:00
|
|
|
|
2003-02-26 19:28:38 +00:00
|
|
|
dispatch_result InsetBibtex::localDispatch(FuncRequest const & cmd)
|
|
|
|
{
|
2003-03-07 21:44:48 +00:00
|
|
|
switch (cmd.action) {
|
2003-05-16 07:44:00 +00:00
|
|
|
|
|
|
|
case LFUN_INSET_EDIT:
|
2003-09-03 17:28:39 +00:00
|
|
|
InsetBibtexMailer(*this).showDialog(cmd.view());
|
2003-05-16 07:44:00 +00:00
|
|
|
return DISPATCHED;
|
|
|
|
|
2003-03-07 21:44:48 +00:00
|
|
|
case LFUN_INSET_MODIFY: {
|
2003-09-03 17:28:39 +00:00
|
|
|
Buffer const * buffer = cmd.view()->buffer();
|
|
|
|
InsetBibtexParams p;
|
|
|
|
InsetBibtexMailer::string2params(cmd.argument, *buffer, p);
|
2003-03-07 21:44:48 +00:00
|
|
|
setParams(p);
|
2003-05-16 07:44:00 +00:00
|
|
|
return DISPATCHED;
|
2003-03-07 21:44:48 +00:00
|
|
|
}
|
2003-05-16 07:44:00 +00:00
|
|
|
|
2003-09-03 17:28:39 +00:00
|
|
|
case LFUN_INSET_DIALOG_UPDATE:
|
|
|
|
InsetBibtexMailer(*this).updateDialog(cmd.view());
|
|
|
|
return DISPATCHED;
|
|
|
|
|
|
|
|
case LFUN_MOUSE_RELEASE:
|
|
|
|
return localDispatch(FuncRequest(cmd.view(), LFUN_INSET_EDIT));
|
|
|
|
|
2003-03-07 21:44:48 +00:00
|
|
|
default:
|
2003-09-03 17:28:39 +00:00
|
|
|
return InsetOld::localDispatch(cmd);
|
2003-02-26 19:28:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
string const InsetBibtex::getScreenLabel(Buffer const &) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
return _("BibTeX Generated References");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-09-03 17:28:39 +00:00
|
|
|
void InsetBibtex::metrics(MetricsInfo & mi, Dimension & dim) const
|
|
|
|
{
|
|
|
|
if (!set_label_) {
|
|
|
|
set_label_ = true;
|
|
|
|
button_.update(getScreenLabel(*mi.base.bv->buffer()),
|
|
|
|
editable() != NOT_EDITABLE);
|
|
|
|
}
|
|
|
|
button_.metrics(mi, dim);
|
|
|
|
center_indent_ = (mi.base.textwidth - dim.wid) / 2;
|
|
|
|
dim.wid = mi.base.textwidth;
|
|
|
|
dim_ = dim;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetBibtex::draw(PainterInfo & pi, int x, int y) const
|
|
|
|
{
|
|
|
|
button_.draw(pi, x + center_indent_, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetBibtex::write(Buffer const & buffer, std::ostream & os) const
|
|
|
|
{
|
|
|
|
params().write(buffer, os);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetBibtex::read(Buffer const & buffer, LyXLex & lex)
|
|
|
|
{
|
|
|
|
InsetBibtexParams p;
|
|
|
|
p.read(buffer, lex);
|
|
|
|
|
|
|
|
// Replace the inset's store
|
|
|
|
setParams(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
int InsetBibtex::latex(Buffer const & buffer, ostream & os,
|
2003-05-23 08:59:47 +00:00
|
|
|
LatexRunParams const & runparams) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2003-09-03 17:28:39 +00:00
|
|
|
ostringstream ss;
|
2001-08-20 13:42:29 +00:00
|
|
|
// 1. \bibliographystyle{style}
|
2003-09-03 17:28:39 +00:00
|
|
|
if (!params().style.empty()) { // we want no \biblio...{}
|
|
|
|
string style = params().style;
|
2001-08-20 13:42:29 +00:00
|
|
|
|
2003-09-03 17:28:39 +00:00
|
|
|
string const abs_style =
|
|
|
|
support::MakeAbsPath(style, buffer.filePath());
|
|
|
|
if (!runparams.nice && support::IsFileReadable(abs_style + ".bst"))
|
|
|
|
style = abs_style;
|
2001-08-20 13:42:29 +00:00
|
|
|
|
2003-09-03 17:28:39 +00:00
|
|
|
ss << "\\bibliographystyle{" << style << "}\n";
|
2001-08-20 13:42:29 +00:00
|
|
|
}
|
|
|
|
|
2003-09-03 17:28:39 +00:00
|
|
|
// 2. \addcontentsline{...} - if option bibtotoc set
|
|
|
|
if (params().bibtotoc) {
|
|
|
|
// Assumption: if the textclass name does not contain "art",
|
|
|
|
// then it's a book.
|
|
|
|
BufferParams const & bp = buffer.params;
|
|
|
|
if (!support::contains(bp.getLyXTextClass().name(), "art")) {
|
|
|
|
if (bp.sides == LyXTextClass::OneSide) {
|
|
|
|
ss << "\\clearpage";
|
2001-08-20 13:42:29 +00:00
|
|
|
} else {
|
2003-09-03 17:28:39 +00:00
|
|
|
ss << "\\cleardoublepage";
|
2001-08-20 13:42:29 +00:00
|
|
|
}
|
|
|
|
|
2003-09-03 17:28:39 +00:00
|
|
|
// book class
|
|
|
|
ss << "\\addcontentsline{toc}{chapter}{\\bibname}\n";
|
2001-08-20 13:42:29 +00:00
|
|
|
} else {
|
|
|
|
// article class
|
2003-09-03 17:28:39 +00:00
|
|
|
ss << "\\addcontentsline{toc}{section}{\\refname}\n";
|
2001-08-20 13:42:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-09-03 17:28:39 +00:00
|
|
|
// 3. \bibliography{database}
|
|
|
|
// If we generate in a temp dir, we _need_ to use the absolute path,
|
|
|
|
// else rely on the user.
|
|
|
|
ss << "\\bibliography{";
|
|
|
|
vector<FileName>::const_iterator begin = params().databases.begin();
|
|
|
|
vector<FileName>::const_iterator end = params().databases.end();
|
|
|
|
vector<FileName>::const_iterator it = begin;
|
|
|
|
for (; it != end; ++it) {
|
|
|
|
if (it != begin)
|
|
|
|
ss << ',';
|
|
|
|
string db = it->outputFilename(buffer.filePath());
|
2003-05-22 21:10:22 +00:00
|
|
|
if (!runparams.nice &&
|
2003-09-03 17:28:39 +00:00
|
|
|
support::IsFileReadable(it->absFilename())+".bib")
|
|
|
|
db = support::os::external_path(it->absFilename());
|
|
|
|
|
|
|
|
ss << db;
|
2000-03-02 02:19:43 +00:00
|
|
|
}
|
2003-09-03 17:28:39 +00:00
|
|
|
ss << '}';
|
|
|
|
|
|
|
|
string const output = STRCONV(ss.str());
|
|
|
|
os << output;
|
|
|
|
return int(lyx::count(output.begin(), output.end(),'\n') + 1);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-09-03 17:28:39 +00:00
|
|
|
int InsetBibtex::ascii(Buffer const &, std::ostream &, int) const
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int InsetBibtex::linuxdoc(Buffer const &, std::ostream &) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2003-09-03 17:28:39 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2001-08-20 13:42:29 +00:00
|
|
|
|
2000-05-17 13:40:40 +00:00
|
|
|
|
2003-09-03 17:28:39 +00:00
|
|
|
int InsetBibtex::docbook(Buffer const &, std::ostream &, bool) const
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2001-08-20 13:42:29 +00:00
|
|
|
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2003-09-03 17:28:39 +00:00
|
|
|
vector<string> const InsetBibtex::getFiles(Buffer const & buffer) const
|
|
|
|
{
|
|
|
|
support::Path p(buffer.filePath());
|
|
|
|
|
|
|
|
vector<string> files;
|
|
|
|
vector<FileName>::const_iterator it = params().databases.begin();
|
|
|
|
vector<FileName>::const_iterator end = params().databases.end();
|
|
|
|
for (; it != end; ++it) {
|
|
|
|
// I really do need to pass the buffer path here...
|
|
|
|
// FileName needs extending it would seem.
|
|
|
|
string file_in = it->relFilename(buffer.filePath());
|
|
|
|
string file_out = support::findtexfile(
|
|
|
|
support::ChangeExtension(file_in, "bib"), "bib");
|
|
|
|
lyxerr[Debug::LATEX] << "Bibfile: " << file_in
|
|
|
|
<< ' ' << file_out << endl;
|
|
|
|
|
|
|
|
// If we don't find a matching file name just fail silently
|
|
|
|
if (!file_out.empty())
|
|
|
|
files.push_back(file_out);
|
2001-08-20 13:42:29 +00:00
|
|
|
}
|
|
|
|
|
2003-09-03 17:28:39 +00:00
|
|
|
return files;
|
2001-08-20 13:42:29 +00:00
|
|
|
}
|
|
|
|
|
2003-02-18 12:36:02 +00:00
|
|
|
|
2001-08-20 13:42:29 +00:00
|
|
|
// This method returns a comma separated list of Bibtex entries
|
2003-08-28 07:41:31 +00:00
|
|
|
void InsetBibtex::fillWithBibKeys(Buffer const & buffer,
|
2003-06-28 01:23:11 +00:00
|
|
|
std::vector<std::pair<string, string> > & keys) const
|
2001-08-20 13:42:29 +00:00
|
|
|
{
|
2003-08-28 07:41:31 +00:00
|
|
|
vector<string> const files = getFiles(buffer);
|
2001-08-20 13:42:29 +00:00
|
|
|
for (vector<string>::const_iterator it = files.begin();
|
|
|
|
it != files.end(); ++ it) {
|
|
|
|
// This is a _very_ simple parser for Bibtex database
|
|
|
|
// files. All it does is to look for lines starting
|
|
|
|
// in @ and not being @preamble and @string entries.
|
|
|
|
// It does NOT do any syntax checking!
|
|
|
|
ifstream ifs(it->c_str());
|
|
|
|
string linebuf0;
|
|
|
|
while (getline(ifs, linebuf0)) {
|
2003-09-03 17:28:39 +00:00
|
|
|
string linebuf = support::trim(linebuf0);
|
2002-02-16 15:59:55 +00:00
|
|
|
if (linebuf.empty()) continue;
|
2003-09-03 17:28:39 +00:00
|
|
|
if (support::prefixIs(linebuf, "@")) {
|
|
|
|
linebuf = support::subst(linebuf, '{', '(');
|
2001-08-20 13:42:29 +00:00
|
|
|
string tmp;
|
2003-09-03 17:28:39 +00:00
|
|
|
linebuf = support::split(linebuf, tmp, '(');
|
|
|
|
tmp = support::ascii_lowercase(tmp);
|
|
|
|
if (!support::prefixIs(tmp, "@string")
|
|
|
|
&& !support::prefixIs(tmp, "@preamble")) {
|
|
|
|
linebuf = support::split(linebuf, tmp, ',');
|
|
|
|
tmp = support::ltrim(tmp, " \t");
|
2001-08-20 13:42:29 +00:00
|
|
|
if (!tmp.empty()) {
|
|
|
|
keys.push_back(pair<string,string>(tmp,string()));
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
2001-08-20 13:42:29 +00:00
|
|
|
} else if (!keys.empty()) {
|
|
|
|
keys.back().second += linebuf + "\n";
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
|
2003-09-03 17:28:39 +00:00
|
|
|
bool InsetBibtex::addDatabase(string const & /* db */)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2003-09-03 17:28:39 +00:00
|
|
|
#ifdef WITH_WARNINGS
|
|
|
|
#warning addDatabase is currently disabled (no LFUN).
|
|
|
|
#endif
|
|
|
|
#if 0
|
|
|
|
vector<string>
|
2000-07-27 08:55:59 +00:00
|
|
|
string contents(getContents());
|
2003-09-03 17:28:39 +00:00
|
|
|
if (!support::contains(contents, db)) {
|
2002-03-21 17:09:55 +00:00
|
|
|
if (!contents.empty())
|
2002-11-27 10:30:28 +00:00
|
|
|
contents += ',';
|
2000-07-27 08:55:59 +00:00
|
|
|
setContents(contents + db);
|
1999-09-27 18:44:28 +00:00
|
|
|
return true;
|
|
|
|
}
|
2003-09-03 17:28:39 +00:00
|
|
|
#endif
|
1999-09-27 18:44:28 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-09-03 17:28:39 +00:00
|
|
|
bool InsetBibtex::delDatabase(string const & /* db */)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2003-09-03 17:28:39 +00:00
|
|
|
#ifdef WITH_WARNINGS
|
|
|
|
#warning delDatabase is currently disabled (no LFUN).
|
|
|
|
#endif
|
|
|
|
#if 0
|
|
|
|
if (support::contains(getContents(), db)) {
|
1999-10-02 16:21:10 +00:00
|
|
|
string bd = db;
|
2000-11-22 18:38:31 +00:00
|
|
|
int const n = tokenPos(getContents(), ',', bd);
|
1999-09-27 18:44:28 +00:00
|
|
|
if (n > 0) {
|
1999-10-26 23:33:30 +00:00
|
|
|
// Weird code, would someone care to explain this?(Lgb)
|
1999-11-15 10:58:38 +00:00
|
|
|
string tmp(", ");
|
1999-09-27 18:44:28 +00:00
|
|
|
tmp += bd;
|
2003-09-03 17:28:39 +00:00
|
|
|
setContents(support::subst(getContents(), tmp, ", "));
|
1999-11-15 10:58:38 +00:00
|
|
|
} else if (n == 0)
|
2003-09-03 17:28:39 +00:00
|
|
|
setContents(support::split(getContents(), bd, ','));
|
2002-03-21 17:09:55 +00:00
|
|
|
else
|
1999-09-27 18:44:28 +00:00
|
|
|
return false;
|
|
|
|
}
|
2003-09-03 17:28:39 +00:00
|
|
|
#endif
|
1999-09-27 18:44:28 +00:00
|
|
|
return true;
|
|
|
|
}
|
2003-09-03 17:28:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
void InsetBibtex::setParams(InsetBibtexParams const & params)
|
|
|
|
{
|
|
|
|
params_ = params;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string const InsetBibtexMailer::name_ = "bibtex";
|
|
|
|
|
|
|
|
|
|
|
|
InsetBibtexMailer::InsetBibtexMailer(InsetBibtex & inset)
|
|
|
|
: inset_(inset)
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
string const InsetBibtexMailer::inset2string(Buffer const & buffer) const
|
|
|
|
{
|
|
|
|
return params2string(inset_.params(), buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetBibtexMailer::string2params(string const & in,
|
|
|
|
Buffer const & buffer,
|
|
|
|
InsetBibtexParams & params)
|
|
|
|
{
|
|
|
|
params = InsetBibtexParams();
|
|
|
|
|
|
|
|
if (in.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
istringstream data(STRCONV(in));
|
|
|
|
LyXLex lex(0,0);
|
|
|
|
lex.setStream(data);
|
|
|
|
|
|
|
|
if (lex.isOK()) {
|
|
|
|
lex.next();
|
|
|
|
string const token = lex.getString();
|
|
|
|
if (token != name_)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is part of the inset proper that is usually swallowed
|
|
|
|
// by Buffer::readInset
|
|
|
|
if (lex.isOK()) {
|
|
|
|
lex.next();
|
|
|
|
string const token = lex.getString();
|
|
|
|
if (token != "Bibtex")
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lex.isOK()) {
|
|
|
|
params.read(buffer, lex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string const InsetBibtexMailer::params2string(InsetBibtexParams const & params,
|
|
|
|
Buffer const & buffer)
|
|
|
|
{
|
|
|
|
ostringstream data;
|
|
|
|
data << name_ << ' ';
|
|
|
|
params.write(buffer, data);
|
|
|
|
data << "\\end_inset\n";
|
|
|
|
return STRCONV(data.str());
|
|
|
|
}
|