2 * \file insetfloatlist.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Lars Gullik Bjønnes
8 * Full author contact details are available in file CREDITS.
13 #include "insetfloatlist.h"
16 #include "bufferparams.h"
18 #include "dispatchresult.h"
20 #include "FloatList.h"
21 #include "funcrequest.h"
23 #include "LaTeXFeatures.h"
25 #include "metricsinfo.h"
28 #include "support/lstrings.h"
31 using lyx::support::bformat;
38 InsetFloatList::InsetFloatList()
39 : InsetCommand(InsetCommandParams("floatlist"), "toc")
43 InsetFloatList::InsetFloatList(string const & type)
44 : InsetCommand(InsetCommandParams("floatlist"), "toc")
50 docstring const InsetFloatList::getScreenLabel(Buffer const & buf) const
52 FloatList const & floats = buf.params().getLyXTextClass().floats();
53 FloatList::const_iterator it = floats[getCmdName()];
54 if (it != floats.end())
55 return buf.B_(it->second.listName());
57 return _("ERROR: Nonexistent float type!");
61 InsetBase::Code InsetFloatList::lyxCode() const
63 return InsetBase::FLOAT_LIST_CODE;
67 void InsetFloatList::write(Buffer const &, ostream & os) const
69 os << "FloatList " << getCmdName() << "\n";
73 void InsetFloatList::read(Buffer const & buf, LyXLex & lex)
75 FloatList const & floats = buf.params().getLyXTextClass().floats();
79 setCmdName(lex.getString());
80 lyxerr[Debug::INSETS] << "FloatList::float_type: " << getCmdName() << endl;
81 if (!floats.typeExist(getCmdName()))
82 lex.printError("InsetFloatList: Unknown float type: `$$Token'");
84 lex.printError("InsetFloatList: Parse error: `$$Token'");
87 token = lex.getString();
88 if (token == "\\end_inset")
91 if (token != "\\end_inset") {
92 lex.printError("Missing \\end_inset at this point. "
98 int InsetFloatList::latex(Buffer const & buf, ostream & os,
99 OutputParams const &) const
101 FloatList const & floats = buf.params().getLyXTextClass().floats();
102 FloatList::const_iterator cit = floats[getCmdName()];
104 if (cit != floats.end()) {
105 if (cit->second.builtin()) {
106 // Only two different types allowed here:
107 string const type = cit->second.type();
108 if (type == "table") {
109 os << "\\listoftables\n";
110 } else if (type == "figure") {
111 os << "\\listoffigures\n";
113 os << "%% unknown builtin float\n";
117 os << "\\listof{" << getCmdName() << "}{"
118 << lyx::to_utf8(buf.B_(cit->second.listName())) << "}\n";
122 os << "%%\\listof{" << getCmdName() << "}{"
123 << lyx::to_utf8(bformat(_("List of %1$s"), lyx::from_utf8(cit->second.name())))
130 int InsetFloatList::plaintext(Buffer const & buffer, lyx::odocstream & os,
131 OutputParams const &) const
133 os << getScreenLabel(buffer) << "\n\n";
135 lyx::toc::asciiTocList(getCmdName(), buffer, os);
142 void InsetFloatList::validate(LaTeXFeatures & features) const
144 features.useFloat(getCmdName());