2000-07-07 07:46:37 +00:00
|
|
|
/* This file is part of*
|
|
|
|
* ======================================================
|
|
|
|
*
|
|
|
|
* LyX, The Document Processor
|
|
|
|
*
|
2001-05-30 13:53:44 +00:00
|
|
|
* Copyright 2000-2001 The LyX Team.
|
2000-07-07 07:46:37 +00:00
|
|
|
*
|
|
|
|
* ====================================================== */
|
2000-06-07 08:53:40 +00:00
|
|
|
|
2000-07-07 07:46:37 +00:00
|
|
|
#include <config.h>
|
2000-06-07 08:53:40 +00:00
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "insetcite.h"
|
2001-07-19 14:12:37 +00:00
|
|
|
#include "buffer.h"
|
2000-07-14 07:52:03 +00:00
|
|
|
#include "BufferView.h"
|
2001-07-19 14:12:37 +00:00
|
|
|
#include "LaTeXFeatures.h"
|
2000-08-01 17:33:32 +00:00
|
|
|
#include "LyXView.h"
|
2002-02-16 15:59:55 +00:00
|
|
|
|
2000-07-14 07:52:03 +00:00
|
|
|
#include "frontends/Dialogs.h"
|
2002-02-16 15:59:55 +00:00
|
|
|
|
2000-07-19 08:37:26 +00:00
|
|
|
#include "support/lstrings.h"
|
2000-07-15 23:51:46 +00:00
|
|
|
|
2002-02-16 15:59:55 +00:00
|
|
|
|
|
|
|
using std::ostream;
|
|
|
|
|
|
|
|
|
2001-07-06 15:57:54 +00:00
|
|
|
InsetCitation::InsetCitation(InsetCommandParams const & p, bool)
|
2000-08-03 12:56:25 +00:00
|
|
|
: InsetCommand(p)
|
2000-07-15 23:51:46 +00:00
|
|
|
{}
|
|
|
|
|
2001-07-28 12:24:16 +00:00
|
|
|
string const InsetCitation::getScreenLabel(Buffer const *) const
|
2000-06-07 08:53:40 +00:00
|
|
|
{
|
2000-07-19 08:37:26 +00:00
|
|
|
string keys(getContents());
|
|
|
|
|
|
|
|
// If keys is "too long" then only print out the first few tokens
|
|
|
|
string label;
|
2000-09-27 18:13:30 +00:00
|
|
|
if (contains(keys, ",")) {
|
2000-07-19 08:37:26 +00:00
|
|
|
// Final comma allows while loop to cover all keys
|
2000-09-27 18:13:30 +00:00
|
|
|
keys = frontStrip(split(keys, label, ',')) + ",";
|
2000-06-07 08:53:40 +00:00
|
|
|
|
2000-10-17 09:14:34 +00:00
|
|
|
string::size_type const maxSize = 40;
|
2002-02-16 15:59:55 +00:00
|
|
|
while (contains(keys, ",")) {
|
2000-07-19 08:37:26 +00:00
|
|
|
string key;
|
2000-09-27 18:13:30 +00:00
|
|
|
keys = frontStrip(split(keys, key, ','));
|
2000-07-19 08:37:26 +00:00
|
|
|
|
2000-10-17 09:14:34 +00:00
|
|
|
string::size_type size = label.size() + 2 + key.size();
|
2000-11-04 10:00:12 +00:00
|
|
|
if (size >= maxSize) {
|
2000-07-19 08:37:26 +00:00
|
|
|
label += ", ...";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
label += ", " + key;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
label = keys;
|
2000-06-07 08:53:40 +00:00
|
|
|
}
|
|
|
|
|
2000-09-27 18:13:30 +00:00
|
|
|
if (!getOptions().empty())
|
2000-07-19 08:37:26 +00:00
|
|
|
label += ", " + getOptions();
|
|
|
|
|
2000-10-03 18:38:10 +00:00
|
|
|
return "[" + label + "]";
|
2000-06-07 08:53:40 +00:00
|
|
|
}
|
2000-07-14 07:52:03 +00:00
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
void InsetCitation::edit(BufferView * bv, int, int, unsigned int)
|
2000-07-14 07:52:03 +00:00
|
|
|
{
|
2000-09-27 18:13:30 +00:00
|
|
|
bv->owner()->getDialogs()->showCitation(this);
|
2000-07-14 07:52:03 +00:00
|
|
|
}
|
|
|
|
|
2001-07-20 14:18:48 +00:00
|
|
|
void InsetCitation::edit(BufferView * bv, bool)
|
|
|
|
{
|
|
|
|
edit(bv, 0, 0, 0);
|
|
|
|
}
|
|
|
|
|
2002-02-16 15:59:55 +00:00
|
|
|
int InsetCitation::ascii(Buffer const *, ostream & os, int) const
|
2001-05-27 17:51:16 +00:00
|
|
|
{
|
|
|
|
os << "[" << getContents() << "]";
|
|
|
|
return 0;
|
|
|
|
}
|
2001-07-19 14:12:37 +00:00
|
|
|
|
|
|
|
// Have to overwrite the default InsetCommand method in order to check that
|
|
|
|
// the \cite command is valid. Eg, the user has natbib enabled, inputs some
|
|
|
|
// citations and then changes his mind, turning natbib support off. The output
|
|
|
|
// should revert to \cite[]{}
|
2002-02-16 15:59:55 +00:00
|
|
|
int InsetCitation::latex(Buffer const * buffer, ostream & os,
|
2001-07-19 14:12:37 +00:00
|
|
|
bool /*fragile*/, bool/*fs*/) const
|
|
|
|
{
|
|
|
|
os << "\\";
|
|
|
|
if (buffer->params.use_natbib)
|
|
|
|
os << getCmdName();
|
|
|
|
else
|
|
|
|
os << "cite";
|
|
|
|
|
|
|
|
if (!getOptions().empty())
|
|
|
|
os << "[" << getOptions() << "]";
|
|
|
|
|
2001-08-01 15:26:04 +00:00
|
|
|
// Paranoia check: make sure that there is no whitespace in here
|
|
|
|
string content;
|
|
|
|
for (string::const_iterator it = getContents().begin();
|
|
|
|
it != getContents().end(); ++it) {
|
|
|
|
if (*it != ' ') content += *it;
|
|
|
|
}
|
|
|
|
|
|
|
|
os << "{" << content << "}";
|
2001-07-19 14:12:37 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetCitation::validate(LaTeXFeatures & features) const
|
|
|
|
{
|
2001-07-28 12:24:16 +00:00
|
|
|
if (features.bufferParams().use_natbib)
|
2001-11-19 15:34:11 +00:00
|
|
|
features.require("natbib");
|
2001-07-19 14:12:37 +00:00
|
|
|
}
|