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() 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 int InsetCitation::ascii(Buffer const *, std::ostream & os, int) const
68 os << "[" << getContents() << "]";
72 // Have to overwrite the default InsetCommand method in order to check that
73 // the \cite command is valid. Eg, the user has natbib enabled, inputs some
74 // citations and then changes his mind, turning natbib support off. The output
75 // should revert to \cite[]{}
76 int InsetCitation::latex(Buffer const * buffer, std::ostream & os,
77 bool /*fragile*/, bool/*fs*/) const
80 if (buffer->params.use_natbib)
85 if (!getOptions().empty())
86 os << "[" << getOptions() << "]";
88 os << "{" << getContents() << "}";
94 void InsetCitation::validate(LaTeXFeatures & features) const
96 if (getCmdName() != "cite" && features.bufferParams().use_natbib)
97 features.natbib = true;