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"
22 #include "frontends/Dialogs.h"
24 #include "support/lstrings.h"
30 InsetCitation::InsetCitation(InsetCommandParams const & p, bool)
34 string const InsetCitation::getScreenLabel(Buffer const *) const
36 string keys(getContents());
38 // If keys is "too long" then only print out the first few tokens
40 if (contains(keys, ",")) {
41 // Final comma allows while loop to cover all keys
42 keys = frontStrip(split(keys, label, ',')) + ",";
44 string::size_type const maxSize = 40;
45 while (contains(keys, ",")) {
47 keys = frontStrip(split(keys, key, ','));
49 string::size_type size = label.size() + 2 + key.size();
50 if (size >= maxSize) {
60 if (!getOptions().empty())
61 label += ", " + getOptions();
63 return "[" + label + "]";
67 void InsetCitation::edit(BufferView * bv, int, int, unsigned int)
69 bv->owner()->getDialogs()->showCitation(this);
72 void InsetCitation::edit(BufferView * bv, bool)
77 int InsetCitation::ascii(Buffer const *, ostream & os, int) const
79 os << "[" << getContents() << "]";
83 // Have to overwrite the default InsetCommand method in order to check that
84 // the \cite command is valid. Eg, the user has natbib enabled, inputs some
85 // citations and then changes his mind, turning natbib support off. The output
86 // should revert to \cite[]{}
87 int InsetCitation::latex(Buffer const * buffer, ostream & os,
88 bool /*fragile*/, bool/*fs*/) const
91 if (buffer->params.use_natbib)
96 if (!getOptions().empty())
97 os << "[" << getOptions() << "]";
99 // Paranoia check: make sure that there is no whitespace in here
101 for (string::const_iterator it = getContents().begin();
102 it != getContents().end(); ++it) {
103 if (*it != ' ') content += *it;
106 os << "{" << content << "}";
112 void InsetCitation::validate(LaTeXFeatures & features) const
114 if (features.bufferParams().use_natbib)
115 features.require("natbib");