1 /* This file is part of*
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 2000-2001 The LyX Team.
8 * ====================================================== */
13 #pragma implementation
16 #include "insetcite.h"
18 #include "BufferView.h"
19 #include "LaTeXFeatures.h"
21 #include "frontends/Dialogs.h"
22 #include "support/lstrings.h"
24 InsetCitation::InsetCitation(InsetCommandParams const & p, bool)
28 string const InsetCitation::getScreenLabel(Buffer const *) const
30 string keys(getContents());
32 // If keys is "too long" then only print out the first few tokens
34 if (contains(keys, ",")) {
35 // Final comma allows while loop to cover all keys
36 keys = frontStrip(split(keys, label, ',')) + ",";
38 string::size_type const maxSize = 40;
39 while (contains( keys, "," )) {
41 keys = frontStrip(split(keys, key, ','));
43 string::size_type size = label.size() + 2 + key.size();
44 if (size >= maxSize) {
54 if (!getOptions().empty())
55 label += ", " + getOptions();
57 return "[" + label + "]";
61 void InsetCitation::edit(BufferView * bv, int, int, unsigned int)
63 bv->owner()->getDialogs()->showCitation(this);
66 void InsetCitation::edit(BufferView * bv, bool)
71 int InsetCitation::ascii(Buffer const *, std::ostream & os, int) const
73 os << "[" << getContents() << "]";
77 // Have to overwrite the default InsetCommand method in order to check that
78 // the \cite command is valid. Eg, the user has natbib enabled, inputs some
79 // citations and then changes his mind, turning natbib support off. The output
80 // should revert to \cite[]{}
81 int InsetCitation::latex(Buffer const * buffer, std::ostream & os,
82 bool /*fragile*/, bool/*fs*/) const
85 if (buffer->params.use_natbib)
90 if (!getOptions().empty())
91 os << "[" << getOptions() << "]";
93 // Paranoia check: make sure that there is no whitespace in here
95 for (string::const_iterator it = getContents().begin();
96 it != getContents().end(); ++it) {
97 if (*it != ' ') content += *it;
100 os << "{" << content << "}";
106 void InsetCitation::validate(LaTeXFeatures & features) const
108 if (features.bufferParams().use_natbib)
109 features.require("natbib");